Java 类javax.lang.model.SourceVersion 实例源码

项目:javaide    文件: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);
        }
    }
}
项目:javaide    文件: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.<JCAnnotation>nil(), null, List.<JCTree>nil());
        toplevel.packge = syms.unnamedPackage;
        return attr.attribIdent(tree, toplevel);
    } finally {
        log.useSource(prev);
    }
}
项目:incubator-servicecomb-java-chassis    文件:ClassUtils.java   
public static String correctMethodParameterName(String paramName) {
  if (SourceVersion.isName(paramName)) {
    return paramName;
  }
  StringBuffer newParam = new StringBuffer();
  char tempChar;
  for (int index = 0; index < paramName.length(); index++) {
    tempChar = paramName.charAt(index);
    if (Character.isJavaIdentifierPart(tempChar)) {
      newParam.append(paramName.charAt(index));
    } else if (tempChar == '.' || tempChar == '-') {
      newParam.append('_');
    }
  }
  return newParam.toString();
}
项目:incubator-netbeans    文件:CustomizerCompile.java   
private void addOptionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOptionButtonActionPerformed
    final AddProcessorOption panel = new AddProcessorOption();
    final DialogDescriptor desc = new DialogDescriptor(panel, NbBundle.getMessage (CustomizerCompile.class, "LBL_AddProcessorOption_Title")); //NOI18N
    desc.setValid(false);
    panel.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            String key = panel.getOptionKey();
            for(String s : key.split("\\.", -1)) { //NOI18N
                if (!SourceVersion.isIdentifier(s)) {
                    desc.setValid(false);
                    return;
                }
            }
            desc.setValid(true);
        }
    });
    Dialog dlg = DialogDisplayer.getDefault().createDialog(desc);
    dlg.setVisible (true);
    if (desc.getValue() == DialogDescriptor.OK_OPTION) {
        ((DefaultTableModel)processorOptionsTable.getModel()).addRow(new String[] {panel.getOptionKey(), panel.getOptionValue()});
    }
    dlg.dispose();
}
项目:incubator-netbeans    文件:JavaCompletionItem.java   
private static String adjustName(String name) {
    if (name == null) {
        return null;
    }
    String shortName = null;
    if (name.startsWith("get") && name.length() > 3) { //NOI18N
        shortName = name.substring(3);
    }
    if (name.startsWith("is") && name.length() > 2) { //NOI18N
        shortName = name.substring(2);
    }
    if (shortName != null) {
        return firstToLower(shortName);
    }
    if (SourceVersion.isKeyword(name)) {
        return "a" + Character.toUpperCase(name.charAt(0)) + name.substring(1); //NOI18N
    } else {
        return name;
    }
}
项目:incubator-netbeans    文件:JavaCompletionItem.java   
private static String firstToLower(String name) {
    if (name.length() == 0) {
        return null;
    }
    StringBuilder result = new StringBuilder();
    boolean toLower = true;
    char last = Character.toLowerCase(name.charAt(0));
    for (int i = 1; i < name.length(); i++) {
        if (toLower && Character.isUpperCase(name.charAt(i))) {
            result.append(Character.toLowerCase(last));
        } else {
            result.append(last);
            toLower = false;
        }
        last = name.charAt(i);
    }
    result.append(last);
    if (SourceVersion.isKeyword(result)) {
        return "a" + name; //NOI18N
    } else {
        return result.toString();
    }
}
项目:incubator-netbeans    文件:JavadocGenerator.java   
public String generateComment(VariableElement field, CompilationInfo javac) {
        StringBuilder builder = new StringBuilder(
//                "/**\n" + // NOI18N
                "\n" // NOI18N
                );

        if (SourceVersion.RELEASE_5.compareTo(srcVersion) <= 0 &&
                JavadocUtilities.isDeprecated(javac, field)) {
            builder.append("@deprecated\n"); // NOI18N
        }


//        builder.append("*/\n"); // NOI18N

        return builder.toString();
    }
