javax.annotation.processing.AbstractProcessor#javax.lang.model.SourceVersion源码实例Demo

下面列出了javax.annotation.processing.AbstractProcessor#javax.lang.model.SourceVersion 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private String assert_java_identifier(ParseTree node, boolean isDefining) {
    String name = node.getText();

    if ("for".equals(name)) {
        if (isDefining) {
            throw reportError("Syntax error on token \"" + name + "\" is not a valid identifier.", node);
        }
        return name;
    }
    if (Code.CONTEXT_NAME.equals(name)) {
        if (isDefining) {
            throw reportError("Duplicate local variable \"" + name + "\" is a reserved identifier.", node);
        }
        return name;
    }

    if (SourceVersion.isKeyword(name)) {
        throw reportError("Syntax error on token \"" + name + "\", It is not a valid identifier in Java.", node);
    }
    if (name.startsWith("$")) {
        throw reportError("Local variable \"" + name + "\" can't start with '$', it is a reserved identifier.", node);
    }

    return name;
}
 
源代码2 项目: openjdk-jdk9   文件: T6395981.java
public static void main(String... args) {
    Tool compiler = ToolProvider.getSystemJavaCompiler();
    Set<SourceVersion> expected = EnumSet.noneOf(SourceVersion.class);
    for (String arg : args)
        expected.add(SourceVersion.valueOf(arg));
    Set<SourceVersion> found = compiler.getSourceVersions();
    Set<SourceVersion> notExpected = EnumSet.copyOf(found);
    for (SourceVersion version : expected) {
        if (!found.contains(version))
            throw new AssertionError("Expected source version not found: " + version);
        else
            notExpected.remove(version);
    }
    if (!notExpected.isEmpty())
        throw new AssertionError("Unexpected source versions: " + notExpected);
}
 
源代码3 项目: auto   文件: GeneratedDoesNotExistTest.java
@Parameters(name = "{0}")
public static Collection<Object[]> data() {
  ImmutableList.Builder<Object[]> params = ImmutableList.builder();
  if (SourceVersion.latestSupported().compareTo(SourceVersion.RELEASE_8) > 0) {
    // use default options when running on JDK > 8
    // TODO(b/72513371): use --release 8 once compile-testing supports that
    params.add(
        new Object[] {
          ImmutableList.of(), "javax.annotation.processing.Generated",
        });
  }
  params.add(
      new Object[] {
        ImmutableList.of("-source", "8", "-target", "8"), "javax.annotation.Generated",
      });
  return params.build();
}
 
