當前位置: 首頁>>代碼示例>>Java>>正文


Java VariableElement.getAnnotation方法代碼示例

本文整理匯總了Java中javax.lang.model.element.VariableElement.getAnnotation方法的典型用法代碼示例。如果您正苦於以下問題:Java VariableElement.getAnnotation方法的具體用法?Java VariableElement.getAnnotation怎麽用?Java VariableElement.getAnnotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.lang.model.element.VariableElement的用法示例。


在下文中一共展示了VariableElement.getAnnotation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Property

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
Property(String fieldName, TypeName typeName, VariableElement element, boolean isMapped) {
    this.fieldName = fieldName;
    this.element = element;
    this.typeName = typeName;
    this.annotations = getAnnotations(element);
    this.isMapped = isMapped;

    // get the parcel adapter if any
    ParcelAdapter parcelAdapter = element.getAnnotation(ParcelAdapter.class);
    if (parcelAdapter != null) {
        try {
            parcelAdapter.value();
        } catch (MirroredTypeException e) {
            this.typeAdapter = e.getTypeMirror();
        }
    }

    // get the element version, default 0
    ParcelVersion parcelVersion = element.getAnnotation(ParcelVersion.class);
    this.version = parcelVersion == null ? 0 : parcelVersion.from();
}
 
開發者ID:foodora,項目名稱:android-auto-mapper,代碼行數:22,代碼來源:AutoMappperProcessor.java

示例2: generateToContentValuesMethod

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private MethodSpec generateToContentValuesMethod(TypeElement typeElement, List<VariableElement> listOfVariables, String methodName, Modifier... modifier) {
    final String parameterName = typeElement.getSimpleName().toString().toLowerCase();
    final ClassName contentValuesClassName = ClassName.get("android.content", "ContentValues");

    final MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(methodName)
            .addModifiers(modifier)
            .returns(contentValuesClassName)
            .addParameter(ClassName.get(typeElement), parameterName)
            .addStatement("$T contentValues = new $T()", contentValuesClassName, contentValuesClassName);

    for (VariableElement variableElement : listOfVariables) {
        Field field = variableElement.getAnnotation(Field.class);
        methodBuilder.addStatement("contentValues.put($S, $L)", field.columnName(), parameterName + "." + variableElement.getSimpleName());
    }

    methodBuilder.addStatement("return contentValues");
    methodBuilder.addJavadoc("Converts the provided " + parameterName + " to ContentValues");
    methodBuilder.addJavadoc("\[email protected] " + parameterName + " to convert values from");
    methodBuilder.addJavadoc("\[email protected] {@code $T} with values converted from {@code $T}", contentValuesClassName, typeElement);

    return methodBuilder.build();
}
 
開發者ID:Neristance,項目名稱:slimorm,代碼行數:23,代碼來源:SlimOrmProcessor.java

示例3: addNonPrimitiveType

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private void addNonPrimitiveType(VariableElement element, MethodSpec.Builder methodBuilder) {

        Field field = element.getAnnotation(Field.class);
        final TypeName typeOfCurrentElement = ClassName.get(element.asType());

        if (typeOfCurrentElement.equals(BYTE_ARRAY_TYPE)) {
            methodBuilder.addStatement("row.$L = cursor.getBlob(cursor.getColumnIndex($S))", element.getSimpleName(), field.columnName());
        } else {
            methodBuilder.addCode("if (!cursor.isNull(cursor.getColumnIndex($S))) {\n", field.columnName());

            if (typeOfCurrentElement.equals(ClassName.get(String.class))) {
                methodBuilder.addStatement("    row.$L = $T.valueOf(cursor.getString(cursor.getColumnIndex($S)))", element.getSimpleName(), typeOfCurrentElement, field.columnName());
            } else if (typeOfCurrentElement.unbox().equals(TypeName.BOOLEAN)) {
                methodBuilder.addStatement("    row.$L = $T.valueOf(cursor." + mapTypeToCursorGetMethod(typeOfCurrentElement.unbox()) + "(cursor.getColumnIndex($S)) == 1)", element.getSimpleName(), typeOfCurrentElement, field.columnName());
            } else {
                methodBuilder.addStatement("    row.$L = $T.valueOf(cursor." + mapTypeToCursorGetMethod(typeOfCurrentElement.unbox()) + "(cursor.getColumnIndex($S)))", element.getSimpleName(), typeOfCurrentElement, field.columnName());
            }

            methodBuilder.addCode("}\n");
        }

    }
 
開發者ID:Neristance,項目名稱:slimorm,代碼行數:23,代碼來源:SlimOrmProcessor.java

示例4: buildAnnotatedClass

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private AnnotatedClass buildAnnotatedClass(TypeElement annotatedClass) {

        List<VariableElement> fields = new ArrayList<>();

        for (Element element : annotatedClass.getEnclosedElements()) {

            if (!(element instanceof VariableElement)) {
                continue;
            }
            VariableElement variableElement = (VariableElement) element;

            if (variableElement.getAnnotation(KVOField.class) != null) {

                fields.add(variableElement);
            }
        }

        return new AnnotatedClass(annotatedClass.getSimpleName() + "KVO", fields, annotatedClass
                , processingEnv.getElementUtils().getPackageOf(annotatedClass).getQualifiedName().toString());
    }
 
