当前位置: 首页>>代码示例>>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;未经允许,请勿转载。