源代码4 项目: buck   文件: SourceVersionUtils.java
/** Gets the class file version corresponding to the given source version constant. */
public static int sourceVersionToClassFileVersion(SourceVersion version) {
  switch (version) {
    case RELEASE_0:
      return Opcodes.V1_1; // JVMS8 4.1: 1.0 and 1.1 both support version 45.3 (Opcodes.V1_1)
    case RELEASE_1:
      return Opcodes.V1_1;
    case RELEASE_2:
      return Opcodes.V1_2;
    case RELEASE_3:
      return Opcodes.V1_3;
    case RELEASE_4:
      return Opcodes.V1_4;
    case RELEASE_5:
      return Opcodes.V1_5;
    case RELEASE_6:
      return Opcodes.V1_6;
    case RELEASE_7:
      return Opcodes.V1_7;
    case RELEASE_8:
      return Opcodes.V1_8;
    default:
      throw new IllegalArgumentException(String.format("Unexpected source version: %s", version));
  }
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: ClassReader.java
private void fillIn(PackageSymbol p,
                    Location location,
                    Iterable<JavaFileObject> files)
{
    currentLoc = location;
    for (JavaFileObject fo : files) {
        switch (fo.getKind()) {
        case CLASS:
        case SOURCE: {
            // TODO pass binaryName to includeClassFile
            String binaryName = fileManager.inferBinaryName(currentLoc, fo);
            String simpleName = binaryName.substring(binaryName.lastIndexOf(".") + 1);
            if (SourceVersion.isIdentifier(simpleName) ||
                simpleName.equals("package-info"))
                includeClassFile(p, fo);
            break;
        }
        default:
            extraFileActions(p, fo);
        }
    }
}
 
源代码6 项目: hottub   文件: T6395981.java
public static void main(String... args) {
    Tool compiler = ToolProvider.getSystemJavaCompiler();
    Set<SourceVersion> expected = EnumSet.noneOf(SourceVersion.class);
    for (String arg : args)
        expected.add(SourceVersion.valueOf(arg));
    Set<SourceVersion> found = compiler.getSourceVersions();
    Set<SourceVersion> notExpected = EnumSet.copyOf(found);
    for (SourceVersion version : expected) {
        if (!found.contains(version))
            throw new AssertionError("Expected source version not found: " + version);
        else
            notExpected.remove(version);
    }
    if (!notExpected.isEmpty())
        throw new AssertionError("Unexpected source versions: " + notExpected);
}
 
源代码7 项目: TencentKona-8   文件: T6395981.java
public static void main(String... args) {
    Tool compiler = ToolProvider.getSystemJavaCompiler();
    Set<SourceVersion> expected = EnumSet.noneOf(SourceVersion.class);
    for (String arg : args)
        expected.add(SourceVersion.valueOf(arg));
    Set<SourceVersion> found = compiler.getSourceVersions();
    Set<SourceVersion> notExpected = EnumSet.copyOf(found);
    for (SourceVersion version : expected) {
        if (!found.contains(version))
            throw new AssertionError("Expected source version not found: " + version);
        else
            notExpected.remove(version);
    }
    if (!notExpected.isEmpty())
        throw new AssertionError("Unexpected source versions: " + notExpected);
}
 
源代码8 项目: jdk8u60   文件: T6395981.java
public static void main(String... args) {
    Tool compiler = ToolProvider.getSystemJavaCompiler();
    Set<SourceVersion> expected = EnumSet.noneOf(SourceVersion.class);
    for (String arg : args)
        expected.add(SourceVersion.valueOf(arg));
    Set<SourceVersion> found = compiler.getSourceVersions();
    Set<SourceVersion> notExpected = EnumSet.copyOf(found);
    for (SourceVersion version : expected) {
        if (!found.contains(version))
            throw new AssertionError("Expected source version not found: " + version);
        else
            notExpected.remove(version);
    }
    if (!notExpected.isEmpty())
        throw new AssertionError("Unexpected source versions: " + notExpected);
}
 
源代码9 项目: openjdk-8-source   文件: JavaCompiler.java
/** Resolve an identifier.
 * @param name      The identifier to resolve
 */
public Symbol resolveIdent(String name) {
    if (name.equals(""))
        return syms.errSymbol;
    JavaFileObject prev = log.useSource(null);
    try {
        JCExpression tree = null;
        for (String s : name.split("\\.", -1)) {
            if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
                return syms.errSymbol;
            tree = (tree == null) ? make.Ident(names.fromString(s))
                                  : make.Select(tree, names.fromString(s));
        }
        JCCompilationUnit toplevel =
            make.TopLevel(List.<JCTree.JCAnnotation>nil(), null, List.<JCTree>nil());
        toplevel.packge = syms.unnamedPackage;
        return attr.attribIdent(tree, toplevel);
    } finally {
        log.useSource(prev);
    }
}
 
源代码10 项目: openjdk-jdk9   文件: Arguments.java
private void validateLimitModules(SourceVersion sv) {
    String limitModules = options.get(Option.LIMIT_MODULES);
    if (limitModules != null) {
        // Each entry must be of the form target-list where target-list is a
        // comma separated list of module names, or ALL-DEFAULT, ALL-SYSTEM,
        // or ALL-MODULE_PATH.
        // Empty items in the target list are ignored.
        // There must be at least one item in the list; this is handled in Option.LIMIT_EXPORTS.
        for (String moduleName : limitModules.split(",")) {
            switch (moduleName) {
                case "":
                    break;

                default:
                    if (!SourceVersion.isName(moduleName, sv)) {
                        // syntactically invalid module name:  e.g. --limit-modules m1,m!
                        log.error(Errors.BadNameForOption(Option.LIMIT_MODULES, moduleName));
                    }
                    break;
            }
        }
    }
}
 
源代码11 项目: buck   文件: ClassVisitorDriverFromElement.java
/**
 * @param targetVersion the class file version to target, expressed as the corresponding Java
 *     source version
 * @param messager
 * @param types
 * @param includeParameterMetadata
 */
ClassVisitorDriverFromElement(
    SourceVersion targetVersion,
    ElementsExtended elements,
    Messager messager,
    Types types,
    boolean includeParameterMetadata) {
  this.targetVersion = targetVersion;
  this.elements = elements;
  descriptorFactory = new DescriptorFactory(elements);
  this.messager = messager;
  this.types = types;
  this.includeParameterMetadata = includeParameterMetadata;
  signatureFactory = new SignatureFactory(descriptorFactory);
  accessFlagsUtils = new AccessFlags(elements);
}
 
源代码12 项目: openjdk-8   文件: JavacProcessingEnvironment.java
/**
 * Checks whether or not a processor's source version is
 * compatible with the compilation source version.  The
 * processor's source version needs to be greater than or
 * equal to the source version of the compile.
 */
private void checkSourceVersionCompatibility(Source source, Log log) {
    SourceVersion procSourceVersion = processor.getSupportedSourceVersion();

    if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 )  {
        log.warning("proc.processor.incompatible.source.version",
                    procSourceVersion,
                    processor.getClass().getName(),
                    source.name);
    }
}
 
