private static List<AnnotationSpec> getExternalAnnotations(VariableElement param) { final List<? extends AnnotationMirror> annotationMirrors = param.getAnnotationMirrors(); final List<AnnotationSpec> annotations = new ArrayList<>(); for (AnnotationMirror annotationMirror : annotationMirrors) { if (annotationMirror.getAnnotationType().toString().startsWith(COMPONENTS_PACKAGE)) { continue; } final AnnotationSpec.Builder annotationSpec = AnnotationSpec.builder( ClassName.bestGuess(annotationMirror.getAnnotationType().toString())); Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> elementValue : elementValues.entrySet()) { annotationSpec.addMember( elementValue.getKey().getSimpleName().toString(), elementValue.getValue().toString()); } annotations.add(annotationSpec.build()); } return annotations; }
/** * Retrieve the string value inside an @Contract annotation without statically depending on the * type. * * @param sym A method which has an @Contract annotation. * @return The string value spec inside the annotation. */ private static @Nullable String getContractFromAnnotation(Symbol.MethodSymbol sym) { for (AnnotationMirror annotation : sym.getAnnotationMirrors()) { Element element = annotation.getAnnotationType().asElement(); assert element.getKind().equals(ElementKind.ANNOTATION_TYPE); if (((TypeElement) element) .getQualifiedName() .contentEquals("org.jetbrains.annotations.Contract")) { for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> e : annotation.getElementValues().entrySet()) { if (e.getKey().getSimpleName().contentEquals("value")) { String value = e.getValue().toString(); if (value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); } return value; } } } } return null; } }
private String getValueOfAnnotation(AnnotationMirror annotationMirror) { String result = null; for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> annotationParamEntry : annotationMirror.getElementValues().entrySet()) { if (annotationParamEntry.getKey().getSimpleName().contentEquals("value")) { result = annotationParamEntry.getValue().toString().replaceAll("\"", ""); } } return result; }
@Override public Void visitUnknown(AnnotationValue value, AnnotationValue unused) { code.add("%s", value.toString()); return null; } }
@Override protected Void defaultAction(Object obj, AnnotationValue value) { code.add("%s", value.toString()); return null; }
private String toString(AnnotationValue value) { if (value.getValue() instanceof TypeMirror) { TypeMirror tm = (TypeMirror) value.getValue(); if (tm.getKind().equals(TypeKind.DECLARED)) { DeclaredType dt = (DeclaredType) tm; return getClassName((TypeElement) dt.asElement()); } } return value.toString(); }
@Override public String toString() { return internal.toString(); } }
private String getValueOfAnnotation(AnnotationMirror annotationMirror) { String result = null; for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> annotationParamEntry : annotationMirror.getElementValues().entrySet()) { if (annotationParamEntry.getKey().getSimpleName().contentEquals("value")) { result = annotationParamEntry.getValue().toString().replaceAll("\"", ""); } } return result; }
protected String getValueOfAnnotation(AnnotationMirror annotationMirror) { String result = null; for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> annotationParamEntry : annotationMirror.getElementValues().entrySet()) { if (annotationParamEntry.getKey().getSimpleName().contentEquals("value")) { result = annotationParamEntry.getValue().toString().replaceAll("\"", ""); } } return result; }
@Override protected Void defaultAction(Object obj, AnnotationValue value) { code.add("%s", value.toString()); return null; }
private static String findTargetId(Element e) { for (AnnotationMirror m : e.getAnnotationMirrors()) { if (m.getAnnotationType().toString().equals(Model.class.getName())) { for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entrySet : m.getElementValues().entrySet()) { ExecutableElement key = entrySet.getKey(); AnnotationValue value = entrySet.getValue(); if ("targetId()".equals(key.toString())) { return value.toString(); } } } } return null; }
@Override public Void visitUnknown(AnnotationValue value, AnnotationValue unused) { code.add("%s", value.toString()); return null; } }
public List<String> getAsStrings(String parameterName) { List<String> res = new ArrayList<String>(); AnnotationValue myValue = map.get(parameterName); if (myValue.getValue() instanceof List) { List<? extends AnnotationValue> values = (List<? extends AnnotationValue>) myValue.getValue(); for (AnnotationValue value : values) { if (value.getValue() instanceof String) { res.add((String) value.getValue()); } else { res.add(value.toString()); } } } else { res.add(myValue.getValue().toString()); } return res; }
private static String getAnnotationValue(Element element, String annotationType, String paramName) { for (AnnotationMirror annotation : element.getAnnotationMirrors()) { if (annotation.getAnnotationType().toString().equals(annotationType)) { for (ExecutableElement key : annotation.getElementValues().keySet()) { //System.out.println("key = " + key.getSimpleName()); if (key.getSimpleName().toString().equals(paramName)) { String value = annotation.getElementValues().get(key).toString(); value = stripQuotes(value); return value; } } } } return ""; }
private String toString(AnnotationValue value) { if (value.getValue() instanceof TypeMirror) { TypeMirror tm = (TypeMirror) value.getValue(); if (tm.getKind().equals(TypeKind.DECLARED)) { DeclaredType dt = (DeclaredType) tm; return getClassName((TypeElement) dt.asElement()); } } return value.toString(); }
private SimplifiedAST.Annotation createAnnotation(AnnotationMirror annotation) { val type = annotation.getAnnotationType().asElement().asType().toString(); val elementValues = annotation.getElementValues(); val values = new HashMap<String, Object>(); for (val e : elementValues.entrySet()) values.put( e.getKey().getSimpleName().toString(), e.getValue().toString() ); return new SimplifiedAST.Annotation() .setParameters(values).setType(type); }
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; }
public static List<AnnotationSpec> generateAnnotations(Element element) { List<AnnotationSpec> result = new ArrayList<>(); List<? extends AnnotationMirror> annotations = element.getAnnotationMirrors(); for (AnnotationMirror ann : annotations) { TypeElement annTypeElm = (TypeElement) ann.getAnnotationType().asElement(); ClassName annClassName = ClassName.get(annTypeElm); AnnotationSpec.Builder annBuilder = AnnotationSpec.builder(annClassName); Map<? extends ExecutableElement, ? extends AnnotationValue> annValues = ann.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annValues.entrySet()) { String name = entry.getKey().getSimpleName().toString(); AnnotationValue value = entry.getValue(); // unstable untested code: annBuilder.addMember(name, "$N", value.toString()); } result.add(annBuilder.build()); } return result; }
/** * This only applies to annotation methods. * <p> * Convenience method for getAnnotationDefaultValue().toString(). */ public String getAnnotationValueAsString() { AnnotationValue annValue = getExecutable().getDefaultValue(); return annValue.toString(); }
@Transition(from = "AnnotationTool", end = true) public String getStringValue(String name) { AnnotationValue av = getAnnotationValue(name); String value; if (av == null) { value = null; } else { value = GetThe.string(av.toString()).unquoted(); } return value; }