Java Code Examples for javax.lang.model.element.AnnotationMirror#getElementValues()
The following examples show how to use
javax.lang.model.element.AnnotationMirror#getElementValues() .
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: AbstractScopedAnalyzer.java From netbeans with Apache License 2.0 | 6 votes |
protected boolean isPassivatingScope( TypeElement scope, WebBeansModel model ) { AnnotationMirror normalScope = AnnotationUtil.getAnnotationMirror( scope, model.getCompilationController(), AnnotationUtil.NORMAL_SCOPE_FQN); if ( normalScope==null){ return false; } Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = normalScope.getElementValues(); boolean isPassivating = false; for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry: elementValues.entrySet()) { ExecutableElement key = entry.getKey(); if ( key.getSimpleName().contentEquals(AnnotationUtil.PASSIVATING)){ isPassivating = Boolean.TRUE.toString().equals(entry.getValue().toString()); } } return isPassivating; }
Example 2
Source File: ElementJavadoc.java From netbeans with Apache License 2.0 | 6 votes |
private void appendAnnotation(StringBuilder sb, AnnotationMirror annotationDesc, boolean topLevel) { DeclaredType annotationType = annotationDesc.getAnnotationType(); if (annotationType != null && (!topLevel || isDocumented(annotationType))) { appendType(sb, annotationType, false, false, true); Map<? extends ExecutableElement, ? extends AnnotationValue> values = annotationDesc.getElementValues(); if (!values.isEmpty()) { sb.append('('); //NOI18N for (Iterator<? extends Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>> it = values.entrySet().iterator(); it.hasNext();) { Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> value = it.next(); createLink(sb, value.getKey(), value.getKey().getSimpleName()); sb.append('='); //NOI18N appendAnnotationValue(sb, value.getValue()); if (it.hasNext()) sb.append(","); //NOI18N } sb.append(')'); //NOI18N } if (topLevel) sb.append("<br>"); //NOI18N } }
Example 3
Source File: MappedSuperclassImpl.java From netbeans with Apache License 2.0 | 6 votes |
boolean refresh(TypeElement typeElement) { class2 = typeElement.getQualifiedName().toString(); AnnotationModelHelper helper = getHelper(); Map<String, ? extends AnnotationMirror> annByType = helper.getAnnotationsByType(typeElement.getAnnotationMirrors()); AnnotationMirror embeddableAnn = annByType.get("javax.persistence.MappedSuperclass"); // NOI18N AnnotationMirror entityAcc = annByType.get("javax.persistence.Access"); // NOI18N if (entityAcc != null) { entityAcc.getElementValues(); AnnotationParser parser = AnnotationParser.create(helper); parser.expect("value", new ValueProvider() { @Override public Object getValue(AnnotationValue elementValue) { return elementValue.toString(); } @Override public Object getDefaultValue() { return null; } });//NOI18N ParseResult parseResult = parser.parse(entityAcc); accessType = parseResult.get("value", String.class); } return embeddableAnn != null; }
Example 4
Source File: Utils.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Return true if the given Element is deprecated for removal. * * @param e the Element to check. * @return true if the given Element is deprecated for removal. */ public boolean isDeprecatedForRemoval(Element e) { List<? extends AnnotationMirror> annotationList = e.getAnnotationMirrors(); JavacTypes jctypes = ((DocEnvImpl) configuration.docEnv).toolEnv.typeutils; for (AnnotationMirror anno : annotationList) { if (jctypes.isSameType(anno.getAnnotationType().asElement().asType(), getDeprecatedType())) { Map<? extends ExecutableElement, ? extends AnnotationValue> pairs = anno.getElementValues(); if (!pairs.isEmpty()) { for (ExecutableElement element : pairs.keySet()) { if (element.getSimpleName().contentEquals("forRemoval")) { return Boolean.parseBoolean((pairs.get(element)).toString()); } } } } } return false; }
Example 5
Source File: StereotypeAnalyzer.java From netbeans with Apache License 2.0 | 6 votes |
private void checkName( TypeElement element, WebBeansModel model, Result result ) { AnnotationMirror named = AnnotationUtil.getAnnotationMirror(element, AnnotationUtil.NAMED , model.getCompilationController()); if ( named == null ){ return; } Map<? extends ExecutableElement, ? extends AnnotationValue> members = named.getElementValues(); for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry: members.entrySet()) { ExecutableElement member = entry.getKey(); if ( member.getSimpleName().contentEquals(AnnotationUtil.VALUE)){ result.addError( element, model, NbBundle.getMessage(StereotypeAnalyzer.class, "ERR_NonEmptyNamedStereotype")); // NOI18N } } }
Example 6
Source File: CompletionCandidatesMetaData.java From picocli with Apache License 2.0 | 6 votes |
/** * Returns the completion candidates from the annotations present on the specified element. * @param element the method or field annotated with {@code @Option} or {@code @Parameters} * @return the completion candidates or {@code null} if not found */ public static Iterable<String> extract(Element element) { List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors(); for (AnnotationMirror mirror : annotationMirrors) { DeclaredType annotationType = mirror.getAnnotationType(); if (TypeUtil.isOption(annotationType) || TypeUtil.isParameter(annotationType)) { Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = mirror.getElementValues(); for (ExecutableElement attribute : elementValues.keySet()) { if ("completionCandidates".equals(attribute.getSimpleName().toString())) { AnnotationValue typeMirror = elementValues.get(attribute); return new CompletionCandidatesMetaData((TypeMirror) typeMirror); } } } } return null; }
Example 7
Source File: ParameterConsumerMetaData.java From picocli with Apache License 2.0 | 6 votes |
/** * Returns the type converters from the annotations present on the specified element. * @param element the method or field annotated with {@code @Option} or {@code @Parameters} * @return the type converters or an empty array if not found */ @SuppressWarnings("unchecked") public static ParameterConsumerMetaData extract(Element element) { List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors(); for (AnnotationMirror mirror : annotationMirrors) { DeclaredType annotationType = mirror.getAnnotationType(); if (TypeUtil.isOption(annotationType) || TypeUtil.isParameter(annotationType)) { Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = mirror.getElementValues(); for (ExecutableElement attribute : elementValues.keySet()) { if ("parameterConsumer".equals(attribute.getSimpleName().toString())) { AnnotationValue parameterConsumer = elementValues.get(attribute); TypeMirror typeMirror = (TypeMirror) parameterConsumer.getValue(); if (typeMirror != null) { return new ParameterConsumerMetaData(typeMirror); } } } } } return null; }
Example 8
Source File: JaxWsNode.java From netbeans with Apache License 2.0 | 6 votes |
private String getServiceName(CompilationController controller, TypeElement classElement) { // check service name AnnotationMirror anMirror = _RetoucheUtil.getAnnotation(controller, classElement, "javax.jws.WebService"); // NOI18N if ( anMirror == null ){ return null; } java.util.Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = anMirror.getElementValues(); for (java.util.Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : expressions.entrySet()) { if (entry.getKey().getSimpleName().contentEquals("serviceName")) { // NOI18N return (String) expressions.get(entry.getKey()).getValue(); } } return null; }
Example 9
Source File: FxClassUtils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Attempts to find the {@code @DefaultProperty} annotation on the type, and returns * the default property name. Returns null, if @DefaultProperty is not defined * * @param te type to inspect * @return default property name, or {@code null} if default property is not defined for the type. */ public static String getDefaultProperty(TypeElement te) { for (AnnotationMirror an : te.getAnnotationMirrors()) { if (!((TypeElement)an.getAnnotationType().asElement()).getQualifiedName().contentEquals(DEFAULT_PROPERTY_TYPE_NAME)) { continue; } Map<? extends ExecutableElement, ? extends AnnotationValue> m = an.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> en : m.entrySet()) { if (en.getKey().getSimpleName().contentEquals(DEFAULT_PROPERTY_VALUE_NAME)) { Object v = en.getValue().getValue(); return v == null ? null : v.toString(); } } } return null; }
Example 10
Source File: JaxWsAddOperation.java From netbeans with Apache License 2.0 | 6 votes |
private boolean isJaxWsImplementationClass(TypeElement classEl, CompilationController controller) { TypeElement wsElement = controller.getElements().getTypeElement("javax.jws.WebService"); //NOI18N if (wsElement != null) { List<? extends AnnotationMirror> annotations = classEl.getAnnotationMirrors(); for (AnnotationMirror anMirror : annotations) { if (controller.getTypes().isSameType(wsElement.asType(), anMirror.getAnnotationType())) { Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = anMirror.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : expressions.entrySet()) { if (entry.getKey().getSimpleName().contentEquals("wsdlLocation")) { //NOI18N return false; } } return true; } } } return false; }
Example 11
Source File: InvokingMessageProcessor.java From SmartEventBus with Apache License 2.0 | 6 votes |
private String getEventType(Element element1) { List<? extends AnnotationMirror> annotationMirrors = elements.getAllAnnotationMirrors(element1); if (annotationMirrors != null && annotationMirrors.size() > 0) { for (AnnotationMirror annotationMirror : annotationMirrors) { if (ANNOTATION_NAME.equals(annotationMirror.getAnnotationType().toString())) { System.out.println(TAG + "annotationMirror: " + annotationMirror.getAnnotationType().toString()); if (annotationMirror.getElementValues() != null) { for (AnnotationValue annotationValue : annotationMirror.getElementValues().values()) { return annotationValue.getValue().toString(); } } } } } return null; }
Example 12
Source File: DeclaredIBindingsAnalyzer.java From netbeans with Apache License 2.0 | 6 votes |
private boolean isSame( AnnotationMirror first, AnnotationMirror second , CompilationController controller ) { Element firstElement = first.getAnnotationType().asElement(); Element secondElement = second.getAnnotationType().asElement(); if ( !firstElement.equals(secondElement)){ return false; } Map<? extends ExecutableElement, ? extends AnnotationValue> firstValues = first.getElementValues(); Map<? extends ExecutableElement, ? extends AnnotationValue> secondValues = second.getElementValues(); if ( firstValues.size() != secondValues.size() ){ return false; } for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : firstValues.entrySet()) { AnnotationValue secondValue = secondValues.get(entry.getKey()); AnnotationValue firstValue = entry.getValue(); if ( !isSame( firstValue, secondValue, controller )){ return false; } } return true; }
Example 13
Source File: DataLoaderProcessor.java From DataLoader with Apache License 2.0 | 6 votes |
private <T> T getAnnotation(Element element, Class<? extends Annotation> type, String name) { String canonicalName = type.getCanonicalName(); List<? extends AnnotationMirror> annotationMirrors = elements.getAllAnnotationMirrors(element); if (annotationMirrors != null && annotationMirrors.size() > 0) { for (AnnotationMirror annotationMirror : annotationMirrors) { if (canonicalName.equals(annotationMirror.getAnnotationType().toString())) { if (annotationMirror.getElementValues() != null) { for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) { ExecutableElement annotationName = entry.getKey(); AnnotationValue annotationValue = entry.getValue(); if (annotationName.getSimpleName().toString().equals(name)) { return (T) annotationValue.getValue(); } } } } } } return null; }
Example 14
Source File: ElementUtils.java From spring-init with Apache License 2.0 | 5 votes |
public List<String> getStringsFromAnnotation(AnnotationMirror annotationMirror, String fieldname) { List<String> collected = new ArrayList<>(); if (annotationMirror != null) { Map<? extends ExecutableElement, ? extends AnnotationValue> values = annotationMirror .getElementValues(); for (ExecutableElement element : values.keySet()) { if (element.getSimpleName().toString().equals(fieldname)) { values.get(element).accept(stringCollector, collected); } } } return collected; }
Example 15
Source File: ApiImplProcessor.java From ApiManager with Apache License 2.0 | 5 votes |
private ApiContract<ClassName> getApiClassNameContract(TypeElement apiImplElement) { String apiClassSymbol = null; List<? extends AnnotationMirror> annotationMirrors = apiImplElement.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotationMirrors) { Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) { apiClassSymbol = entry.getValue().accept(annotationValueVisitor, null); } } ClassName apiName = ClassName.get(elements.getTypeElement(apiClassSymbol)); ClassName apiImplName = ClassName.get(apiImplElement); return new ApiContract<>(apiName, apiImplName); }
Example 16
Source File: ElementUtils.java From spring-init with Apache License 2.0 | 5 votes |
public List<TypeElement> getTypesFromAnnotation(AnnotationMirror annotationMirror, String fieldname) { List<TypeElement> collected = new ArrayList<>(); if (annotationMirror != null) { Map<? extends ExecutableElement, ? extends AnnotationValue> values = annotationMirror .getElementValues(); for (ExecutableElement element : values.keySet()) { if (element.getSimpleName().toString().equals(fieldname)) { values.get(element).accept(typeCollector, collected); } } } return collected; }
Example 17
Source File: JUnit4TestGenerator.java From netbeans with Apache License 2.0 | 5 votes |
/** * Checks that the given annotation is of type * <code>{@value #ANN_SUITE}.{@value #ANN_SUITE_MEMBERS}</code> * and contains the given list of classes as (the only) argument, * in the same order. * * @param annMirror annotation to be checked * @param suiteMembers list of fully qualified class names denoting * content of the test suite * @return {@code true} if the annotation meets the described criteria, * {@code false} otherwise */ private boolean checkSuiteMembersAnnotation(AnnotationMirror annMirror, List<String> suiteMembers, WorkingCopy workingCopy) { Map<? extends ExecutableElement,? extends AnnotationValue> annParams = annMirror.getElementValues(); if (annParams.size() != 1) { return false; } AnnotationValue annValue = annParams.values().iterator().next(); Object value = annValue.getValue(); if (value instanceof java.util.List) { List<? extends AnnotationValue> items = (List<? extends AnnotationValue>) value; if (items.size() != suiteMembers.size()) { return false; } Types types = workingCopy.getTypes(); Iterator<String> suiteMembersIt = suiteMembers.iterator(); for (AnnotationValue item : items) { Name suiteMemberName = getAnnotationValueClassName(item, types); if (suiteMemberName == null) { return false; } if (!suiteMemberName.contentEquals(suiteMembersIt.next())) { return false; } } return true; } return false; }
Example 18
Source File: AddWsOperationHelper.java From netbeans with Apache License 2.0 | 5 votes |
private String getEndpointInterface(TypeElement classEl, CompilationController controller) { TypeElement wsElement = controller.getElements(). getTypeElement("javax.jws.WebService"); //NOI18N if ( wsElement == null ){ isIncomplete = true; return null; } List<? extends AnnotationMirror> annotations = classEl.getAnnotationMirrors(); for (AnnotationMirror anMirror : annotations) { if (controller.getTypes().isSameType(wsElement.asType(), anMirror.getAnnotationType())) { Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = anMirror.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : expressions.entrySet()) { if (entry.getKey().getSimpleName() .contentEquals("endpointInterface")) // NOI18N { String value = (String) expressions.get(entry.getKey()) .getValue(); if (value != null) { TypeElement seiEl = controller.getElements() .getTypeElement(value); if (seiEl != null) { return seiEl.getQualifiedName().toString(); } } } } } } return null; }
Example 19
Source File: MethodVisitor.java From netbeans with Apache License 2.0 | 5 votes |
/** * Determines if the WSDL operation is the corresponding Java method */ private boolean isMethodFor(ExecutableElement method, String operationName){ if(method.getSimpleName().toString().equals(operationName)){ return true; } //if method name is not the same as the operation name, look at WebMethod annotation List<? extends AnnotationMirror> methodAnnotations = method.getAnnotationMirrors(); for (AnnotationMirror anMirror : methodAnnotations) { if (JaxWsUtils.hasFqn(anMirror, "javax.jws.WebMethod")) { // NOI18N Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = anMirror.getElementValues(); for(Entry<? extends ExecutableElement, ? extends AnnotationValue> entry: expressions.entrySet()) { if (entry.getKey().getSimpleName(). contentEquals("operationName")) //NOI18N { String name = (String)expressions.get(entry.getKey()). getValue(); if (operationName.equals(name)){ return true; } } } } } return false; }
Example 20
Source File: BindingsPanel.java From netbeans with Apache License 2.0 | 4 votes |
private void appendBindingParamters( AnnotationMirror mirror, StringBuilder builder ) { Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = mirror.getElementValues(); StringBuilder params = new StringBuilder(); for ( Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) { ExecutableElement key = entry.getKey(); AnnotationValue value = entry.getValue(); List<? extends AnnotationMirror> annotationMirrors = key.getAnnotationMirrors(); boolean nonBinding = false; for (AnnotationMirror annotationMirror : annotationMirrors) { DeclaredType annotationType = annotationMirror.getAnnotationType(); Element element = annotationType.asElement(); if ( ( element instanceof TypeElement ) && ((TypeElement)element).getQualifiedName(). contentEquals(NON_BINDING_MEMBER_ANNOTATION)) { nonBinding = true; break; } } if ( !nonBinding ){ params.append( key.getSimpleName().toString() ); params.append( "=" ); // NOI18N if ( value.getValue() instanceof String ){ params.append('"'); params.append( value.getValue().toString()); params.append('"'); } else { params.append( value.getValue().toString()); } params.append(", "); // NOI18N } } if ( params.length() >0 ){ builder.append( "(" ); // NOI18N builder.append( params.substring(0 , params.length() -2 )); builder.append( ")" ); // NOI18N } }