源代码13 项目: celerio   文件: PackageUtil.java
public static boolean isPackageNameValid(String packageName) {
    if (!SourceVersion.isName(packageName)) {
        return false;
    }

    if (packageName.startsWith("java")) {
        return false;
    }

    return true;
}
 
源代码14 项目: netbeans   文件: ConvertSwitchToRuleSwitchTest.java
public void testTrailingEmptyCase() throws Exception {
    if(!ConvertSwitchToRuleSwitchTest.isJDK14())
        return;
    HintTest.create()
            .input("package test;" +
                   "public class Test {\n" +
                   "     private void test(int p) {\n" +
                   "         String result;\n" +
                   "         switch (p) {\n" +
                   "             case 0:\n" +
                   "                 int i = 0;\n" +
                   "                 int j = 0;\n" +
                   "                 break;\n" +
                   "             default:\n" +
                   "         }\n" +
                   "     }\n" +
                   "}\n")
            .sourceLevel(SourceVersion.latest().name())
            .run(ConvertSwitchToRuleSwitch.class)
            .findWarning("3:9-3:15:verifier:" + Bundle.ERR_ConvertSwitchToRuleSwitch())
            .applyFix()
            .assertCompilable()
            .assertOutput("package test;" +
                          "public class Test {\n" +
                          "     private void test(int p) {\n" +
                          "         String result;\n" +
                          "         switch (p) {\n" +
                          "             case 0 -> {\n" +
                          "                 int i = 0;\n" +
                          "                 int j = 0;\n" +
                          "             }\n" +
                          "             default -> { }\n" +
                          "         }\n" +
                          "     }\n" +
                          "}\n");
}
 
源代码15 项目: netbeans   文件: ReindenterTest.java
public void testSpanIndentationTextBlock1() throws Exception {
    try {
        SourceVersion.valueOf("RELEASE_13");
    } catch (IllegalArgumentException ex) {
        //OK, skip test:
        return ;
    }
    performSpanIndentationTest("package t;\npublic class T {\n|private final String s = \"\"\"\n\"\"\";|\n}\n",
            "package t;\npublic class T {\n    private final String s = \"\"\"\n                             \"\"\";\n}\n");
}
 