项目:OpenJSharp    文件:JavacProcessingEnvironment.java   
public static boolean isValidOptionName(String optionName) {
    for(String s : optionName.split("\\.", -1)) {
        if (!SourceVersion.isIdentifier(s))
            return false;
    }
    return true;
}
项目:openjdk-jdk10    文件:CheckNamesProcessor.java   
@Override
public SourceVersion getSupportedSourceVersion() {
    /*
     * Return latest source version instead of a fixed version
     * like RELEASE_9. To return a fixed version, this class could
     * be annotated with a SupportedSourceVersion annotation.
     *
     * Warnings will be issued if any unknown language constructs
     * are encountered.
     */
    return SourceVersion.latest();
}
项目:javaide    文件:JavacFileManager.java   
private static boolean isValidName(String name) {
    // Arguably, isValidName should reject keywords (such as in SourceVersion.isName() ),
    // but the set of keywords depends on the source level, and we don't want
    // impls of JavaFileManager to have to be dependent on the source level.
    // Therefore we simply check that the argument is a sequence of identifiers
    // separated by ".".
    for (String s : name.split("\\.", -1)) {
        if (!SourceVersion.isIdentifier(s))
            return false;
    }
    return true;
}
项目:javaide    文件:JavacProcessingEnvironment.java   
/**
 * Return true if the argument string is a valid import-style
 * string specifying claimed annotations; return false otherwise.
 */
public static boolean isValidImportString(String s) {
    if (s.equals("*"))
        return true;

    boolean valid = true;
    String t = s;
    int index = t.indexOf('*');

    if (index != -1) {
        // '*' must be last character...
        if (index == t.length() -1) {
            // ... any and preceding character must be '.'
            if ( index-1 >= 0 ) {
                valid = t.charAt(index-1) == '.';
                // Strip off ".*$" for identifier checks
                t = t.substring(0, t.length()-2);
            }
        } else
            return false;
    }

    // Verify string is off the form (javaId \.)+ or javaId
    if (valid) {
        String[] javaIds = t.split("\\.", t.length()+2);
        for(String javaId: javaIds)
            valid &= SourceVersion.isIdentifier(javaId);
    }
    return valid;
}
项目:openjdk-jdk10    文件:NameConverter.java   
public String toConstantName( String token ) {
    String name = super.toConstantName(token);
    if(!SourceVersion.isKeyword(name))
        return name;
    else
        return '_'+name;
}
项目:OpenJSharp    文件: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;
}
项目:openjdk-jdk10    文件:JavacElements.java   
private <S extends Symbol> S doGetElement(ModuleElement module, String methodName,
                                          CharSequence name, Class<S> clazz) {
    String strName = name.toString();
    if (!SourceVersion.isName(strName) && (!strName.isEmpty() || clazz == ClassSymbol.class)) {
        return null;
    }
    if (module == null) {
        return unboundNameToSymbol(methodName, strName, clazz);
    } else {
        return nameToSymbol((ModuleSymbol) module, strName, clazz);
    }
}
项目:incubator-netbeans    文件:Context.java   
public @NonNull SourceVersion sourceVersion() {
    String sourceLevel = SourceLevelQuery.getSourceLevel(ctx.getInfo().getFileObject());

    if (sourceLevel == null) {
        return SourceVersion.latest(); //TODO
    }

    String[] splited = sourceLevel.split("\\.");
    String   spec    = splited[1];

    return SourceVersion.valueOf("RELEASE_"+  spec);//!!!
}
项目:jdk8u-jdk    文件:SerialFilterTest.java   
/**
 * Generate an object to be used with the various wildcard pattern forms.
 * Explicitly supports only specific package wildcards with specific objects.
 * @param pattern a wildcard pattern ending in "*"
 * @param allowed a boolean indicating to generate the allowed or disallowed case
 * @return an object within or outside the wildcard
 */
