Java Code Examples for javax.lang.model.SourceVersion#isName()

The following examples show how to use javax.lang.model.SourceVersion#isName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Arguments.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void validateAddModules(SourceVersion sv) {
    String addModules = options.get(Option.ADD_MODULES);
    if (addModules != 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.ADD_MODULES.
        for (String moduleName : addModules.split(",")) {
            switch (moduleName) {
                case "":
                case "ALL-SYSTEM":
                case "ALL-MODULE-PATH":
                    break;

                default:
                    if (!SourceVersion.isName(moduleName, sv)) {
                        // syntactically invalid module name:  e.g. --add-modules m1,m!
                        log.error(Errors.BadNameForOption(Option.ADD_MODULES, moduleName));
                    }
                    break;
            }
        }
    }
}
 
Example 2
Source File: Arguments.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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;
            }
        }
    }
}
 
Example 3
Source File: Arguments.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
            }
        }
    }
}
 
Example 4
Source File: JavacFiler.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
    if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
        if (lint)
            log.warning(Warnings.ProcIllegalFileName(name));
        throw new FilerException("Illegal name " + name);
    }
}
 
Example 5
Source File: JavacFiler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
    if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
        if (lint)
            log.warning("proc.illegal.file.name", name);
        throw new FilerException("Illegal name " + name);
    }
}
 
Example 6
Source File: JavacElements.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
    }
}
 
Example 7
Source File: JavacFiler.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
    if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
        if (lint)
            log.warning("proc.illegal.file.name", name);
        throw new FilerException("Illegal name " + name);
    }
}
 
Example 8
Source File: Arguments.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void validateAddReads(SourceVersion sv) {
    String addReads = options.get(Option.ADD_READS);
    if (addReads != null) {
        // Each entry must be of the form source=target-list where target-list is a
        // comma-separated list of module or ALL-UNNAMED.
        // Empty items in the target list are ignored.
        // There must be at least one item in the list; this is handled in Option.ADD_READS.
        Pattern p = Option.ADD_READS.getPattern();
        for (String e : addReads.split("\0")) {
            Matcher m = p.matcher(e);
            if (m.matches()) {
                String sourceName = m.group(1);
                if (!SourceVersion.isName(sourceName, sv)) {
                    // syntactically invalid source name:  e.g. --add-reads m!=m2
                    log.warning(Warnings.BadNameForOption(Option.ADD_READS, sourceName));
                }

                String targetNames = m.group(2);
                for (String targetName : targetNames.split(",", -1)) {
                    switch (targetName) {
                        case "":
                        case "ALL-UNNAMED":
                            break;

                        default:
                            if (!SourceVersion.isName(targetName, sv)) {
                                // syntactically invalid target name:  e.g. --add-reads m1=m!
                                log.warning(Warnings.BadNameForOption(Option.ADD_READS, targetName));
                            }
                            break;
                    }
                }
            }
        }
    }
}
 
Example 9
Source File: JavacFiler.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
    if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
        if (lint)
            log.warning("proc.illegal.file.name", name);
        throw new FilerException("Illegal name " + name);
    }
}
 
Example 10
Source File: JavacElements.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public PackageSymbol getPackageElement(CharSequence name) {
    String strName = name.toString();
    if (strName.equals(""))
        return syms.unnamedPackage;
    return SourceVersion.isName(strName)
        ? nameToSymbol(strName, PackageSymbol.class)
        : null;
}
 
Example 11
Source File: JavacElements.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public PackageSymbol getPackageElement(CharSequence name) {
    String strName = name.toString();
    if (strName.equals(""))
        return syms.unnamedPackage;
    return SourceVersion.isName(strName)
        ? nameToSymbol(strName, PackageSymbol.class)
        : null;
}
 
Example 12
Source File: Arguments.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void validateDefaultModuleForCreatedFiles(SourceVersion sv) {
    String moduleName = options.get(Option.DEFAULT_MODULE_FOR_CREATED_FILES);
    if (moduleName != null) {
        if (!SourceVersion.isName(moduleName, sv)) {
            // syntactically invalid module name:  e.g. --default-module-for-created-files m!
            log.error(Errors.BadNameForOption(Option.DEFAULT_MODULE_FOR_CREATED_FILES,
                                              moduleName));
        }
    }
}
 
Example 13
Source File: JavacFiler.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
    if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
        if (lint)
            log.warning("proc.illegal.file.name", name);
        throw new FilerException("Illegal name " + name);
    }
}
 