開發者ID:ahmed-basyouni,項目名稱:AndroidKVO,代碼行數:21,代碼來源:KVOProcessor.java

示例5: KickbackElementClass

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
public KickbackElementClass(VariableElement variableElement, Elements elementUtils) throws VerifyException {
    KickbackElement kickbackElement = variableElement.getAnnotation(KickbackElement.class);
    Weak weak = variableElement.getAnnotation(Weak.class);
    Soft soft = variableElement.getAnnotation(Soft.class);
    PackageElement packageElement = elementUtils.getPackageOf(variableElement);
    this.variableElement = variableElement;
    this.packageName = packageElement.isUnnamed() ? null : packageElement.getQualifiedName().toString();
    this.typeName = TypeName.get(variableElement.asType());
    this.clazzName = variableElement.getSimpleName().toString();
    this.value = variableElement.getConstantValue();
    if(weak != null) this.isWeak = true;
    else this.isWeak = false;
    if(soft != null) this.isSoft = true;
    else this.isSoft = false;

    if(kickbackElement != null) {
        this.elementName =  StringUtils.toUpperCamel(Strings.isNullOrEmpty(kickbackElement.name()) ? this.clazzName : kickbackElement.name());
    } else {
        this.elementName = StringUtils.toUpperCamel(this.clazzName);
    }

    checkPrimitiveType();
    checkModifierValidate();
    checkAnnotationValidate();
}
 
開發者ID:skydoves,項目名稱:Kickback,代碼行數:26,代碼來源:KickbackElementClass.java

