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


Java SourceVersion.isKeyword方法代码示例

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


在下文中一共展示了SourceVersion.isKeyword方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: adjustName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
static String adjustName(String name) {
    if (name == null) {
        return null;
    }
    
    String shortName = null;
    
    if (name.startsWith("get") && name.length() > 3) {
        shortName = name.substring(3);
    }
    
    if (name.startsWith("is") && name.length() > 2) {
        shortName = name.substring(2);
    }
    
    if (shortName != null) {
        return firstToLower(shortName);
    }
    
    if (SourceVersion.isKeyword(name)) {
        return "a" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
    } else {
        return name;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:JavaPluginUtils.java

示例3: adjustName

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

示例4: firstToLower

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

示例5: adjustName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
static String adjustName(String name) {
    if (name == null || ERROR.contentEquals(name))
        return null;
    
    String shortName = null;
    
    if (name.startsWith("get") && name.length() > 3) {
        shortName = name.substring(3);
    }
    
    if (name.startsWith("is") && name.length() > 2) {
        shortName = name.substring(2);
    }
    
    if (shortName != null) {
        return firstToLower(shortName);
    }
    
    if (SourceVersion.isKeyword(name)) {
        return "a" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
    } else {
        return name;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:Utilities.java

示例6: firstToLower

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

示例7: firstToLower

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

示例8: isClashing

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private static boolean isClashing(String varName, TypeMirror type, Iterable<? extends Element> locals) {
    if (SourceVersion.isKeyword(varName))
        return true;
    if (type != null && type.getKind() == TypeKind.DECLARED && ((DeclaredType)type).asElement().getSimpleName().contentEquals(varName))
        return true;
    for (Element e : locals) {
        if ((e.getKind().isField() || e.getKind() == ElementKind.LOCAL_VARIABLE || e.getKind() == ElementKind.RESOURCE_VARIABLE
                || e.getKind() == ElementKind.PARAMETER || e.getKind() == ElementKind.EXCEPTION_PARAMETER) && varName.contentEquals(e.getSimpleName()))
            return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:Utilities.java

示例9: 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

示例10: checkForReservedWord

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
private static String checkForReservedWord(String name) {

    if (SourceVersion.isKeyword(name)) {
      return name + "Variable";
    } else {

      return name;
    }
  }
 
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:10,代码来源:Names.java

示例11: toConstantName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
public String toConstantName( String token ) {
    String name = super.toConstantName(token);
    if(!SourceVersion.isKeyword(name))
        return name;
    else
        return '_'+name;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:NameConverter.java

示例12: run

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
@TriggerTreeKind(Kind.MEMBER_SELECT)
public static List<ErrorDescription> run(HintContext ctx) {
    CompilationInfo info = ctx.getInfo();
    TreePath treePath = ctx.getPath();

    Element e = info.getTrees().getElement(treePath);
    EnumSet<ElementKind> supportedTypes = EnumSet.of(ElementKind.METHOD, ElementKind.ENUM_CONSTANT, ElementKind.FIELD);
    if (e == null || !e.getModifiers().contains(Modifier.STATIC) || !supportedTypes.contains(e.getKind())) {
        return null;
    }

    if (ElementKind.METHOD.equals(e.getKind())) {
        TreePath mitp = treePath.getParentPath();
        if (mitp == null || mitp.getLeaf().getKind() != Kind.METHOD_INVOCATION) {
        return null;
    }
        if (((MethodInvocationTree) mitp.getLeaf()).getMethodSelect() != treePath.getLeaf()) {
        return null;
    }
        List<? extends Tree> typeArgs = ((MethodInvocationTree) mitp.getLeaf()).getTypeArguments();
        if (typeArgs != null && !typeArgs.isEmpty()) {
        return null;
    }
    }
    Element enclosingEl = e.getEnclosingElement();
    if (enclosingEl == null) {
        return null;
    }
    String sn = e.getSimpleName().toString();
    // rules out .class, but who knows what keywords will be abused in the future.
    if (SourceVersion.isKeyword(sn)) {
        return null;
    }
    TreePath cc = getContainingClass(treePath);
    if (cc == null){
        return null;
    }
    Element klass = info.getTrees().getElement(cc);
    if (klass == null || klass.getKind() != ElementKind.CLASS) {
        return null;
    }
    String fqn = null;
    String fqn1 = getFqn(info, e);
    if (!isSubTypeOrInnerOfSubType(info, klass, enclosingEl) && !isStaticallyImported(info, fqn1)) {
        if (hasMethodNameClash(info, klass, sn) || hasStaticImportSimpleNameClash(info, sn)) {
            return null;
        }
        fqn = fqn1;
    }
    Scope currentScope = info.getTrees().getScope(treePath);
    TypeMirror enclosingType = e.getEnclosingElement().asType();
    if (enclosingType == null || enclosingType.getKind() != TypeKind.DECLARED || !info.getTrees().isAccessible(currentScope, e, (DeclaredType) enclosingType)) {
        return null;
    }
    String desc = NbBundle.getMessage(StaticImport.class, "ERR_StaticImport");
    ErrorDescription ed = ErrorDescriptionFactory.forTree(ctx, treePath, desc, new FixImpl(TreePathHandle.create(treePath, info), fqn, sn).toEditorFix());
    if (ctx.isCanceled()) {
        return null;
    }
    return Collections.singletonList(ed);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:62,代码来源:StaticImport.java

示例13: toPackageName

import javax.lang.model.SourceVersion; //导入方法依赖的package包/类
/**
 * Computes a Java package name from a namespace URI,
 * as specified in the spec.
 *
 * @return
 *      null if it fails to derive a package name.
 */
public String toPackageName( String nsUri ) {
    // remove scheme and :, if present
    // spec only requires us to remove 'http' and 'urn'...
    int idx = nsUri.indexOf(':');
    String scheme = "";
    if(idx>=0) {
        scheme = nsUri.substring(0,idx);
        if( scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("urn") )
            nsUri = nsUri.substring(idx+1);
    }

    // tokenize string
    ArrayList<String> tokens = tokenize( nsUri, "/: " );
    if( tokens.size() == 0 ) {
        return null;
    }

    // remove trailing file type, if necessary
    if( tokens.size() > 1 ) {
        // for uri's like "www.foo.com" and "foo.com", there is no trailing
        // file, so there's no need to look at the last '.' and substring
        // otherwise, we loose the "com" (which would be wrong)
        String lastToken = tokens.get( tokens.size()-1 );
        idx = lastToken.lastIndexOf( '.' );
        if( idx > 0 ) {
            lastToken = lastToken.substring( 0, idx );
            tokens.set( tokens.size()-1, lastToken );
        }
    }

    // tokenize domain name and reverse.  Also remove :port if it exists
    String domain = tokens.get( 0 );
    idx = domain.indexOf(':');
    if( idx >= 0) domain = domain.substring(0, idx);
    ArrayList<String> r = reverse( tokenize( domain, scheme.equals("urn")?".-":"." ) );
    if( r.get( r.size()-1 ).equalsIgnoreCase( "www" ) ) {
        // remove leading www
        r.remove( r.size()-1 );
    }

    // replace the domain name with tokenized items
    tokens.addAll( 1, r );
    tokens.remove( 0 );

    // iterate through the tokens and apply xml->java name algorithm
    for( int i = 0; i < tokens.size(); i++ ) {

        // get the token and remove illegal chars
        String token = tokens.get( i );
        token = removeIllegalIdentifierChars( token );

        // this will check for reserved keywords
        if (SourceVersion.isKeyword(token.toLowerCase())) {
            token = '_' + token;
        }

        tokens.set( i, token.toLowerCase() );
    }

    // concat all the pieces and return it
    return combine( tokens, '.' );
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:70,代码来源:NameConverter.java


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