Example 14
Source File: ReplaceConstructorWithBuilderPlugin.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Problem fastCheckParameters() {
    String builderName = refactoring.getBuilderName();
    String buildMethodName = refactoring.getBuildMethodName();
    if (builderName == null || builderName.length() == 0) {
        return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NoFactory"));
    }
    if (!SourceVersion.isName(builderName)) {
        return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NotIdentifier", builderName));
    }
    if (buildMethodName == null || buildMethodName.isEmpty()) {
        return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NoBuildMethod"));
    }
    if (!SourceVersion.isIdentifier(buildMethodName)) {
        return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_NotIdentifier", buildMethodName));
    }
    final TreePathHandle constr = treePathHandle;
    ClassPath classPath = ClassPath.getClassPath(constr.getFileObject(), ClassPath.SOURCE);
    String name = refactoring.getBuilderName().replace(".", "/") + ".java";
    FileObject resource = classPath.findResource(name);
    if (resource !=null) {
        return new Problem(true, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "ERR_FileExists", name));
    }
    Problem problem = null;
    for (Setter set : refactoring.getSetters()) {
        if(set.isOptional() && set.getDefaultValue() == null) {
            problem = JavaPluginUtils.chainProblems(problem, new Problem(false, NbBundle.getMessage(ReplaceConstructorWithBuilderPlugin.class, "WRN_NODEFAULT", set.getVarName())));
        }
    }
    return problem;
}
 
Example 15
Source File: SchemaGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 16
Source File: JavacFiler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
    if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
        if (lint)
            log.warning("proc.illegal.file.name", name);
        throw new FilerException("Illegal name " + name);
    }
}
 
Example 17
Source File: JavacFiler.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean isPackageInfo(String name, boolean allowUnnamedPackageInfo) {
    // Is the name of the form "package-info" or
    // "foo.bar.package-info"?
    final String PKG_INFO = "package-info";
    int periodIndex = name.lastIndexOf(".");
    if (periodIndex == -1) {
        return allowUnnamedPackageInfo ? name.equals(PKG_INFO) : false;
    } else {
        // "foo.bar.package-info." illegal
        String prefix = name.substring(0, periodIndex);
        String simple = name.substring(periodIndex+1);
        return SourceVersion.isName(prefix) && simple.equals(PKG_INFO);
    }
}
 
Example 18
Source File: Scanner.java    From jpms-module-names with MIT License 4 votes vote down vote up
private void scanModule(Item item) {
  summary.scanModuleCounter++;

  var name = item.moduleName;
  var group = item.mavenGroupId;

  logger.log(DEBUG, "Found {0} module in `{1}`", item.moduleMode, item);

  // Is the (automatic) module name an invalid Java name?
  if (!SourceVersion.isName(name)) {
    logger.log(INFO, "Invalid module name detected: {0}", name);
    if ("explicit".equals(item.moduleMode)) {
      logger.log(WARNING, "Invalid module name `{0}` in an _explicit_ module?!", name);
    }
    summary.suspicious.syntax.add(item);
    return;
  }

  // Is the name of the module already well-known?
  var module = modules.get(name);
  if (module != null) {
    // Is it an identical line, a glitch in the matrix?
    if (module.line.equals(item.line)) {
      logger.log(INFO, "Exact line duplication detected: {0}", item.line);
      return;
    }
    // Is it an update of the Maven version?
    if (module.mavenGroupColonArtifact.equals(item.mavenGroupColonArtifact)) {
      var now = item.mavenVersion;
      var old = module.mavenVersion;
      if (Objects.equals(now, old)) {
        logger.log(INFO, "Version duplication detected: {0}", item.line);
        return;
      }
      logger.log(INFO, "Version of module {0} set to {1} (was={2}) ", name, now, old);
      modules.put(name, item);
      summary.updates.put(name, item);
      return;
    }
    // No, no, an impostor!
    logger.log(INFO, "Impostor of module `{0}` detected: {1}", name, item);
    summary.suspicious.impostors.add(item);
    return;
  }

  // Doesn't the module name starts with its Maven Group ID or an well-know alias thereof?
  if (!name.startsWith(group)) {
    logger.log(INFO, "Module name {0} does not start with its group id: {1}", name, group);
    var alias = mavenGroupAlias.get(group);
    if (alias != null && name.startsWith(alias)) {
      logger.log(INFO, "Module name {0} starts with a group alias {1}", name, alias);
      // fall-through
    } else {
      logger.log(DEBUG, "Module name {0} does not start with a group alias", name);
      summary.suspicious.naming.add(item);
      return;
    }
  }

  //
  // Still here?! Yeah, found either a new unique module name or an updated version.
  //
  logger.log(INFO, "Found new unique {0} module named: `{1}`", item.moduleMode, name);
  modules.put(name, item);
  summary.uniques.put(name, item);
}
 
Example 19
Source File: JavacElements.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public ClassSymbol getTypeElement(CharSequence name) {
    String strName = name.toString();
    return SourceVersion.isName(strName)
        ? nameToSymbol(strName, ClassSymbol.class)
        : null;
}
 
Example 20
Source File: JavacElements.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public ClassSymbol getTypeElement(CharSequence name) {
    String strName = name.toString();
    return SourceVersion.isName(strName)
        ? nameToSymbol(strName, ClassSymbol.class)
        : null;
}