示例6: constructorSignature

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private TypeMirror[] constructorSignature(ExecutableElement method) {
    TypeMirror[] parameters = new TypeMirror[method.getParameters().size()];
    for (int i = 0; i < method.getParameters().size(); i++) {
        VariableElement parameter = method.getParameters().get(i);
        if (parameter.getAnnotation(ConstantNodeParameter.class) == null) {
            parameters[i] = valueNodeType();
        } else {
            TypeMirror type = parameter.asType();
            if (isTypeCompatible(type, classType())) {
                type = resolvedJavaTypeType();
            }
            parameters[i] = type;
        }
    }
    return parameters;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:NodeIntrinsicVerifier.java

示例7: createExecute

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
@Override
protected InjectedDependencies createExecute(ProcessingEnvironment env, PrintWriter out) {
    InjectedDependencies deps = new InjectedDependencies();

    List<? extends VariableElement> params = getParameters();

    int idx = 0;
    for (; idx < params.size(); idx++) {
        VariableElement param = params.get(idx);
        if (param.getAnnotation(InjectedNodeParameter.class) == null) {
            break;
        }

        out.printf("            %s arg%d = %s;\n", param.asType(), idx, deps.use(env, (DeclaredType) param.asType()));
    }

    for (int i = 0; i < signature.length; i++, idx++) {
        if (intrinsicMethod.getParameters().get(i).getAnnotation(ConstantNodeParameter.class) != null) {
            constantArgument(env, out, deps, idx, signature[i], i);
        } else {
            if (signature[i].equals(valueNodeType(env))) {
                out.printf("            ValueNode arg%d = args[%d];\n", idx, i);
            } else {
                out.printf("            %s arg%d = (%s) args[%d];\n", signature[i], idx, signature[i], i);
            }
        }
    }

    factoryCall(env, out, deps, idx);

    return deps;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:GeneratedNodeIntrinsicPlugin.java

示例8: getParamName

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private String getParamName(VariableElement methodParam) {
    Param paramAnnotation = methodParam.getAnnotation(Param.class);
    if (paramAnnotation != null) {
        return paramAnnotation.value();
    }
    throw new IllegalArgumentException("Parameter " + methodParam.getSimpleName() + " doesn't have " + Param.class.getSimpleName() + " annotation with name.");
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:8,代碼來源:ClassCrawler.java

示例9: create

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
public static LJSONVariableElement create(VariableElement element) {
    LJSONVariableElement ljsonElement = new LJSONVariableElement();
    ljsonElement.variableElement = element;
    ljsonElement.ljsonVariable = element.getAnnotation(LIMITJSONVariable.class);

    return ljsonElement;
}
 
開發者ID:freelifer,項目名稱:limitjson,代碼行數:8,代碼來源:LJSONVariableElement.java

示例10: ElementDescription

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
public ElementDescription(VariableElement field) {
    this.field = field;
    key = field.getSimpleName().toString();
    Key keyAno = field.getAnnotation(Key.class);
    if(keyAno != null) {
        String annoValue = keyAno.value();
        if(annoValue != null && !"".equals(annoValue)) {
            key = annoValue;
        }
    }
    code = field.getAnnotation(Code.class);
    fieldType = ClassName.get(field.asType());
    fieldName = field.getSimpleName().toString();
}
 
開發者ID:foreveruseful,項目名稱:smartkey,代碼行數:15,代碼來源:ElementDescription.java

示例11: filterIgnore

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
public static List<VariableElement> filterIgnore(List<VariableElement> elements) {
    List<VariableElement> filtered = new ArrayList<>();
    for (VariableElement variableElement : elements) {
        if (variableElement.getAnnotation(Ignore.class) == null && !Constants.PARCEL_CREATOR.equals(
            ProcessUtils.getObjectName(variableElement)) || ProcessUtils.isNotVariable(variableElement)) {
            filtered.add(variableElement);
        }
    }
    return filterStaticFinal(filtered);
}
 
開發者ID:florent37,項目名稱:RxAndroidOrm,代碼行數:11,代碼來源:ProcessUtils.java

示例12: PreferenceKeyField

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
public PreferenceKeyField(@NonNull VariableElement variableElement, @NonNull Elements elementUtils) throws IllegalAccessException {
    KeyName annotation_keyName = variableElement.getAnnotation(KeyName.class);
    this.variableElement = variableElement;
    PackageElement packageElement = elementUtils.getPackageOf(variableElement);
    this.packageName = packageElement.isUnnamed() ? null : packageElement.getQualifiedName().toString();
    this.typeName = TypeName.get(variableElement.asType());
    this.clazzName = variableElement.getSimpleName().toString();
    this.value = variableElement.getConstantValue();
    setTypeStringName();

    if(annotation_keyName != null)
        this.keyName = Strings.isNullOrEmpty(annotation_keyName.name()) ? StringUtils.toUpperCamel(this.clazzName) : annotation_keyName.name();
    else
        this.keyName = StringUtils.toUpperCamel(this.clazzName);

    if(this.isObjectField) {
        variableElement.getAnnotationMirrors().stream()
                .filter(annotationMirror -> TypeName.get(annotationMirror.getAnnotationType()).equals(TypeName.get(TypeConverter.class)))
                .forEach(annotationMirror -> {
                    annotationMirror.getElementValues().forEach((type, value) -> {
                        String[] split = value.getValue().toString().split("\\.");
                        StringBuilder builder = new StringBuilder();
                        for (int i=0; i<split.length-1; i++)
                            builder.append(split[i] + ".");
                        this.converterPackage = builder.toString().substring(0, builder.toString().length()-1);
                        this.converter = split[split.length-1];
                    });
        });
    }

    if(variableElement.getModifiers().contains(Modifier.PRIVATE)) {
        throw new IllegalAccessException(String.format("Field \'%s\' should not be private.", variableElement.getSimpleName()));
    } else if(!this.isObjectField && !variableElement.getModifiers().contains(Modifier.FINAL)) {
        throw new IllegalAccessException(String.format("Field \'%s\' should be final.", variableElement.getSimpleName()));
    }
}
 
開發者ID:skydoves,項目名稱:PreferenceRoom,代碼行數:37,代碼來源:PreferenceKeyField.java

示例13: getOutParameter

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
protected VariableElement getOutParameter(ExecutableElement method) {
    WebParam webParam;
    for (VariableElement param : method.getParameters()) {
        webParam = param.getAnnotation(WebParam.class);
        if (webParam != null && webParam.mode() != WebParam.Mode.IN) {
            return param;
        }
    }
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:WebServiceVisitor.java

示例14: getModeParameterCount

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
protected int getModeParameterCount(ExecutableElement method, WebParam.Mode mode) {
    WebParam webParam;
    int cnt = 0;
    for (VariableElement param : method.getParameters()) {
        webParam = param.getAnnotation(WebParam.class);
        if (webParam != null) {
            if (webParam.header())
                continue;
            if (isEquivalentModes(mode, webParam.mode()))
                cnt++;
        } else {
            if (isEquivalentModes(mode, WebParam.Mode.IN)) {
                cnt++;
            }
        }
    }
    return cnt;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:WebServiceVisitor.java

示例15: isLegalParameter

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
protected boolean isLegalParameter(VariableElement param,
                                   ExecutableElement method,
                                   TypeElement typeElement,
                                   int paramIndex) {
    if (!isLegalType(param.asType())) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_PARAMETER_TYPES_CANNOT_IMPLEMENT_REMOTE(typeElement.getQualifiedName(),
                method.getSimpleName(),
                param.getSimpleName(),
                param.asType().toString()), param);
        return false;
    }
    TypeMirror holderType;
    holderType = builder.getHolderValueType(param.asType());
    WebParam webParam = param.getAnnotation(WebParam.class);
    WebParam.Mode mode = null;
    if (webParam != null)
        mode = webParam.mode();

    if (holderType != null) {
        if (mode != null && mode == WebParam.Mode.IN)
            builder.processError(WebserviceapMessages.WEBSERVICEAP_HOLDER_PARAMETERS_MUST_NOT_BE_IN_ONLY(typeElement.getQualifiedName(), method.toString(), paramIndex), param);
    } else if (mode != null && mode != WebParam.Mode.IN) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_NON_IN_PARAMETERS_MUST_BE_HOLDER(typeElement.getQualifiedName(), method.toString(), paramIndex), param);
    }

    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:WebServiceVisitor.java


注:本文中的javax.lang.model.element.VariableElement.getAnnotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。