当前位置: 首页>>代码示例>>Java>>正文


Java SourceVersion.isName方法代码示例

本文整理汇总了Java中javax.lang.model.SourceVersion.isName方法的典型用法代码示例。如果您正苦于以下问题:Java SourceVersion.isName方法的具体用法?Java SourceVersion.isName怎么用?Java SourceVersion.isName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.lang.model.SourceVersion的用法示例。


在下文中一共展示了SourceVersion.isName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateLimitModules

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
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;
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:Arguments.java

示例2: validateAddModules

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
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;
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:Arguments.java

示例3: checkClassName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private static String checkClassName(@NotNull final String className) {
    requireNonNull(className);
    if (!SourceVersion.isName(className)) {
        throw new IllegalArgumentException("Class name " + className + " is invalid.");
    }
    return className;
}
 
开发者ID:florentw,项目名称:bench,代码行数:8,代码来源:ActorBootstrap.java

示例4: fastCheckParameters

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:ReplaceConstructorWithBuilderPlugin.java

示例5: getClassName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
public String getClassName() {
    String n = className.getText().trim();
    if (n.isEmpty() || !SourceVersion.isName(n)) {
        return null;
    }
    return n;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ClassNamePanel.java

示例6: isPackageInfo

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:15,代码来源:JavacFiler.java

示例7: getPackageElement

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
public PackageSymbol getPackageElement(CharSequence name) {
    String strName = name.toString();
    if (strName.equals(""))
        return syms.unnamedPackage;
    return SourceVersion.isName(strName)
        ? nameToSymbol(strName, PackageSymbol.class)
        : null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:9,代码来源:JavacElements.java

示例8: isModuleName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:Locations.java

示例9: doGetElement

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:JavacElements.java

示例10: parse

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:SchemaGenerator.java

示例11: checkName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:JavacFiler.java

示例12: isValidName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private boolean isValidName(CharSequence name) {
    return SourceVersion.isName(name, Source.toSourceVersion(source));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:Modules.java

示例13: getValidBundleName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private String getValidBundleName(String name) {
    if (name == null) {
        return null;
    }
    if (name.contains("..") || name.contains("//")) { // NOI18N
        return null;
    }
    name = name.trim();
    if ("".equals(name)) { // NOI18N
        return null;
    }
    if (name.toLowerCase().endsWith(".java")) { // NOI18N
        return null;
    }

    if (name.startsWith("/")) { // NOI18N
        name = name.substring(1);
    }
    // We prefer if the name (without extension) can be used as a class name, but
    // that can be too strict, so we allow to use any file that already exists.
    int i = name.lastIndexOf('.');
    String withPropertiesExt = i < 0 ? name + ".properties" : null; // NOI18N
    FileObject sourceFile = getSourceFile();
    ClassPath cp = ClassPath.getClassPath(sourceFile, ClassPath.SOURCE);
    for (FileObject r : cp.getRoots()) {
        if (FileUtil.isParentOf(r, sourceFile)) {
            if (r.getFileObject(name) != null
                    || (withPropertiesExt != null && r.getFileObject(withPropertiesExt) != null)) {
                return name; // it exists
            }
            break;
        }
    }

    String withoutExt;
    String ext;
    if (i >= 0) {
        withoutExt = name.substring(0, i);
        ext = name.substring(i+1); // one dot considered as extension
    } else {
        withoutExt = name;
        ext = null;
    }
    if (withoutExt.contains(".") || withoutExt.length() == 0) { // NOI18N
        return null; // likely entered dot-separated class name, but that's not allowed here
    }
    if (!SourceVersion.isName(withoutExt.replace('/', '.'))
                || (ext != null && !SourceVersion.isIdentifier(ext))) {
        return null;
    }
    return name;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:ResourceSupport.java

示例14: checkErrors

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
@NbBundle.Messages({
   "ERR_ClassnameNotSpecified=Error: class name has not been specified",
   "# {0} - class name",
   "ERR_ClassnameInvalid=Error: {0} is not a valid Java class name",
   "ERR_PackagDoesNotExist=Error: existing package must be selected",
   "ERR_NoSourceGroups=Error: no place to generate class, set up a Source folder",
   "INFO_ClassAlreadyExists=Note: The class already exists. It will be overwritten.",
   "ERR_ProjectNotSelected=Project is not selected"
})
private void checkErrors() {
    enableDisable();
    if (project == null) {
        reportError(Bundle.ERR_ProjectNotSelected());
        return;
    }
    if (packageSelect.getItemCount() == 0) {
        reportError(Bundle.ERR_NoSourceGroups());
        return;
    }
    if (packageSelect.getSelectedItem() == null) {
        reportError(Bundle.ERR_PackagDoesNotExist());
        return;
    }
    String n = className.getText().trim();
    if (n.isEmpty()) {
        reportError(Bundle.ERR_ClassnameNotSpecified());
        return;
    }
    
    if (!SourceVersion.isName(n)) {
        reportError(Bundle.ERR_ClassnameInvalid(n));
        return;
    }
    
    notifier.clearMessages();

    FileObject folder = getTarget();
    if (folder != null) {
        n = getClassName();
        FileObject existing = folder.getFileObject(n, "java"); // NOI18N
        if (existing != null) {
            notifier.setInformationMessage(Bundle.INFO_ClassAlreadyExists());
        }
    }
    
    if (listener != null) {
        listener.stateChanged(new ChangeEvent(this));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:50,代码来源:ClassNamePanel.java

示例15: createUserMarker

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
/**
 * Extracts the {@link UserMarkerAnnotation} from the given element, which is expected to be an annotation
 * annotated with {@link Service}. (This is checked).
 * @param annotationElement The marked annotation.
 * @param procEnv The current processing environment.
 * @return The extracted UserMarkerAnnotation
 */
static UserMarkerAnnotation createUserMarker(Element annotationElement, ProcessingEnvironment procEnv) {

    Elements elements = procEnv.getElementUtils();

    // Annotations are considered interfaces, as per the documentation.
    if (!annotationElement.getKind().isInterface()) {
        throw new IllegalStateException(
                "Annotated something that wasn't an annotation? "+annotationElement.toString());
    }

    TypeElement annotationMarkingSP = (TypeElement) annotationElement;


    Service serviceAnnotation = annotationElement.getAnnotation(Service.class);

    AnnotationMirror serviceMirror =
            Util.getMatchingMirror(
                    elements.getTypeElement(Service.class.getName()).asType(),
                    elements.getAllAnnotationMirrors(annotationElement),
                    procEnv.getTypeUtils());

    // We can't get the interface the normal way (via the annotation's methods)
    // Since Class<?>'s are a runtime construct and require classloading ... etc
    String interfaceQName = Util.getValueStringByName(serviceMirror, "serviceInterface");

    TypeElement serviceClass = elements.getTypeElement(interfaceQName);
    if (serviceClass == null) {
        throw new EasyPluginException(
                "Couldn't find interface class named: " + interfaceQName);
    }

    String serviceName = serviceAnnotation.value();

    if (!SourceVersion.isName(serviceName)) {
        throw new EasyPluginException(String.format("Service name isn't a valid java name: '%s'", serviceName));
    }

    String serviceNameFromAnnotaion = serviceAnnotation.serviceNameKey();
    String outputPackage = serviceAnnotation.outputPackage();

    return new UserMarkerAnnotation(
            annotationMarkingSP,
            serviceClass,
            serviceName,
            serviceNameFromAnnotaion,
            outputPackage);
}
 
开发者ID:c0d3d,项目名称:easy-plugins,代码行数:55,代码来源:PluginAnnotation.java


注:本文中的javax.lang.model.SourceVersion.isName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。