static Object genTestObjectWildcard(String pattern, boolean allowed) {
    if (pattern.endsWith(".**")) {
        // package hierarchy wildcard
        if (pattern.startsWith("javax.lang.")) {
            return SourceVersion.RELEASE_5;
        }
        if (pattern.startsWith("java.")) {
            return 4;
        }
        if (pattern.startsWith("javax.")) {
            return SourceVersion.RELEASE_6;
        }
        return otherObject;
    } else if (pattern.endsWith(".*")) {
        // package wildcard
        if (pattern.startsWith("javax.lang.model")) {
            return SourceVersion.RELEASE_6;
        }
    } else {
        // class wildcard
        if (pattern.equals("*")) {
            return otherObject; // any object will do
        }
        if (pattern.startsWith("java.util.Hash")) {
            return new Hashtable<String, String>();
        }
    }
    Assert.fail("Object could not be generated for pattern: "
            + pattern
            + ", allowed: " + allowed);
    return null;
}
项目:OpenJSharp    文件:CheckNamesProcessor.java   
@Override
public SourceVersion getSupportedSourceVersion() {
    /*
     * Return latest source version instead of a fixed version
     * like RELEASE_8.  To return a fixed version, this class
     * could be annotated with a SupportedSourceVersion
     * annotation.
     *
     * Warnings will be issued if any unknown language constructs
     * are encountered.
     */
    return SourceVersion.latest();
}
项目:openjdk-jdk10    文件:JavacFileManager.java   
private boolean isValid(Path fileName) {
    if (fileName == null) {
        return true;
    } else {
        String name = fileName.toString();
        if (name.endsWith("/")) {
            name = name.substring(0, name.length() - 1);
        }
        return SourceVersion.isIdentifier(name);
    }
}
项目:incubator-netbeans    文件:FileObjects.java   
public static boolean isJavaPath(
        @NonNull final String path,
        final char separator) {
    for (String name : path.split(Pattern.quote(Character.toString(separator)))) {
        if (!SourceVersion.isIdentifier(name)) {
            return false;
        }
    }
    return true;
}
项目:javaide    文件: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);
    }
}
项目:incubator-netbeans    文件:HintMetadata.java   
HintMetadata(String id, String displayName, String description, String category, boolean enabled, Hint.Kind kind, Severity severity, Collection<? extends String> suppressWarnings, CustomizerProvider customizer, Set<Options> options, SourceVersion sourceVersion) {
    this.id = id;
    this.displayName = displayName;
    this.description = description;
    this.category = category;
    this.enabled = enabled;
    this.kind = kind;
    this.severity = severity;
    this.suppressWarnings = suppressWarnings;
    this.customizer = customizer;
    this.options = options;
    this.sourceVersion = sourceVersion;
}
项目:incubator-netbeans    文件:ErrorDescriptionFactory.java   
private static boolean isSuppressWarningsSupported(CompilationInfo info) {
    //cannot suppress if there is no SuppressWarnings annotation in the platform:
    if (info.getElements().getTypeElement("java.lang.SuppressWarnings") == null)
        return false;

    return info.getSourceVersion().compareTo(SourceVersion.RELEASE_5) >= 0;
}
项目:incubator-netbeans    文件:ReplaceConstructorWithFactoryPlugin.java   
@Override
public Problem fastCheckParameters() {
    String factoryName = refactoring.getFactoryName();

    if (factoryName == null || factoryName.length() == 0) {
        // FIXME: I18N
        return new Problem(true, "No factory method name specified.");
    }
    if (!SourceVersion.isIdentifier(factoryName)) {
        // FIXME: I18N
        return new Problem(true, factoryName + " is not an identifier.");
    }
    return null;
}
项目:openjdk-jdk10    文件:GetSourceVersionsTest.java   
/**
 * Verify getSourceVersions.
 */
@Test
public void testRun() throws Exception {
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    Set<SourceVersion> found = tool.getSourceVersions();
    Set<SourceVersion> expect = EnumSet.range(SourceVersion.RELEASE_3, SourceVersion.latest());
    if (!expect.equals(found)) {
        System.err.println("expect: " + expect);
        System.err.println(" found: " + expect);
        error("unexpected versions");
    }
}
项目:openjdk-jdk10    文件:TestSourceVersionWarnings.java   
@Override
public SourceVersion getSupportedSourceVersion() {
    String sourceVersion = processingEnv.getOptions().get("SourceVersion");
    if (sourceVersion == null) {
        processingEnv.getMessager().printMessage(WARNING,
                                                 "No SourceVersion option given");
        return SourceVersion.RELEASE_6;
    } else {
        return SourceVersion.valueOf(sourceVersion);
    }
}
项目:incubator-netbeans    文件:JavaPluginUtils.java   
private static String firstToLower(String name) {
    if (name.length() == 0) {
        return null;
    }

    StringBuilder result = new StringBuilder();
    boolean toLower = true;
    char last = Character.toLowerCase(name.charAt(0));

    for (int i = 1; i < name.length(); i++) {
        if (toLower && (Character.isUpperCase(name.charAt(i)) || name.charAt(i) == '_')) {
            result.append(Character.toLowerCase(last));
        } else {
            result.append(last);
            toLower = false;
        }
        last = name.charAt(i);

    }

    result.append(toLower ? Character.toLowerCase(last) : last);

    if (SourceVersion.isKeyword(result)) {
        return "a" + name;
    } else {
        return result.toString();
    }
}
项目:incubator-netbeans    文件:AddPropertyPanel.java   
public AddFxPropertyConfig getAddPropertyConfig() {
    final String propertyType = typeComboBox.getSelectedItem().toString().trim();
    String implementationType = implemenationCombobox.getSelectedItem().toString().trim();
    final String name = nameTextField.getText().trim();
    final String initializer = initializerTextField.getText().trim();
    AddFxPropertyConfig.ACCESS access = AddFxPropertyConfig.ACCESS.PACKAGE;
    if (privateRadioButton.isSelected()) {
        access = AddFxPropertyConfig.ACCESS.PRIVATE;
    } else if (protectedRadioButton.isSelected()) {
        access = AddFxPropertyConfig.ACCESS.PROTECTED;
    } else if (publicRadioButton.isSelected()) {
        access = AddFxPropertyConfig.ACCESS.PUBLIC;
    }

    AddFxPropertyConfig.GENERATE generate = AddFxPropertyConfig.GENERATE.WRITABLE;
    if (!writableRadioButton.isSelected()) {
        generate = AddFxPropertyConfig.GENERATE.READ_ONLY;
    }

    if (implementationType.indexOf('<') != -1) { // NOI18N
        if (javac.getSourceVersion().compareTo(SourceVersion.RELEASE_7) >= 0) {
            // TODO: apply coding style ?
            implementationType = implementationType.substring(0, implementationType.indexOf('<')) + "<>"; // NOI18N
        } else {
            int propTemplate = propertyType.indexOf("<"); // NOI18N
            if (propTemplate != -1) {
                implementationType = implementationType.substring(0, implementationType.indexOf('<')) + propertyType.substring(propTemplate);
            }
        }
    }

    AddFxPropertyConfig addPropertyConfig = new AddFxPropertyConfig(
            name, initializer, propertyType, implementationType, access, generate, generateJavadocCheckBox.isSelected());
    return addPropertyConfig;
}
项目:incubator-netbeans    文件:ClassNamePanel.java   
public String getClassName() {
    String n = className.getText().trim();
    if (n.isEmpty() || !SourceVersion.isName(n)) {
        return null;
    }
    return n;
}
项目:openjdk-jdk10    文件:Locations.java   
/**
 * Returns {@code true} if the given name is a legal module name.
 */
