Java Code Examples for javax.lang.model.element.Name#contentEquals()
The following examples show how to use
javax.lang.model.element.Name#contentEquals() .
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: JUnit4TestGenerator.java From netbeans with Apache License 2.0 | 6 votes |
/** * Checks that the given annotation is of type * <code>{@value #ANN_RUN_WITH}</code> and contains argument * <code>{@value #ANN_SUITE}{@literal .class}</code>. * * @param annMirror annotation to be checked * @return {@code true} if the annotation meets the described criteria, * {@code false} otherwise */ private boolean checkRunWithSuiteAnnotation(AnnotationMirror annMirror, WorkingCopy workingCopy) { Map<? extends ExecutableElement,? extends AnnotationValue> annParams = annMirror.getElementValues(); if (annParams.size() != 1) { return false; } AnnotationValue annValue = annParams.values().iterator().next(); Name annValueClsName = getAnnotationValueClassName(annValue, workingCopy.getTypes()); return annValueClsName != null ? annValueClsName.contentEquals(ANN_SUITE) : false; }
Example 2
Source File: WebParamDuplicity.java From netbeans with Apache License 2.0 | 6 votes |
/** check if another param has @WebParam annotation of the saem name * * @param subject * @param nameValue * @return */ private boolean isDuplicate(VariableElement subject, Object nameValue) { Element methodEl = subject.getEnclosingElement(); if (ElementKind.METHOD == methodEl.getKind()) { for (VariableElement var: ((ExecutableElement)methodEl).getParameters()) { Name paramName = var.getSimpleName(); if (!paramName.contentEquals(subject.getSimpleName())) { AnnotationMirror paramAnn = Utilities.findAnnotation(var, ANNOTATION_WEBPARAM); if (paramAnn != null) { AnnotationValue val = Utilities.getAnnotationAttrValue(paramAnn, ANNOTATION_ATTRIBUTE_NAME); if (val != null) { if (nameValue.equals(val.getValue())) { return true; } } else if (paramName.contentEquals(nameValue.toString())) { return true; } } else if (paramName.contentEquals(nameValue.toString())) { return true; } } } } return false; }
Example 3
Source File: AnnotationMirrors.java From immutables with Apache License 2.0 | 6 votes |
@Override public Void visitAnnotation(AnnotationMirror a, Void p) { builder.append('@').append(a.getAnnotationType()); Map<? extends ExecutableElement, ? extends AnnotationValue> values = a.getElementValues(); if (!values.isEmpty()) { builder.append('('); boolean notFirst = false; for (Entry<? extends ExecutableElement, ? extends AnnotationValue> e : values.entrySet()) { if (notFirst) { builder.append(", "); } notFirst = true; Name name = e.getKey().getSimpleName(); boolean onlyValue = values.size() == 1 && name.contentEquals(ATTRIBUTE_VALUE); if (!onlyValue) { builder.append(name).append(" = "); } printValue(e.getValue()); } builder.append(')'); } return null; }
Example 4
Source File: ReplaceBufferByString.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Boolean visitNewClass(NewClassTree node, Void p) { TypeMirror tm = ci.getTrees().getTypeMirror(getCurrentPath()); if (tm == null || tm.getKind() != TypeKind.DECLARED) { return false; } TypeElement el = (TypeElement)((DeclaredType)tm).asElement(); if (el == null) { return false; } Name n = el.getQualifiedName(); boolean res = n.contentEquals("java.lang.StringBuilder") || n.contentEquals("java.lang.StringBuffer"); // NOI18N // check if there is some initial contents if (node.getArguments().size() == 1 && Utilities.isJavaString(ci, ci.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getArguments().get(0))))) { hasContents = true; } return res; }
Example 5
Source File: WebBeansActionHelper.java From netbeans with Apache License 2.0 | 6 votes |
static boolean hasAnnotation(Element element,String fqn){ List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotationMirrors) { DeclaredType annotationType = annotationMirror.getAnnotationType(); Element annotationElement = annotationType.asElement(); if ( annotationElement instanceof TypeElement ){ Name qualifiedName = ((TypeElement)annotationElement). getQualifiedName(); if ( qualifiedName.contentEquals(fqn)){ return true; } } } return false; }
Example 6
Source File: IntroduceHint.java From netbeans with Apache License 2.0 | 5 votes |
/** * Crates method formal parameters, following code style conventions. * The trees in 'statements' will be rewritten to use the new identifiers. * * @param copy working copy * @param parameters variables to turn into parameters * @param statements trees that should refer to parameters * @return */ static List<VariableTree> createVariables(WorkingCopy copy, List<VariableElement> parameters, TreePath targetParent, List<TreePath> statements) { final TreeMaker make = copy.getTreeMaker(); List<VariableTree> formalArguments = new LinkedList<VariableTree>(); CodeStyle cs = CodeStyle.getDefault(copy.getFileObject()); String prefix = cs.getParameterNamePrefix(); String suffix = cs.getParameterNameSuffix(); Map<VariableElement, CharSequence> renamedVariables = new HashMap<VariableElement, CharSequence>(); Set<Name> changedNames = new HashSet<Name>(); for (VariableElement p : parameters) { TypeMirror tm = p.asType(); Tree type = make.Type(tm); Name formalArgName = p.getSimpleName(); Set<Modifier> formalArgMods = EnumSet.noneOf(Modifier.class); if (p.getModifiers().contains(Modifier.FINAL)) { formalArgMods.add(Modifier.FINAL); } String strippedName = Utilities.stripVariableName(cs, p); CharSequence codeStyleName = Utilities.guessName(copy, strippedName, targetParent, prefix, suffix, p.getKind() == ElementKind.PARAMETER); if (!formalArgName.contentEquals(codeStyleName)) { renamedVariables.put(p, codeStyleName); changedNames.add(formalArgName); } else { codeStyleName = formalArgName; } formalArguments.add(make.Variable(make.Modifiers(formalArgMods), codeStyleName, type, null)); } if (!changedNames.isEmpty()) { VariableRenamer renamer = new VariableRenamer(copy, renamedVariables, changedNames); for (TreePath stPath : statements) { renamer.scan(stPath, null); } } return formalArguments; }
Example 7
Source File: Util.java From netbeans with Apache License 2.0 | 5 votes |
private static void addXmlRootAnnotation(WorkingCopy working, TreeMaker make){ if ( working.getElements().getTypeElement( XMLROOT_ANNOTATION) == null) { return; } TypeElement entityElement = working.getTopLevelElements().get(0); List<? extends AnnotationMirror> annotationMirrors = working.getElements().getAllAnnotationMirrors( entityElement); boolean hasXmlRootAnnotation = false; for (AnnotationMirror annotationMirror : annotationMirrors) { DeclaredType type = annotationMirror.getAnnotationType(); Element annotationElement = type.asElement(); if ( annotationElement instanceof TypeElement ){ Name annotationName = ((TypeElement)annotationElement). getQualifiedName(); if ( annotationName.contentEquals(XMLROOT_ANNOTATION)) { hasXmlRootAnnotation = true; } } } if ( !hasXmlRootAnnotation ){ ClassTree classTree = working.getTrees().getTree( entityElement); GenerationUtils genUtils = GenerationUtils. newInstance(working); ModifiersTree modifiersTree = make.addModifiersAnnotation( classTree.getModifiers(), genUtils.createAnnotation(XMLROOT_ANNOTATION)); working.rewrite( classTree.getModifiers(), modifiersTree); } }
Example 8
Source File: EEInjectiontargetQueryImplementation.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean isInjectionTarget(CompilationController controller, TypeElement typeElement) { if (controller == null || typeElement==null) { throw new NullPointerException("Passed null to EEInjectiontargetQueryImplementation.isInjectionTarget(CompilationController, TypeElement)"); // NOI18N } FileObject fo = controller.getFileObject(); Project project = FileOwnerQuery.getOwner(fo); J2eeProjectCapabilities j2eeProjectCapabilities = J2eeProjectCapabilities.forProject(project); if (j2eeProjectCapabilities == null) { return false; } boolean ejb31 = j2eeProjectCapabilities.isEjb31Supported() || j2eeProjectCapabilities.isEjb31LiteSupported();//it's foe ee6 only or common annotations 1.1 if (ejb31 && !(ElementKind.INTERFACE==typeElement.getKind())) { List<? extends AnnotationMirror> annotations = typeElement.getAnnotationMirrors(); boolean found = false; for (AnnotationMirror m : annotations) { Name qualifiedName = ((TypeElement)m.getAnnotationType().asElement()).getQualifiedName(); if (qualifiedName.contentEquals("javax.annotation.ManagedBean")) { //NOI18N found = true; break; } } if (found) return true; } return false; }
Example 9
Source File: Util.java From netbeans with Apache License 2.0 | 5 votes |
protected static boolean containsName(String[] stringNames, Name name) { for (String stringName : stringNames) { if (name.contentEquals(stringName)) { return true; } } return false; }
Example 10
Source File: WSCompletionProvider.java From netbeans with Apache License 2.0 | 5 votes |
private void createAssignmentResults(CompilationController controller, Env env) throws IOException { TreePath elementPath = env.getPath(); TreePath parentPath = elementPath.getParentPath(); Tree parent = parentPath.getLeaf(); switch (parent.getKind()) { case ANNOTATION : { ExpressionTree var = ((AssignmentTree)elementPath.getLeaf()). getVariable(); if (var!= null && var.getKind() == Kind.IDENTIFIER) { Name name = ((IdentifierTree)var).getName(); if (name.contentEquals("value")) {//NOI18N controller.toPhase(Phase.ELEMENTS_RESOLVED); TypeElement webParamEl = controller.getElements(). getTypeElement("javax.xml.ws.BindingType"); //NOI18N if (webParamEl==null) { hasErrors = true; return; } TypeMirror el = controller.getTrees().getTypeMirror(parentPath); if (el==null || el.getKind() == TypeKind.ERROR) { hasErrors = true; return; } if ( controller.getTypes().isSameType(el,webParamEl.asType())) { for (String mode : BINDING_TYPES) { if (mode.startsWith(env.getPrefix())){ results.add(WSCompletionItem. createEnumItem(mode, "String", env.getOffset())); //NOI18N } } } } } } break; // ANNOTATION } }
Example 11
Source File: ImportsTrackerTestHelper.java From buck with Apache License 2.0 | 5 votes |
private static void handleImport(Trees trees, ImportsTracker imports, TreePath importTreePath) { ImportTree importTree = (ImportTree) importTreePath.getLeaf(); MemberSelectTree importedExpression = (MemberSelectTree) importTree.getQualifiedIdentifier(); TreePath importedExpressionPath = new TreePath(importTreePath, importedExpression); Name simpleName = importedExpression.getIdentifier(); boolean isStarImport = simpleName.contentEquals("*"); if (!isStarImport && !importTree.isStatic()) { TypeElement importedType = (TypeElement) trees.getElement(importedExpressionPath); imports.importType(importedType, importedExpressionPath); } else { ExpressionTree containingElementExpression = importedExpression.getExpression(); TreePath containingElementExpressionPath = new TreePath(importedExpressionPath, containingElementExpression); QualifiedNameable containingElement = (QualifiedNameable) trees.getElement(containingElementExpressionPath); if (importTree.isStatic()) { TypeElement containingType = (TypeElement) containingElement; if (isStarImport) { imports.importStaticMembers((TypeElement) containingElement); } else { imports.importStatic(containingType, simpleName); } } else { // Normal star import imports.importMembers(containingElement, containingElementExpressionPath); } } }
Example 12
Source File: ElementJavadoc.java From netbeans with Apache License 2.0 | 5 votes |
private Integer getIdx(Element e, Name n) { if (e instanceof ExecutableElement && n != null) { int idx = 0; for (VariableElement par : ((ExecutableElement)e).getParameters()) { if (n.contentEquals(par.getSimpleName())) { return idx; } idx++; } } return null; }
Example 13
Source File: GwtCompatibility.java From SimpleWeibo with Apache License 2.0 | 5 votes |
GwtCompatibility(TypeElement type) { Optional<AnnotationMirror> gwtCompatibleAnnotation = Optional.absent(); List<? extends AnnotationMirror> annotations = type.getAnnotationMirrors(); for (AnnotationMirror annotation : annotations) { Name name = annotation.getAnnotationType().asElement().getSimpleName(); if (name.contentEquals("GwtCompatible")) { gwtCompatibleAnnotation = Optional.of(annotation); } } this.gwtCompatibleAnnotation = gwtCompatibleAnnotation; }
Example 14
Source File: GeneratorUtilitiesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void validate(CompilationInfo info) { TypeElement test = info.getElements().getTypeElement("test.Test"); ClassTree ct = info.getTrees().getTree(test); assertNotNull(ct); int foundTestIdx = -1; int idx = 0; for (Tree t : ct.getMembers()) { Name name = null; switch(t.getKind()) { case VARIABLE: name = ((VariableTree)t).getName(); break; case METHOD: name = ((MethodTree)t).getName(); break; case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE: name = ((ClassTree)t).getSimpleName(); break; } if (name != null) { if (name.contentEquals("test")) { assertEquals(-1, foundTestIdx); foundTestIdx = idx; } else if (name.contentEquals("<init>") && ((MethodTree)t).getParameters().size() > 0) { assertEquals(-1, foundTestIdx); foundTestIdx = idx; } } idx++; } assertEquals(testIdx, foundTestIdx); }
Example 15
Source File: ElementUtilities.java From netbeans with Apache License 2.0 | 5 votes |
private boolean overridesPackagePrivateOutsidePackage(ExecutableElement ee, TypeElement impl) { Name elemPackageName = getPackageName(ee); Name currentPackageName = getPackageName(impl); return !ee.getModifiers().contains(Modifier.PRIVATE) && !ee.getModifiers().contains(Modifier.PUBLIC) && !ee.getModifiers().contains(Modifier.PROTECTED) && !currentPackageName.contentEquals(elemPackageName); }
Example 16
Source File: ValueAttribute.java From immutables with Apache License 2.0 | 4 votes |
private void initSpecialAnnotations() { Environment environment = containingType.constitution.protoclass().environment(); ImmutableList.Builder<AnnotationInjection> annotationInjections = null; for (AnnotationMirror annotation : element.getAnnotationMirrors()) { MetaAnnotated metaAnnotated = MetaAnnotated.from(annotation, environment); for (InjectionInfo info : metaAnnotated.injectAnnotation()) { if (annotationInjections == null) { annotationInjections = ImmutableList.builder(); } annotationInjections.add(info.injectionFor(annotation, environment)); } TypeElement annotationElement = (TypeElement) annotation.getAnnotationType().asElement(); Name simpleName = annotationElement.getSimpleName(); Name qualifiedName = annotationElement.getQualifiedName(); if (isNullableAnnotation(simpleName, qualifiedName)) { nullability = ImmutableNullabilityAnnotationInfo.of(annotationElement); } else if (simpleName.contentEquals(TypeStringProvider.EPHEMERAL_ANNOTATION_ALLOW_NULLS)) { nullElements = NullElements.ALLOW; } else if (simpleName.contentEquals(TypeStringProvider.EPHEMERAL_ANNOTATION_SKIP_NULLS)) { nullElements = NullElements.SKIP; } } if (containingType.isGenerateJacksonProperties() && typeKind.isMap() && Proto.isAnnotatedWith(element, Annotations.JACKSON_ANY_GETTER)) { jacksonAnyGetter = true; } if (containingType.isGenerateJacksonMapped() && (isGenerateAbstract || isGenerateDefault) && Proto.isAnnotatedWith(element, Annotations.JACKSON_VALUE)) { jacksonValue = true; } if (isCollectionType() && nullElements == NullElements.BAN && protoclass().styles().style().validationMethod() == ValidationMethod.NONE) { nullElements = NullElements.NOP; } if (annotationInjections != null) { this.annotationInjections = annotationInjections.build(); } }
Example 17
Source File: InlineVariableTransformer.java From netbeans with Apache License 2.0 | 4 votes |
private void replaceUsageIfMatch(TreePath path, Tree tree, Element elementToFind) { if (workingCopy.getTreeUtilities().isSynthetic(path)) { return; } Trees trees = workingCopy.getTrees(); Element el = workingCopy.getTrees().getElement(path); if (el == null) { path = path.getParentPath(); if (path != null && path.getLeaf().getKind() == Tree.Kind.IMPORT) { ImportTree impTree = (ImportTree) path.getLeaf(); if (!impTree.isStatic()) { return; } Tree idTree = impTree.getQualifiedIdentifier(); if (idTree.getKind() != Tree.Kind.MEMBER_SELECT) { return; } final Name id = ((MemberSelectTree) idTree).getIdentifier(); if (id == null || id.contentEquals("*")) { // NOI18N // skip import static java.lang.Math.* return; } Tree classTree = ((MemberSelectTree) idTree).getExpression(); path = trees.getPath(workingCopy.getCompilationUnit(), classTree); el = trees.getElement(path); if (el == null) { return; } Iterator<? extends Element> iter = workingCopy.getElementUtilities().getMembers(el.asType(), new ElementUtilities.ElementAcceptor() { @Override public boolean accept(Element e, TypeMirror type) { return id.equals(e.getSimpleName()); } }).iterator(); if (iter.hasNext()) { el = iter.next(); } if (iter.hasNext()) { return; } } else { return; } } if (el.equals(elementToFind)) { GeneratorUtilities genUtils = GeneratorUtilities.get(workingCopy); TreePath resolvedPath = trees.getPath(elementToFind); VariableTree varTree = (VariableTree)resolvedPath.getLeaf(); varTree = genUtils.importComments(varTree, resolvedPath.getCompilationUnit()); ExpressionTree body = varTree.getInitializer(); boolean parenthesize = OperatorPrecedence.needsParentheses(path, elementToFind, varTree.getInitializer(), workingCopy); if (parenthesize) { body = make.Parenthesized((ExpressionTree) body); } genUtils.copyComments(varTree, body, true); rewrite(tree, body); } }
Example 18
Source File: AccessorAttributesCollector.java From immutables with Apache License 2.0 | 4 votes |
private void processUtilityCandidateMethod(ExecutableElement utilityMethodCandidate, TypeElement originalType) { Name name = utilityMethodCandidate.getSimpleName(); List<? extends VariableElement> parameters = utilityMethodCandidate.getParameters(); TypeElement definingType = (TypeElement) utilityMethodCandidate.getEnclosingElement(); boolean nonFinal = !utilityMethodCandidate.getModifiers().contains(Modifier.FINAL); boolean nonAbstract = !utilityMethodCandidate.getModifiers().contains(Modifier.ABSTRACT); if (isJavaLangObjectType(definingType)) { // We ignore methods of java.lang.Object return; } if (name.contentEquals(EQUALS_METHOD) && parameters.size() == 1 && isJavaLangObjectType(parameters.get(0).asType())) { if (nonAbstract) { type.isEqualToDefined = true; type.isEqualToFinal = !nonFinal; if (!definingType.equals(originalType) && hasNonInheritedAttributes && nonFinal) { report(originalType) .warning(About.INCOMPAT, "Type inherits overriden 'equals' method but have some non-inherited attributes." + " Please override 'equals' with abstract method to have it generate. Otherwise override" + " with calling super implemtation to use custom implementation"); } } return; } if (name.contentEquals(HASH_CODE_METHOD) && parameters.isEmpty()) { if (nonAbstract) { type.isHashCodeDefined = true; type.isHashCodeFinal = !nonFinal; // inherited non-abstract implementation if (!definingType.equals(originalType) && hasNonInheritedAttributes && nonFinal) { report(originalType) .warning(About.INCOMPAT, "Type inherits non-default 'hashCode' method but have some non-inherited attributes." + " Please override 'hashCode' with abstract method to have it generated. Otherwise override" + " with calling super implemtation to use custom implementation"); } } return; } if (name.contentEquals(TO_STRING_METHOD) && parameters.isEmpty()) { if (nonAbstract) { type.isToStringDefined = true; // inherited non-abstract implementation if (!definingType.equals(originalType) && hasNonInheritedAttributes && nonFinal) { report(originalType) .warning(About.INCOMPAT, "Type inherits non-default 'toString' method but have some non-inherited attributes." + " Please override 'toString' with abstract method to have generate it. Otherwise override" + " with calling super implementation to use custom implementation"); } } return; } }
Example 19
Source File: WSCompletionProvider.java From netbeans with Apache License 2.0 | 4 votes |
private void createStringResults(CompilationController controller, Env env) throws IOException { TreePath elementPath = env.getPath(); TreePath parentPath = elementPath.getParentPath(); Tree parent = parentPath.getLeaf(); Tree grandParent = parentPath.getParentPath().getLeaf(); switch (grandParent.getKind()) { case ANNOTATION : { switch (parent.getKind()) { case ASSIGNMENT : { ExpressionTree var = ((AssignmentTree)parent).getVariable(); if (var.getKind() == Kind.IDENTIFIER) { Name name = ((IdentifierTree)var).getName(); if (!name.contentEquals("wsdlLocation") || //NOI18N jaxWsSupport==null) { return; } controller.toPhase(Phase.ELEMENTS_RESOLVED); TypeElement webMethodEl = controller .getElements().getTypeElement( "javax.jws.WebService"); // NOI18N if (webMethodEl == null) { hasErrors = true; return; } TypeMirror el = controller.getTrees().getTypeMirror( parentPath.getParentPath()); if (el == null || el.getKind() == TypeKind.ERROR) { hasErrors = true; return; } if (controller.getTypes().isSameType(el, webMethodEl.asType())) { FileObject wsdlFolder = jaxWsSupport .getWsdlFolder(false); if (wsdlFolder != null) { Enumeration<? extends FileObject> en = wsdlFolder.getChildren(true); while (en.hasMoreElements()) { FileObject fo = en.nextElement(); if (!fo.isData() || !"wsdl" // NOI18N .equalsIgnoreCase(fo.getExt())) { continue; } String wsdlPath = FileUtil.getRelativePath( wsdlFolder.getParent() .getParent(),fo); // Temporary fix for wsdl // files in EJB project if (wsdlPath.startsWith("conf/")) // NOI18 { wsdlPath = "META-INF/"+ wsdlPath// NOI18 .substring(5); } if (wsdlPath.startsWith(env.getPrefix())) { results.add(WSCompletionItem .createWsdlFileItem( wsdlFolder, fo, env.getOffset())); } } } } } } break; //ASSIGNMENT } } break; // ANNOTATION } }
Example 20
Source File: TreeDiffer.java From compile-testing with Apache License 2.0 | 4 votes |
private boolean namesEqual(@Nullable Name expected, @Nullable Name actual) { return (expected == null) ? actual == null : (actual != null && expected.contentEquals(actual)); }