Java Code Examples for javax.lang.model.element.Name#equals()

The following examples show how to use javax.lang.model.element.Name#equals() . 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: Analyzer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({"# {0} - @param name", "UNKNOWN_TYPEPARAM_DESC=Unknown @param: {0}",
                    "# {0} - @param name", "DUPLICATE_PARAM_DESC=Duplicate @param name: {0}"})
private void checkParamDeclared(ParamTree tree, List<? extends Element> list,
        DocTreePathHandle dtph, int start, int end, List<ErrorDescription> errors) {
    Name name = tree.getName().getName();
    boolean found = false;
    for (Element e: list) {
        if(ctx.isCanceled()) { return; }
        if (name.equals(e.getSimpleName())) {
            if(!foundParams.add(e)) {
                errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, DUPLICATE_PARAM_DESC(name), new RemoveTagFix(dtph, "@param").toEditorFix())); // NOI18N
            }
            found = true;
        }
    }
    if (!found) {
        errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, UNKNOWN_TYPEPARAM_DESC(name), new RemoveTagFix(dtph, "@param").toEditorFix())); //NOI18N
    }
}
 
Example 2
Source File: TypeSimplifier.java    From auto with Apache License 2.0 6 votes vote down vote up
private static Set<String> ambiguousNames(Types typeUtils, Set<TypeMirror> types) {
  Set<String> ambiguous = new HashSet<>();
  Map<String, Name> simpleNamesToQualifiedNames = new HashMap<>();
  for (TypeMirror type : types) {
    if (type.getKind() == TypeKind.ERROR) {
      throw new MissingTypeException(MoreTypes.asError(type));
    }
    String simpleName = typeUtils.asElement(type).getSimpleName().toString();
    /*
     * Compare by qualified names, because in Eclipse JDT, if Java 8 type annotations are used,
     * the same (unannotated) type may appear multiple times in the Set<TypeMirror>.
     * TODO(emcmanus): investigate further, because this might cause problems elsewhere.
     */
    Name qualifiedName = ((QualifiedNameable) typeUtils.asElement(type)).getQualifiedName();
    Name previous = simpleNamesToQualifiedNames.put(simpleName, qualifiedName);
    if (previous != null && !previous.equals(qualifiedName)) {
      ambiguous.add(simpleName);
    }
  }
  return ambiguous;
}
 
Example 3
Source File: LLNI.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected final boolean needLongName(ExecutableElement method,
                                     TypeElement clazz) {
    Name methodName = method.getSimpleName();
    for (ExecutableElement memberMethod: methods) {
        if ((memberMethod != method) &&
            memberMethod.getModifiers().contains(Modifier.NATIVE) &&
                (methodName.equals(memberMethod.getSimpleName())))
            return true;
    }
    return false;
}
 
Example 4
Source File: LLNI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected final boolean needLongName(ExecutableElement method,
                                     TypeElement clazz) {
    Name methodName = method.getSimpleName();
    for (ExecutableElement memberMethod: methods) {
        if ((memberMethod != method) &&
            memberMethod.getModifiers().contains(Modifier.NATIVE) &&
                (methodName.equals(memberMethod.getSimpleName())))
            return true;
    }
    return false;
}
 
Example 5
Source File: LLNI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected final boolean needLongName(ExecutableElement method,
                                     TypeElement clazz) {
    Name methodName = method.getSimpleName();
    for (ExecutableElement memberMethod: methods) {
        if ((memberMethod != method) &&
            memberMethod.getModifiers().contains(Modifier.NATIVE) &&
                (methodName.equals(memberMethod.getSimpleName())))
            return true;
    }
    return false;
}
 
Example 6
Source File: LLNI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected final boolean needLongName(ExecutableElement method,
                                     TypeElement clazz) {
    Name methodName = method.getSimpleName();
    for (ExecutableElement memberMethod: methods) {
        if ((memberMethod != method) &&
            memberMethod.getModifiers().contains(Modifier.NATIVE) &&
                (methodName.equals(memberMethod.getSimpleName())))
            return true;
    }
    return false;
}
 
Example 7
Source File: LLNI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected final boolean needLongName(ExecutableElement method,
                                     TypeElement clazz) {
    Name methodName = method.getSimpleName();
    for (ExecutableElement memberMethod: methods) {
        if ((memberMethod != method) &&
            memberMethod.getModifiers().contains(Modifier.NATIVE) &&
                (methodName.equals(memberMethod.getSimpleName())))
            return true;
    }
    return false;
}
 
