javax.lang.model.element.AnnotationValue Java Examples
The following examples show how to use
javax.lang.model.element.AnnotationValue.
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: FieldInfo.java From CallBuilder with Apache License 2.0 | 6 votes |
static FieldInfo from(Elements elementUtils, VariableElement parameter) { FieldStyle style = null; // Look for style field on the @BuilderField annotation. If the annotation is // present, the value of that field overrides the default set above. for (AnnotationMirror ann : parameter.getAnnotationMirrors()) { if (ann.getAnnotationType().toString() .equals(BuilderField.class.getCanonicalName())) { for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> annEl : ann.getElementValues().entrySet()) { if ("style".equals(annEl.getKey().getSimpleName().toString())) { style = FieldStyle.fromStyleClass((DeclaredType) annEl.getValue().getValue()); } } } } return new FieldInfo(parameter, style); }
Example #2
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 #3
Source File: JoinTableImpl.java From netbeans with Apache License 2.0 | 6 votes |
public JoinTableImpl(final AnnotationModelHelper helper, AnnotationMirror annotation) { AnnotationParser parser = AnnotationParser.create(helper); ArrayValueHandler joinColumnHandler = new ArrayValueHandler() { public Object handleArray(List<AnnotationValue> arrayMembers) { List<JoinColumn> result = new ArrayList<JoinColumn>(); for (AnnotationValue arrayMember : arrayMembers) { AnnotationMirror joinColumnAnnotation = (AnnotationMirror)arrayMember.getValue(); result.add(new JoinColumnImpl(helper, joinColumnAnnotation)); } return result; } }; TypeMirror joinColumnType = helper.resolveType("javax.persistence.JoinColumn"); // NOI18N parser.expectAnnotationArray("joinColumn", joinColumnType, joinColumnHandler, parser.defaultValue(Collections.emptyList())); // NOI18N parser.expectAnnotationArray("inverseJoinColumn", joinColumnType, joinColumnHandler, parser.defaultValue(Collections.emptyList())); // NOI18N parseResult = parser.parse(annotation); }
Example #4
Source File: InconsistentPortType.java From netbeans with Apache License 2.0 | 6 votes |
protected ErrorDescription[] apply(TypeElement subject, ProblemContext ctx) { AnnotationMirror annEntity = Utilities.findAnnotation(subject, ANNOTATION_WEBSERVICE); if (subject.getKind() == ElementKind.CLASS && Utilities.getAnnotationAttrValue(annEntity, ANNOTATION_ATTRIBUTE_SEI) == null) { Service service = ctx.getLookup().lookup(Service.class); WSDLModel model = ctx.getLookup().lookup(WSDLModel.class); if (service != null && model != null && model.getState() == State.VALID) { PortType portType = model.findComponentByName(subject.getSimpleName().toString(), PortType.class); if (portType == null) { AnnotationValue nameVal = Utilities.getAnnotationAttrValue(annEntity, ANNOTATION_ATTRIBUTE_NAME); if(nameVal!=null) portType = model.findComponentByName(nameVal.toString(), PortType.class); } if (portType == null) { String label = NbBundle.getMessage(InconsistentPortType.class, "MSG_InconsistentPortType"); AnnotationTree annotationTree = (AnnotationTree) ctx.getCompilationInfo(). getTrees().getTree(subject, annEntity); Tree problemTree = Utilities.getAnnotationArgumentTree(annotationTree, ANNOTATION_ATTRIBUTE_WSDLLOCATION); ctx.setElementToAnnotate(problemTree); ErrorDescription problem = createProblem(subject, ctx, label, (Fix) null); ctx.setElementToAnnotate(null); return new ErrorDescription[]{problem}; } } } return null; }
Example #5
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 #6
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 #7
Source File: CodeGenerator.java From netbeans with Apache License 2.0 | 6 votes |
private AnnotationTree computeAnnotationTree(AnnotationMirror am) { List<ExpressionTree> params = new LinkedList<ExpressionTree>(); for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) { ExpressionTree val = createTreeForAnnotationValue(make, entry.getValue()); if (val == null) { LOG.log(Level.WARNING, "Cannot create annotation for: {0}", entry.getValue()); continue; } ExpressionTree vt = make.Assignment(make.Identifier(entry.getKey().getSimpleName()), val); params.add(vt); } return make.Annotation(make.Type(am.getAnnotationType()), params); }
Example #8
Source File: MoreApt.java From j2cl with Apache License 2.0 | 6 votes |
/** * Returns a list of fully qualified name of a class found in an annotation. * * <p>Reading values for type Class in annotation processors causes issues, see {@link * Element#getAnnotation(Class)}. To work around these issues we treat the annotation value as a * String. * * <p>Note: If this method is invoked with an annotation and method that does not contain a * Collection / Array of class files it will throw an {@link IllegalArgumentException}. */ public static ImmutableList<String> getClassNamesFromAnnotation( Element element, final Class<? extends Annotation> annotationClass, String field) { Optional<AnnotationValue> annotationValue = getAnnotationValue(element, annotationClass, field); if (!annotationValue.isPresent()) { return ImmutableList.<String>of(); } Object value = annotationValue.get().getValue(); checkArgument(value instanceof List, "The annotation value does not represent a list"); @SuppressWarnings("unchecked") List<AnnotationValue> values = (List<AnnotationValue>) value; return values .stream() .map(input -> extractClassName(input.toString())) .collect(toImmutableList()); }
Example #9
Source File: NoPrivateTypesExported.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private void verifyAnnotations(Iterable<? extends AnnotationMirror> annotations, Set<String> acceptable) { for (AnnotationMirror mirror : annotations) { Element annotationElement = mirror.getAnnotationType().asElement(); if (annotationElement.getAnnotation(Documented.class) == null) { note("Ignoring undocumented annotation: " + mirror.getAnnotationType()); } verifyTypeAcceptable(mirror.getAnnotationType(), acceptable); for (AnnotationValue value : mirror.getElementValues().values()) { verifyAnnotationValue(value, acceptable); } } }
Example #10
Source File: FindTasksVisitor.java From kripton with Apache License 2.0 | 6 votes |
@Override public Void visitAnnotation(AnnotationMirror a, String p) { if (AnnotationAttributeType.UPDATE_TASKS.getValue().equals(p)) { inTasks = true; } for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : a.getElementValues().entrySet()) { String key = entry.getKey().getSimpleName().toString(); entry.getValue().accept(this, key); } if (AnnotationAttributeType.UPDATE_TASKS.getValue().equals(p)) { inTasks = false; } return null; }
Example #11
Source File: AnnotationOutput.java From RetroFacebook with Apache License 2.0 | 6 votes |
@Override public Void visitAnnotation(AnnotationMirror a, StringBuilder sb) { sb.append('@').append(typeSimplifier.simplify(a.getAnnotationType())); Map<ExecutableElement, AnnotationValue> map = ImmutableMap.copyOf(a.getElementValues()); if (!map.isEmpty()) { sb.append('('); String sep = ""; for (Map.Entry<ExecutableElement, AnnotationValue> entry : map.entrySet()) { sb.append(sep).append(entry.getKey().getSimpleName()).append(" = "); sep = ", "; this.visit(entry.getValue(), sb); } sb.append(')'); } return null; }
Example #12
Source File: UseDatabaseGeneratorTest.java From netbeans with Apache License 2.0 | 6 votes |
private static void checkDatasourceField(TypeElement typeElement, String name) { List<VariableElement> elements = ElementFilter.fieldsIn(typeElement.getEnclosedElements()); VariableElement variableElement = elements.get(0); assertTrue(variableElement.getSimpleName().contentEquals(name)); // field name DeclaredType declaredType = (DeclaredType) variableElement.asType(); TypeElement returnTypeElement = (TypeElement) declaredType.asElement(); assertTrue(returnTypeElement.getQualifiedName().contentEquals("javax.sql.DataSource")); // field type AnnotationMirror annotationMirror = variableElement.getAnnotationMirrors().get(0); DeclaredType annotationDeclaredType = annotationMirror.getAnnotationType(); TypeElement annotationTypeElement = (TypeElement) annotationDeclaredType.asElement(); assertTrue(annotationTypeElement.getQualifiedName().contentEquals("javax.annotation.Resource")); // annotation type Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry = annotationMirror.getElementValues().entrySet().iterator().next(); String attributeName = entry.getKey().getSimpleName().toString(); String attributeValue = (String) entry.getValue().getValue(); assertEquals("name", attributeName); // attributes assertEquals(name, attributeValue); }
Example #13
Source File: EntityMappingsUtilities.java From netbeans with Apache License 2.0 | 6 votes |
public static List<JoinColumn> getJoinColumns(final AnnotationModelHelper helper, Map<String, ? extends AnnotationMirror> annByType) { final List<JoinColumn> result = new ArrayList<JoinColumn>(); AnnotationMirror joinColumnAnn = annByType.get("javax.persistence.JoinColumn"); // NOI18N if (joinColumnAnn != null) { result.add(new JoinColumnImpl(helper, joinColumnAnn)); } else { AnnotationMirror joinColumnsAnnotation = annByType.get("javax.persistence.JoinColumns"); // NOI18N if (joinColumnsAnnotation != null) { AnnotationParser jcParser = AnnotationParser.create(helper); jcParser.expectAnnotationArray("value", helper.resolveType("javax.persistence.JoinColumn"), new ArrayValueHandler() { // NOI18N public Object handleArray(List<AnnotationValue> arrayMembers) { for (AnnotationValue arrayMember : arrayMembers) { AnnotationMirror joinColumnAnnotation = (AnnotationMirror)arrayMember.getValue(); result.add(new JoinColumnImpl(helper, joinColumnAnnotation)); } return null; } }, null); jcParser.parse(joinColumnsAnnotation); } } return result; }
Example #14
Source File: AnnotationUtils.java From j2cl with Apache License 2.0 | 5 votes |
static List<?> getAnnotationParameterArray(AnnotationMirror annotationMirror, String paramName) { if (annotationMirror == null) { return null; } for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> member : annotationMirror.getElementValues().entrySet()) { if (member.getKey().getSimpleName().contentEquals(paramName)) { if (member.getValue().getValue() instanceof List) { return (List<?>) member.getValue().getValue(); } } } return null; }
Example #15
Source File: AnnotationOutput.java From RetroFacebook with Apache License 2.0 | 5 votes |
/** * Returns a string representation of the given annotation value, suitable for inclusion in a Java * source file as the initializer of a variable of the appropriate type. */ String sourceFormForInitializer( AnnotationValue annotationValue, ProcessingEnvironment processingEnv, String memberName, Element context) { SourceFormVisitor visitor = new InitializerSourceFormVisitor(processingEnv, memberName, context); StringBuilder sb = new StringBuilder(); visitor.visit(annotationValue, sb); return sb.toString(); }
Example #16
Source File: ElementUtils.java From spring-init with Apache License 2.0 | 5 votes |
@Override public Boolean visitArray(List<? extends AnnotationValue> vals, String name) { for (AnnotationValue value : vals) { // TODO: really? if (this.visit(value, name) || value.toString().equals("<error>")) { return true; } } return false; }
Example #17
Source File: FindIndexesVisitor.java From kripton with Apache License 2.0 | 5 votes |
@Override public Void visitArray(List<? extends AnnotationValue> vals, String p) { for (AnnotationValue val : vals) { val.accept(this, p); } return null; }
Example #18
Source File: ProcessorUtils.java From pandroid with Apache License 2.0 | 5 votes |
public static Object getAnnotationValue(AnnotationMirror annotationMirror, String key) { for(Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet() ) { if(entry.getKey().getSimpleName().toString().equals(key)) { return entry.getValue().getValue(); } } return null; }
Example #19
Source File: ConfiguredObjectFactoryGenerator.java From qpid-broker-j with Apache License 2.0 | 5 votes |
private String getParamName(final AnnotationMirror paramAnnotation) { String paramName = null; for(ExecutableElement paramElement : paramAnnotation.getElementValues().keySet()) { if(paramElement.getSimpleName().toString().equals("name")) { AnnotationValue value = paramAnnotation.getElementValues().get(paramElement); paramName = value.getValue().toString(); break; } } return paramName; }
Example #20
Source File: FindXmlNamespaceVisitor.java From kripton with Apache License 2.0 | 5 votes |
@Override public Void visitAnnotation(AnnotationMirror a, String p) { for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : a.getElementValues().entrySet()) { String key = entry.getKey().getSimpleName().toString(); entry.getValue().accept(this, key); } return null; }
Example #21
Source File: ComponentExtractor.java From Auto-Dagger2 with MIT License | 5 votes |
private boolean validateAnnotationValue(AnnotationValue value, String member) { if (!(value.getValue() instanceof TypeMirror)) { errors.addInvalid("%s cannot reference generated class. Use the class that applies the @AutoComponent annotation", member); return false; } return true; }
Example #22
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 #23
Source File: ElementUtils.java From spring-init with Apache License 2.0 | 5 votes |
public List<AnnotationMirror> getAnnotationsFromAnnotation( AnnotationMirror annotationMirror, String fieldname) { List<AnnotationMirror> 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(annotationCollector, collected); } } } return collected; }
Example #24
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 #25
Source File: JavacElements.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Returns the best approximation for the tree node and compilation unit * corresponding to the given element, annotation and value. * If the element is null, null is returned. * If the annotation is null or cannot be found, the tree node and * compilation unit for the element is returned. * If the annotation value is null or cannot be found, the tree node and * compilation unit for the annotation is returned. */ public Pair<JCTree, JCCompilationUnit> getTreeAndTopLevel( Element e, AnnotationMirror a, AnnotationValue v) { if (e == null) return null; Pair<JCTree, JCCompilationUnit> elemTreeTop = getTreeAndTopLevel(e); if (elemTreeTop == null) return null; if (a == null) return elemTreeTop; JCTree annoTree = matchAnnoToTree(a, e, elemTreeTop.fst); if (annoTree == null) return elemTreeTop; if (v == null) return new Pair<>(annoTree, elemTreeTop.snd); JCTree valueTree = matchAttributeToTree( cast(Attribute.class, v), cast(Attribute.class, a), annoTree); if (valueTree == null) return new Pair<>(annoTree, elemTreeTop.snd); return new Pair<>(valueTree, elemTreeTop.snd); }
Example #26
Source File: MemberCheckerFilter.java From netbeans with Apache License 2.0 | 5 votes |
void init( Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues, Set<ExecutableElement> members, WebBeansModelImplementation impl ) { myImpl = impl; myValues = elementValues; myMembers = members; }
Example #27
Source File: HktProcessor.java From hkt with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Function<HktConf, HktConf> hktConfDefaultMod(Element elt) { Function<HktConf, HktConf> conf = elt.getAnnotationMirrors() .stream() .filter(am -> am.getAnnotationType().asElement().equals(this.HktConfigElt)) .map(am -> { Map<? extends ExecutableElement, ? extends AnnotationValue> explicitValues = am.getElementValues(); Optional<Function<HktConf, HktConf>> witnessTypeName = unNull(explicitValues.get(witnessTypeNameConfMethod)).map( value -> _HktConf.setWitnessTypeName((String) Visitors.getAnnotationValue.visit(value))); Optional<Function<HktConf, HktConf>> generateIn = unNull(explicitValues.get(generateInConfMethod)).map( value -> _HktConf.setClassName((String) Visitors.getAnnotationValue.visit(value))); Optional<Function<HktConf, HktConf>> withVisibility = unNull(explicitValues.get(withVisibilityConfMethod)).map( value -> _HktConf.setVisibility( HktConfig.Visibility.valueOf((String) Visitors.getAnnotationValue.visit(value)))); Optional<Function<HktConf, HktConf>> coerceMethodName = unNull( explicitValues.get(coerceMethodNameConfMethod)).map( value -> _HktConf.setCoerceMethodTemplate((String) Visitors.getAnnotationValue.visit(value))); Optional<Function<HktConf, HktConf>> typeEqMethodName = unNull( explicitValues.get(typeEqMethodNameConfMethod)).map( value -> _HktConf.setTypeEqMethodTemplate((String) Visitors.getAnnotationValue.visit(value))); return Stream.of(witnessTypeName, generateIn, withVisibility, coerceMethodName, typeEqMethodName) .flatMap(Opt::asStream) .reduce(Function::andThen) .orElse(Function.identity()); }) .findAny() .orElse(Function.identity()); return Opt.cata(parentElt(elt), parentElt -> conf.compose(hktConfDefaultMod(parentElt)), () -> conf); }
Example #28
Source File: PoliciesVisualPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void handleList( Set<String> result, Entry<? extends ExecutableElement, ? extends AnnotationValue> entry ) { ExecutableElement method = entry.getKey(); AnnotationValue value = entry.getValue(); if ( VALUE.contentEquals( method.getSimpleName())){ Object policies = value.getValue(); if ( policies instanceof List<?> ){ List<?> policiesList = (List<?>) policies; for (Object policy : policiesList) { if ( policy instanceof AnnotationMirror ){ AnnotationMirror annotation = (AnnotationMirror) policy; Element annotationElement = annotation.getAnnotationType().asElement(); if ( annotationElement instanceof TypeElement){ String fqn = ((TypeElement)annotationElement). getQualifiedName().toString(); if ( fqn.equals( OWSM_SECURITY_POLICY )){ addId( result , (AnnotationMirror)policy); } } } } } } }
Example #29
Source File: ErrorLoggingProcessor.java From squidb with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void logErrors(Element element) { AnnotationValue errorsArrayValue = utils.getAnnotationValue(element, ModelGenErrors.class, "value"); List<? extends AnnotationValue> errorsList = (List<? extends AnnotationValue>) errorsArrayValue.getValue(); for (AnnotationValue error : errorsList) { logSingleError(error); } }
Example #30
Source File: MemberCheckerFilter.java From netbeans with Apache License 2.0 | 5 votes |
private void checkMember( ExecutableElement exec, AnnotationValue value, Set<T> elementsWithBindings ) { Element annotationElement = exec.getEnclosingElement(); if ( !( annotationElement instanceof TypeElement ) ){ return; } String annotationName = ((TypeElement)annotationElement). getQualifiedName().toString(); // annotation member should be checked for presence at Binding type for (Iterator<? extends Element> iterator = elementsWithBindings.iterator(); iterator.hasNext(); ) { Element element = iterator.next(); if ( !checkMember(exec, value, element, iterator , annotationName)) { // check specializes.... if (element instanceof TypeElement) { TypeElement specializedSuper = AnnotationObjectProvider .checkSuper((TypeElement) element, annotationName, getImplementation().getHelper()); if (specializedSuper != null) { checkMember(exec, value, specializedSuper, iterator, annotationName); } } else if ( element instanceof ExecutableElement){ Element specialized = getSpecialized((ExecutableElement)element, getImplementation(), annotationName ); if ( specialized != null ){ checkMember(exec, value, specialized, iterator, annotationName); } } } } }