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


Java SourceVersion.isIdentifier方法代码示例

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


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

示例1: correctClassName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
public static String correctClassName(String name) {
  if (SourceVersion.isIdentifier(name) && !SourceVersion.isKeyword(name)) {
    return name;
  }
  String parts[] = name.split("\\.", -1);
  for (int idx = 0; idx < parts.length; idx++) {
    String part = parts[idx];
    if (part.isEmpty()) {
      parts[idx] = "_";
      continue;
    }

    part = part.replace('-', '_');
    if (Character.isDigit(part.charAt(0)) || SourceVersion.isKeyword(part)) {
      part = "_" + part;
    }
    parts[idx] = part;
  }
  return String.join(".", parts);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:ClassUtils.java

示例2: resolveIdent

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
/** Resolve an identifier.
 * @param msym      The module in which the search should be performed
 * @param name      The identifier to resolve
 */
public Symbol resolveIdent(ModuleSymbol msym, 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.nil());
        toplevel.modle = msym;
        toplevel.packge = msym.unnamedPackage;
        return attr.attribIdent(tree, toplevel);
    } finally {
        log.useSource(prev);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:JavaCompiler.java

示例3: resolveIdent

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

示例4: isInJavaPackage

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private static boolean isInJavaPackage(
        @NonNull final FileObject root,
        @NonNull final FileObject file) {
    FileObject fld = file.getParent();
    while (fld != null && !fld.equals(root)) {
        if (!SourceVersion.isIdentifier(fld.getNameExt())) {
            return false;
        }
        fld = fld.getParent();
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:FileObjectArchive.java

示例5: isJavaPath

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

示例6: findNameSpan

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
/**Find span of the name in the DocTree's reference tree (see {@link #getReferenceName(com.sun.source.util.DocTreePath)}
 * identifier in the source. Returns starting and ending offset of the name in
 * the source code that was parsed (ie. {@link CompilationInfo.getText()}, which
 * may differ from the positions in the source document if it has been already
 * altered.
 * 
 * @param ref reference for which the identifier should be found
 * @return the span of the name, or null if cannot be found
 * @since 0.124
 */
public int[] findNameSpan(DocCommentTree docTree, ReferenceTree ref) {
    Name name = ((DCReference) ref).memberName;
    if (name == null || !SourceVersion.isIdentifier(name)) {
        //names like "<error>", etc.
        return null;
    }
    
    int pos = (int) info.getDocTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), docTree, ref);
    
    if (pos < 0)
        return null;
    
    TokenSequence<JavaTokenId> tokenSequence = info.getTokenHierarchy().tokenSequence(JavaTokenId.language());
    
    tokenSequence.move(pos);
    
    if (!tokenSequence.moveNext() || tokenSequence.token().id() != JavaTokenId.JAVADOC_COMMENT) return null;
    
    TokenSequence<JavadocTokenId> jdocTS = tokenSequence.embedded(JavadocTokenId.language());
    
    jdocTS.move(pos);
    
    boolean wasNext;
    
    while ((wasNext = jdocTS.moveNext()) && jdocTS.token().id() != JavadocTokenId.HASH)
        ;
    
    if (wasNext && jdocTS.moveNext()) {
        if (jdocTS.token().id() == JavadocTokenId.IDENT &&
            name.contentEquals(jdocTS.token().text())) {
            return new int[] {
                jdocTS.offset(),
                jdocTS.offset() + jdocTS.token().length()
            };
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:50,代码来源:TreeUtilities.java

示例7: fastCheckParameters

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

示例8: isValid

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

示例9: fastCheckParameters

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
@Override
public Problem fastCheckParameters() {
    String name = invertBooleanRefactoring.getNewName();
    
    if (name == null || name.length() == 0 || !SourceVersion.isIdentifier(name)) {
        return new Problem(true, NbBundle.getMessage(InvertBooleanRefactoringPlugin.class, "ERR_InvalidIdentifier", name));
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:InvertBooleanRefactoringPlugin.java

示例10: isJavaIdentifier

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
/** Test whether a given string is a valid Java identifier.
* @param id string which should be checked
* @return <code>true</code> if a valid identifier
* @see SourceVersion#isIdentifier
* @see SourceVersion#isKeyword
*/
public static boolean isJavaIdentifier(String id) {
    if (id == null) {
        return false;
    }
    return SourceVersion.isIdentifier(id) && !SourceVersion.isKeyword(id);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:BaseUtilities.java

示例11: listDirectory

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
/**
 * Insert all files in subdirectory subdirectory of directory directory
 * which match fileKinds into resultList
 */
private void listDirectory(File directory,
                           RelativeDirectory subdirectory,
                           Set<JavaFileObject.Kind> fileKinds,
                           boolean recurse,
                           ListBuffer<JavaFileObject> resultList) {
    File d = subdirectory.getFile(directory);
    if (!caseMapCheck(d, subdirectory))
        return;

    File[] files = d.listFiles();
    if (files == null)
        return;

    if (sortFiles != null)
        Arrays.sort(files, sortFiles);

    for (File f: files) {
        String fname = f.getName();
        if (f.isDirectory()) {
            if (recurse && SourceVersion.isIdentifier(fname)) {
                listDirectory(directory,
                              new RelativeDirectory(subdirectory, fname),
                              fileKinds,
                              recurse,
                              resultList);
            }
        } else {
            if (isValidFile(fname, fileKinds)) {
                JavaFileObject fe =
                    new RegularFileObject(this, fname, new File(d, fname));
                resultList.append(fe);
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:40,代码来源:JavacFileManager.java

示例12: isValidOptionName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
public static boolean isValidOptionName(String optionName) {
    for(String s : optionName.split("\\.", -1)) {
        if (!SourceVersion.isIdentifier(s))
            return false;
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:JavacProcessingEnvironment.java

示例13: isValidName

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

示例14: listDirectory

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
/**
 * Insert all files in subdirectory subdirectory of directory directory
 * which match fileKinds into resultList
 */
private void listDirectory(File directory,
                           RelativeDirectory subdirectory,
                           Set<JavaFileObject.Kind> fileKinds,
                           boolean recurse,
                           ListBuffer<JavaFileObject> resultList) {
    File d = subdirectory.getFile(directory);
    if (!caseMapCheck(d, subdirectory))
        return;

    File[] files = d.listFiles();
    if (files == null)
        return;

    if (sortFiles != null)
        Arrays.sort(files, sortFiles);

    for (File f : files) {
        String fname = f.getName();
        if (f.isDirectory()) {
            if (recurse && SourceVersion.isIdentifier(fname)) {
                listDirectory(directory,
                        new RelativeDirectory(subdirectory, fname),
                        fileKinds,
                        recurse,
                        resultList);
            }
        } else {
            if (isValidFile(fname, fileKinds)) {
                JavaFileObject fe =
                        new RegularFileObject(this, fname, new File(d, fname));
                resultList.append(fe);
            }
        }
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:40,代码来源:JavacFileManager.java

示例15: isValidImportString

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


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