summaryrefslogtreecommitdiffstats
path: root/jack/src/com/android/jack/api/impl/JackProviderImpl.java
blob: 1ec577f1aee7dbc81d8a3ae05bf6ebe618b2f40b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.jack.api.impl;

import com.android.jack.Jack;
import com.android.jack.api.ConfigNotSupportedException;
import com.android.jack.api.JackConfig;
import com.android.jack.api.JackProvider;
import com.android.jack.api.v01.Api01Config;
import com.android.jack.api.v01.impl.Api01ConfigImpl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;

/**
 * This class provides an implementation to build the requested {@link JackConfig}
 */
public class JackProviderImpl implements JackProvider {
  @Override
  @SuppressWarnings("unchecked")
  public <T extends JackConfig> T createConfig(Class<T> cls) throws ConfigNotSupportedException {
    if (cls == Api01Config.class) {
      return (T) new Api01ConfigImpl();
    }

    throw new ConfigNotSupportedException(cls.getName() + " are not supported");
  }

  @Override
  public Collection<Class<? extends JackConfig>> getSupportedConfigs() {
    List<Class<? extends JackConfig>> result = new ArrayList<Class<? extends JackConfig>>(1);
    result.add(Api01Config.class);
    return result;
  }

  @Override
  @Nonnull
  public <T extends JackConfig> boolean isConfigSupported(@Nonnull Class<T> cls) {
    return cls == Api01Config.class;
  }

  @Override
  @Nonnull
  public String getCompilerReleaseName() {
    return Jack.getVersion().getReleaseName();
  }

  @Override
  @Nonnegative
  public int getCompilerReleaseCode() {
    return Jack.getVersion().getReleaseCode();
  }

  @Override
  @Nonnegative
  public int getCompilerSubReleaseCode() {
    return Jack.getVersion().getSubReleaseCode();
  }

  @Override
  @Nonnull
  public SubReleaseKind getCompilerSubReleaseKind() {
    switch (Jack.getVersion().getSubReleaseKind()) {
      case ENGINEERING:
        return SubReleaseKind.ENGINEERING;
      case PRE_ALPHA:
        return SubReleaseKind.PRE_ALPHA;
      case ALPHA:
        return SubReleaseKind.ALPHA;
      case BETA:
        return SubReleaseKind.BETA;
      case CANDIDATE:
        return SubReleaseKind.CANDIDATE;
      case RELEASE:
        return SubReleaseKind.RELEASE;
      default:
        throw new AssertionError(Jack.getVersion().getSubReleaseKind().name());
    }
  }

  @Override
  @CheckForNull
  public String getCompilerSourceCodeBase() {
    return Jack.getVersion().getCodeBase();
  }

  @Override
  public String getCompilerVersion() {
    return Jack.getVersion().getVersion();
  }

  @Override
  @CheckForNull
  public String getCompilerBuildId() {
    return Jack.getVersion().getBuildId();
  }
}