Example 8
Source File: LLNI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected final boolean needLongName(ExecutableElement method,
                                     TypeElement clazz) {
    Name methodName = method.getSimpleName();
    for (ExecutableElement memberMethod: methods) {
        if ((memberMethod != method) &&
            memberMethod.getModifiers().contains(Modifier.NATIVE) &&
                (methodName.equals(memberMethod.getSimpleName())))
            return true;
    }
    return false;
}
 
Example 9
Source File: LLNI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected final boolean needLongName(ExecutableElement method,
                                     TypeElement clazz) {
    Name methodName = method.getSimpleName();
    for (ExecutableElement memberMethod: methods) {
        if ((memberMethod != method) &&
            memberMethod.getModifiers().contains(Modifier.NATIVE) &&
                (methodName.equals(memberMethod.getSimpleName())))
            return true;
    }
    return false;
}
 
Example 10
Source File: LLNI.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected final boolean needLongName(ExecutableElement method,
                                     TypeElement clazz) {
    Name methodName = method.getSimpleName();
    for (ExecutableElement memberMethod: methods) {
        if ((memberMethod != method) &&
            memberMethod.getModifiers().contains(Modifier.NATIVE) &&
                (methodName.equals(memberMethod.getSimpleName())))
            return true;
    }
    return false;
}
 
Example 11
Source File: ModelNode.java    From featured with Apache License 2.0 5 votes vote down vote up
public void detectInheritance(ProcessingEnvironment env) {
    Collection<FeatureNode> featureNodes = getFeatureNodes();
    for (FeatureNode featureNode : featureNodes) {

        // feature has inheriting features if it is parametrized with generics
        List<? extends TypeParameterElement> typeParams =
                featureNode.getElement().getTypeParameters();
        if (typeParams.size() > 0) {
            featureNode.setHasInheritingFeatureNodes(true);
            continue;
        }

        // look up for super-features within collected nodes
        TypeMirror superType = featureNode.getElement().getSuperclass();
        while (superType.getKind() != TypeKind.NONE) {
            for (FeatureNode otherFeatureNode : featureNodes) {
                if (featureNode == otherFeatureNode) {
                    continue;
                }
                Name otherName = otherFeatureNode.getElement().getQualifiedName();
                Name superName = ((TypeElement) env.getTypeUtils()
                        .asElement(superType)).getQualifiedName();
                if (otherName.equals(superName)) {
                    featureNode.setSuperFeatureNode(otherFeatureNode);
                    break;
                }
            }
            superType = ((TypeElement) env.getTypeUtils().asElement(superType)).getSuperclass();
        }
    }
}
 
Example 12
Source File: StaticAccess.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected static Fix computeFixes(CompilationInfo info, TreePath treePath, int[] bounds, int[] kind, String[] simpleName) {
    if (treePath.getLeaf().getKind() != Kind.MEMBER_SELECT) {
        return null;
    }
    MemberSelectTree mst = (MemberSelectTree)treePath.getLeaf();
    Tree expression = mst.getExpression();
    TreePath expr = new TreePath(treePath, expression);
    
    TypeMirror tm = info.getTrees().getTypeMirror(expr);
    if (!Utilities.isValidType(tm)) {
        return null;
    }
    Element el = info.getTypes().asElement(tm);
    if (el == null || (!el.getKind().isClass() && !el.getKind().isInterface())) {
        return null;
    }
    
    TypeElement type = (TypeElement)el;
    
    if (isError(type)) {
        return null;
    }
    
    Name idName = null;
    
    if (expression.getKind() == Kind.MEMBER_SELECT) {
        MemberSelectTree exprSelect = (MemberSelectTree)expression;
        idName = exprSelect.getIdentifier();
    }
    
    if (expression.getKind() == Kind.IDENTIFIER) {
        IdentifierTree idt = (IdentifierTree)expression;
        idName = idt.getName();
    }
    
    if (idName != null) {
        if (idName.equals(type.getSimpleName())) {
            return null;
        }
        if (idName.equals(type.getQualifiedName())) {
            return null;
        }
    }
    
    Element used = info.getTrees().getElement(treePath);
    
    if (used == null || !used.getModifiers().contains(Modifier.STATIC)) {
        return null;
    }
    
    if (isError(used)) {
        return null;
    }
    
    if (used.getKind().isField()) {
        kind[0] = 0;
    } else {
        if (used.getKind() == ElementKind.METHOD) {
            kind[0] = 1;
        } else {
            kind[0] = 2;
        }
    }
    
    simpleName[0] = used.getSimpleName().toString();
    
    return new FixImpl(info, expr, type).toEditorFix();
}