源代码16 项目: netbeans   文件: ReindenterTest.java
public void testSpanIndentationTextBlock2() throws Exception {
    try {
        SourceVersion.valueOf("RELEASE_13");
    } catch (IllegalArgumentException ex) {
        //OK, skip test:
        return ;
    }
    performSpanIndentationTest("package t;\npublic class T {\n|private final String s = \"\"\"\n1\n  2\n 3\n\"\"\";|\n}\n",
            "package t;\npublic class T {\n    private final String s = \"\"\"\n                             1\n                               2\n                              3\n                             \"\"\";\n}\n");
}
 
源代码17 项目: openjdk-8   文件: SchemaGenerator.java
public static JavacOptions parse(OptionChecker primary, OptionChecker secondary, String... arguments) {
    List<String> recognizedOptions = new ArrayList<String>();
    List<String> unrecognizedOptions = new ArrayList<String>();
    List<String> classNames = new ArrayList<String>();
    List<File> files = new ArrayList<File>();
    for (int i = 0; i < arguments.length; i++) {
        String argument = arguments[i];
        int optionCount = primary.isSupportedOption(argument);
        if (optionCount < 0) {
            optionCount = secondary.isSupportedOption(argument);
        }
        if (optionCount < 0) {
            File file = new File(argument);
            if (file.exists())
                files.add(file);
            else if (SourceVersion.isName(argument))
                classNames.add(argument);
            else
                unrecognizedOptions.add(argument);
        } else {
            for (int j = 0; j < optionCount + 1; j++) {
                int index = i + j;
                if (index == arguments.length) throw new IllegalArgumentException(argument);
                recognizedOptions.add(arguments[index]);
            }
            i += optionCount;
        }
    }
    return new JavacOptions(recognizedOptions, classNames, files, unrecognizedOptions);
}
 
源代码18 项目: netbeans   文件: DetectorTest.java
public void testRecord2() throws Exception {
    try {
        SourceVersion.valueOf("RELEASE_14"); //NOI18N
    } catch (IllegalArgumentException ex) {
        //OK, no RELEASE_14, skip tests
        return;
    }        
    setSourceLevel("14");
    performTest("Records",
                "public class Records {\n" +
                "    public interface Super {}\n" +
                "    public record Foo1(String i, String j) implements Super { }\n" +
                "    public record Foo2(String i, String j) implements Super { }\n" +
                "    public record Foo3(String i, String j) implements Super { }\n" +
                "}\n",
                "[PUBLIC, CLASS, DECLARATION], 0:13-0:20",
                "[STATIC, PUBLIC, INTERFACE, DECLARATION], 1:21-1:26",
                "[KEYWORD], 2:11-2:17",
                "[STATIC, PUBLIC, RECORD, DECLARATION], 2:18-2:22",
                "[PUBLIC, CLASS], 2:23-2:29",
                "[PUBLIC, RECORD_COMPONENT, DECLARATION], 2:30-2:31",
                "[PUBLIC, CLASS], 2:33-2:39",
                "[PUBLIC, RECORD_COMPONENT, DECLARATION], 2:40-2:41",
                "[STATIC, PUBLIC, INTERFACE], 2:54-2:59",
                "[KEYWORD], 3:11-3:17",
                "[STATIC, PUBLIC, RECORD, DECLARATION], 3:18-3:22",
                "[PUBLIC, CLASS], 3:23-3:29",
                "[PUBLIC, RECORD_COMPONENT, DECLARATION], 3:30-3:31",
                "[PUBLIC, CLASS], 3:33-3:39",
                "[PUBLIC, RECORD_COMPONENT, DECLARATION], 3:40-3:41",
                "[STATIC, PUBLIC, INTERFACE], 3:54-3:59",
                "[KEYWORD], 4:11-4:17",
                "[STATIC, PUBLIC, RECORD, DECLARATION], 4:18-4:22",
                "[PUBLIC, CLASS], 4:23-4:29",
                "[PUBLIC, RECORD_COMPONENT, DECLARATION], 4:30-4:31",
                "[PUBLIC, CLASS], 4:33-4:39",
                "[PUBLIC, RECORD_COMPONENT, DECLARATION], 4:40-4:41",
                "[STATIC, PUBLIC, INTERFACE], 4:54-4:59");
}
 