private boolean isModuleName(String name) {
    int next;
    int off = 0;
    while ((next = name.indexOf('.', off)) != -1) {
        String id = name.substring(off, next);
        if (!SourceVersion.isName(id))
            return false;
        off = next+1;
    }
    String last = name.substring(off);
    return SourceVersion.isName(last);
}
项目:DUnit    文件:DUnitProcessor.java   
@Override
/**
 * 指定Java版本
 * 可用注解SupportedSourceVersion代替
 */
public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.latestSupported();
}
项目:openjdk-jdk10    文件: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);
}
项目:openjdk-jdk10    文件:JavacFileManager.java   
private static boolean isValidName(String name) {
    // Arguably, isValidName should reject keywords (such as in SourceVersion.isName() ),
    // but the set of keywords depends on the source level, and we don't want
    // impls of JavaFileManager to have to be dependent on the source level.
    // Therefore we simply check that the argument is a sequence of identifiers
    // separated by ".".
    for (String s : name.split("\\.", -1)) {
        if (!SourceVersion.isIdentifier(s))
            return false;
    }
    return true;
}
项目:incubator-netbeans    文件:OptionAnnotationProcessor.java   
@Override
public SourceVersion getSupportedSourceVersion() {
    if (delegate() != null) {
        return delegate().getSupportedSourceVersion();
    } else {
        return SourceVersion.RELEASE_7;
    }
}
项目:OpenJSharp    文件:SchemaGenerator.java   
@Override
public SourceVersion getSupportedSourceVersion() {
    if (SourceVersion.latest().compareTo(SourceVersion.RELEASE_6) > 0)
        return SourceVersion.valueOf("RELEASE_7");
    else
        return SourceVersion.RELEASE_6;
}
项目:annotation-processor-toolkit    文件:AnnotationProcessorWrapper.java   
@Override
public SourceVersion getSupportedSourceVersion() {
    return wrappedProcessor.getSupportedSourceVersion();
}
项目:incap    文件:Processor1.java   
@Override
public SourceVersion getSupportedSourceVersion() {
    return latestSupported();
}
项目:cuckoo    文件:DelegationProcessor.java   
@Override
public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.latest();
}
项目:GitHub    文件:EventBusAnnotationProcessor.java   
@Override
public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.latest();
}
项目:data-mediator    文件:MediatorAnnotationProcessor_backup.java   
/**
 * 用来指定你使用的 java 版本
 */
@Override
public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.latestSupported();
}
项目:openjdk-jdk10    文件:SourceOption.java   
@Override
public SourceVersion getSupportedSourceVersion() {
    return SourceVersion.latest();
}