源代码19 项目: openjdk-jdk8u   文件: AbstractProcessor.java
/**
 * If the processor class is annotated with {@link
 * SupportedSourceVersion}, return the source version in the
 * annotation.  If the class is not so annotated, {@link
 * SourceVersion#RELEASE_6} is returned.
 *
 * @return the latest source version supported by this processor
 */
public SourceVersion getSupportedSourceVersion() {
    SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class);
    SourceVersion sv = null;
    if (ssv == null) {
        sv = SourceVersion.RELEASE_6;
        if (isInitialized())
            processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
                                                     "No SupportedSourceVersion annotation " +
                                                     "found on " + this.getClass().getName() +
                                                     ", returning " + sv + ".");
    } else
        sv = ssv.value();
    return sv;
}
 
源代码20 项目: jdk8u60   文件: TestSourceVersion.java
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnvironment) {
    SourceVersion expectedVersion =
        SourceVersion.valueOf(processingEnv.getOptions().get("ExpectedVersion"));
    SourceVersion actualVersion =  processingEnv.getSourceVersion();
    System.out.println("Expected SourceVersion " + expectedVersion +
                       " actual SourceVersion "  + actualVersion);
    if (expectedVersion != actualVersion)
        throw new RuntimeException();

    return true;
}
 
源代码21 项目: JReFrameworker   文件: CodeWriter.java
private static String extractMemberName(String part) {
  checkArgument(Character.isJavaIdentifierStart(part.charAt(0)), "not an identifier: %s", part);
  for (int i = 1; i <= part.length(); i++) {
    if (!SourceVersion.isIdentifier(part.substring(0, i))) {
      return part.substring(0, i - 1);
    }
  }
  return part;
}
 
源代码22 项目: hottub   文件: AnnotationParser.java
@Override
public SourceVersion getSupportedSourceVersion() {
    if (SourceVersion.latest().compareTo(SourceVersion.RELEASE_6) > 0)
        return SourceVersion.valueOf("RELEASE_7");
    else
        return SourceVersion.RELEASE_6;
}
 
源代码23 项目: Prism4j   文件: PrismBundler.java
@Override
public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.RELEASE_8;
}
 
源代码24 项目: bazel   文件: JavacTurbineTest.java
@Override
public SourceVersion getSupportedSourceVersion() {
  return SourceVersion.latest();
}
 
源代码25 项目: openjdk-jdk9   文件: TestTrees.java
@Override
public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.latest();
}
 
源代码26 项目: openjdk-8   文件: TypeProcOnly.java
@Override
public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.latest();
}
 
源代码27 项目: ig-json-parser   文件: JsonAnnotationProcessor.java
@Override
public SourceVersion getSupportedSourceVersion() {
  return SourceVersion.latestSupported();
}
 
源代码28 项目: SimpleWeibo   文件: CompilationTest.java
@Override
public SourceVersion getSupportedSourceVersion() {
  return SourceVersion.latestSupported();
}
 
源代码29 项目: openjdk-jdk9   文件: Example.java
@Override
public SourceVersion getSupportedSourceVersion() {
    // support the latest release
    return SourceVersion.latest();
}
 
源代码30 项目: openjdk-8   文件: TestGetElement.java
@Override
public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.latest();
}