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


Java VariableElement.asType方法代碼示例

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


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

示例1: getHolderValueType

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
public static TypeMirror getHolderValueType(TypeMirror type, TypeElement defHolder, ProcessingEnvironment env) {
    TypeElement typeElement = getDeclaration(type);
    if (typeElement == null)
        return null;

    if (isSubElement(typeElement, defHolder)) {
        if (type.getKind().equals(TypeKind.DECLARED)) {
            Collection<? extends TypeMirror> argTypes = ((DeclaredType) type).getTypeArguments();
            if (argTypes.size() == 1) {
                return argTypes.iterator().next();
            } else if (argTypes.isEmpty()) {
                VariableElement member = getValueMember(typeElement);
                if (member != null) {
                    return member.asType();
                }
            }
        }
    }
    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:TypeModeler.java

示例2: 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

示例3: getParamTypeMirror

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private TypeMirror getParamTypeMirror(VariableElement param, Messager messager) {
    TypeMirror typeMirror = param.asType();
    // Check for generic type
    if (typeMirror instanceof TypeVariable) {
        TypeMirror upperBound = ((TypeVariable) typeMirror).getUpperBound();
        if (upperBound instanceof DeclaredType) {
            if (messager != null) {
                messager.printMessage(Diagnostic.Kind.NOTE, "Using upper bound type " + upperBound +
                        " for generic parameter", param);
            }
            typeMirror = upperBound;
        }
    }
    return typeMirror;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:EventBusAnnotationProcessor.java

示例4: validateExtendsRequestOptions

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private static void validateExtendsRequestOptions(ExecutableElement executableElement) {
  validateStaticVoid(executableElement, GlideOption.class);
  if (executableElement.getParameters().isEmpty()) {
    throw new IllegalArgumentException("@GlideOption methods must take a "
        + "RequestOptions object as their first parameter, but given none");
  }
  VariableElement first = executableElement.getParameters().get(0);
  TypeMirror expected = first.asType();
  if (!expected.toString().equals(
      "com.bumptech.glide.request.RequestOptions")) {
    throw new IllegalArgumentException("@GlideOption methods must take a"
        + " RequestOptions object as their first parameter, but given: " + expected);
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:GlideExtensionValidator.java

示例5: validateGlideOptionParameters

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private static void validateGlideOptionParameters(ExecutableElement executableElement) {
  if (executableElement.getParameters().isEmpty()) {
    throw new IllegalArgumentException("@GlideOption methods must take a "
        + "RequestOptions object as their first parameter, but given none");
  }
  VariableElement first = executableElement.getParameters().get(0);
  TypeMirror expected = first.asType();
  if (!isRequestOptions(expected)) {
    throw new IllegalArgumentException("@GlideOption methods must take a"
        + " RequestOptions object as their first parameter, but given: " + expected);
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:GlideExtensionValidator.java

示例6: validateGlideTypeParameters

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private static void validateGlideTypeParameters(ExecutableElement executableElement) {
  if (executableElement.getParameters().size() != 1) {
    throw new IllegalArgumentException("@GlideType methods must take a"
        + " RequestBuilder object as their first and only parameter, but given multiple for: "
    + executableElement.getEnclosingElement() + "#" + executableElement);
  }

  VariableElement first = executableElement.getParameters().get(0);
  TypeMirror argumentType = first.asType();
  if (!argumentType.toString().startsWith("com.bumptech.glide.RequestBuilder")) {
    throw new IllegalArgumentException("@GlideType methods must take a"
        + " RequestBuilder object as their first and only parameter, but given: " + argumentType);
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:GlideExtensionValidator.java

示例7: checkRealmListType

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private boolean checkRealmListType(VariableElement field) {
    // Check for missing generic (default back to Object)
    if (Utils.getGenericTypeQualifiedName(field) == null) {
        Utils.error("No generic type supplied for field", field);
        return false;
    }

    // Check that the referenced type is a concrete class and not an interface
    TypeMirror fieldType = field.asType();
    final TypeMirror elementTypeMirror = ((DeclaredType) fieldType).getTypeArguments().get(0);
    if (elementTypeMirror.getKind() == TypeKind.DECLARED /* class of interface*/) {
        TypeElement elementTypeElement = (TypeElement) ((DeclaredType) elementTypeMirror).asElement();
        if (elementTypeElement.getSuperclass().getKind() == TypeKind.NONE) {
            Utils.error(
                    "Only concrete Realm classes are allowed in RealmLists. "
                            + "Neither interfaces nor abstract classes are allowed.",
                    field);
            return false;
        }
    }

    // Check if the actual value class is acceptable
    if (!validListValueTypes.contains(elementTypeMirror) && !Utils.isRealmModel(elementTypeMirror)) {
        final StringBuilder messageBuilder = new StringBuilder(
                "Element type of RealmList must be a class implementing 'RealmModel' or one of the ");
        final String separator = ", ";
        for (TypeMirror type : validListValueTypes) {
            messageBuilder.append('\'').append(type.toString()).append('\'').append(separator);
        }
        messageBuilder.setLength(messageBuilder.length() - separator.length());
        messageBuilder.append('.');
        Utils.error(messageBuilder.toString(), field);
        return false;
    }

    return true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:38,代碼來源:ClassMetaData.java

示例8: checkRealmResultsType

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private boolean checkRealmResultsType(VariableElement field) {
    // Only classes implementing RealmModel are allowed since RealmResults field is used only for backlinks.

    // Check for missing generic (default back to Object)
    if (Utils.getGenericTypeQualifiedName(field) == null) {
        Utils.error("No generic type supplied for field", field);
        return false;
    }

    TypeMirror fieldType = field.asType();
    final TypeMirror elementTypeMirror = ((DeclaredType) fieldType).getTypeArguments().get(0);
    if (elementTypeMirror.getKind() == TypeKind.DECLARED /* class or interface*/) {
        TypeElement elementTypeElement = (TypeElement) ((DeclaredType) elementTypeMirror).asElement();
        if (elementTypeElement.getSuperclass().getKind() == TypeKind.NONE) {
            Utils.error(
                    "Only concrete Realm classes are allowed in RealmResults. "
                            + "Neither interfaces nor abstract classes are allowed.",
                    field);
            return false;
        }
    }

    // Check if the actual value class is acceptable
    if (!Utils.isRealmModel(elementTypeMirror)) {
        Utils.error("Element type of RealmResults must be a class implementing 'RealmModel'.", field);
        return false;
    }

    return true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:ClassMetaData.java

示例9: getMethodParameters

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
public TypeMirror[] getMethodParameters(ExecutableElement m) {
    Collection<? extends VariableElement> ps = m.getParameters();
    TypeMirror[] r = new TypeMirror[ps.size()];
    int i=0;
    for (VariableElement p : ps)
        r[i++] = p.asType();
    return r;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:ApNavigator.java

示例10: addConstant

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private void addConstant(VariableElement v) {
    Set<Modifier> mods = v.getModifiers();
    if (!(mods.contains(Modifier.FINAL) && mods.contains(Modifier.STATIC))) {
        return;
    }
    
    boolean ok = false;
    
    // check that the return type is the same as this class' type
    if (!compilationInfo.getTypes().isSameType(
            v.asType(), classElement.asType())) {
        // the constant may be primitive & our type the wrapper
        TypeMirror t = v.asType();
        if (t instanceof PrimitiveType) {
            PrimitiveType p = (PrimitiveType)t;
            if (compilationInfo.getTypes().isSameType(
                    compilationInfo.getTypes().boxedClass(p).asType(),
                    classElement.asType())) {
                ok = true;
            }
        } 
        if (!ok) {
            return;
        }
    }
    
    addConstant(v.getSimpleName().toString());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:BeanModelBuilder.java

示例11: createVariables

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
/**
 * Crates method formal parameters, following code style conventions.
 * The trees in 'statements' will be rewritten to use the new identifiers.
 * 
 * @param copy working copy
 * @param parameters variables to turn into parameters
 * @param statements trees that should refer to parameters
 * @return 
 */
static List<VariableTree> createVariables(WorkingCopy copy, List<VariableElement> parameters, 
        TreePath targetParent,
        List<TreePath> statements) {
    final TreeMaker make = copy.getTreeMaker();
    List<VariableTree> formalArguments = new LinkedList<VariableTree>();
    CodeStyle cs = CodeStyle.getDefault(copy.getFileObject());
    
    String prefix = cs.getParameterNamePrefix();
    String suffix = cs.getParameterNameSuffix(); 
    Map<VariableElement, CharSequence> renamedVariables = new HashMap<VariableElement, CharSequence>();
    Set<Name> changedNames = new HashSet<Name>();
    for (VariableElement p : parameters) {
        TypeMirror tm = p.asType();
        Tree type = make.Type(tm);
        Name formalArgName = p.getSimpleName();
        Set<Modifier> formalArgMods = EnumSet.noneOf(Modifier.class);
        
        if (p.getModifiers().contains(Modifier.FINAL)) {
            formalArgMods.add(Modifier.FINAL);
        }
        String strippedName = Utilities.stripVariableName(cs, p);
        CharSequence codeStyleName = Utilities.guessName(copy, strippedName, targetParent, prefix, suffix, p.getKind() == ElementKind.PARAMETER);
        if (!formalArgName.contentEquals(codeStyleName)) {
            renamedVariables.put(p, codeStyleName);
            changedNames.add(formalArgName);
        } else {
            codeStyleName = formalArgName;
        }
        formalArguments.add(make.Variable(make.Modifiers(formalArgMods), codeStyleName, type, null));
    }
    if (!changedNames.isEmpty()) {
        VariableRenamer renamer = new VariableRenamer(copy, renamedVariables, changedNames);
        for (TreePath stPath : statements) {
            renamer.scan(stPath, null);
        }
    }
    return formalArguments;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:48,代碼來源:IntroduceHint.java

示例12: getParametersAsString

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
String getParametersAsString(List<? extends VariableElement> params) {
    StringBuilder sb = new StringBuilder();
    for (VariableElement param : params) {
        TypeMirror t = param.asType();
        // prefix P for primitive and R for reference types, thus items will
        // be ordered lexically and correctly.
        sb.append(getTypeCode(t)).append("-").append(t).append("-");
    }
    return sb.toString();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:Utils.java

示例13: parseUiThreadAnnotation

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private void parseUiThreadAnnotation(Element element, Map<TypeElement, Builder> builderMap) {
    if (!(element instanceof ExecutableElement) || element.getKind() != METHOD) {
        throw new IllegalStateException(
                String.format("@%s annotation must be on a method.",
                        CallOnUiThread.class.getSimpleName()));
    }

    ExecutableElement executableElement = (ExecutableElement) element;
    if (!executableElement.getModifiers().contains(Modifier.PUBLIC)) {
        throw new IllegalStateException(
                String.format("@%s annotation must be on a public method.",
                        CallOnUiThread.class.getSimpleName()));
    }
    TypeElement typeElement = (TypeElement) element.getEnclosingElement();
    String name = executableElement.getSimpleName().toString();

    List<? extends VariableElement> methodParameters = executableElement.getParameters();
    TypeMirror returnTypeMirror = executableElement.getReturnType();
    if (returnTypeMirror.getKind() != TypeKind.VOID) {
        throw new IllegalStateException(String.format("@%s annotation must be on void method.",
                CallOnUiThread.class.getSimpleName()));
    }

    MethodParameter[] parameters = MethodParameter.NONE;

    if (!methodParameters.isEmpty()) {
        parameters = new MethodParameter[methodParameters.size()];
        for (int i = 0; i < methodParameters.size(); i++) {
            VariableElement variableElement = methodParameters.get(i);
            TypeMirror methodParameterType = variableElement.asType();
            if (methodParameterType instanceof TypeVariable) {
                TypeVariable typeVariable = (TypeVariable) methodParameterType;
                methodParameterType = typeVariable.getUpperBound();
            }
            parameters[i] = new MethodParameter(i, TypeName.get(methodParameterType),
                    variableElement.getSimpleName().toString());
        }
    }

    MethodThreadStitching methodThreadStitching = new MethodThreadStitching(name,
            TypeName.get(returnTypeMirror),
            Arrays.asList(parameters),
            Constants.TYPE_UI_THREAD);
    StitchGenerator.Builder builder = getOrCreateStitchingBuilder(builderMap, typeElement);
    builder.addMethod(methodThreadStitching);
}
 
開發者ID:amitkma,項目名稱:Stitch,代碼行數:47,代碼來源:StitchProcessor.java

示例14: parseNewThreadAnnotation

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private void parseNewThreadAnnotation(Element element, Map<TypeElement, Builder> builderMap) {
    if (!(element instanceof ExecutableElement) || element.getKind() != METHOD) {
        throw new IllegalStateException(
                String.format("@%s annotation must be on a method.",
                        CallOnNewThread.class.getSimpleName()));
    }

    ExecutableElement executableElement = (ExecutableElement) element;
    if (!executableElement.getModifiers().contains(Modifier.PUBLIC)) {
        throw new IllegalStateException(
                String.format("@%s annotation must be on a public method.",
                        CallOnNewThread.class.getSimpleName()));
    }
    TypeElement typeElement = (TypeElement) element.getEnclosingElement();
    String name = executableElement.getSimpleName().toString();

    List<? extends VariableElement> methodParameters = executableElement.getParameters();
    TypeMirror returnTypeMirror = executableElement.getReturnType();

    MethodParameter[] parameters = MethodParameter.NONE;

    if (!methodParameters.isEmpty()) {
        parameters = new MethodParameter[methodParameters.size()];
        for (int i = 0; i < methodParameters.size(); i++) {
            VariableElement variableElement = methodParameters.get(i);
            TypeMirror methodParameterType = variableElement.asType();
            if (methodParameterType instanceof TypeVariable) {
                TypeVariable typeVariable = (TypeVariable) methodParameterType;
                methodParameterType = typeVariable.getUpperBound();
            }
            parameters[i] = new MethodParameter(i, TypeName.get(methodParameterType),
                    variableElement.getSimpleName().toString());
        }
    }

    MethodThreadStitching methodThreadStitching = new MethodThreadStitching(
            name,
            TypeName.get(returnTypeMirror),
            Arrays.asList(parameters),
            Constants.TYPE_NEW_THREAD);

    StitchGenerator.Builder builder = getOrCreateStitchingBuilder(builderMap, typeElement);
    builder.addMethod(methodThreadStitching);
}
 
開發者ID:amitkma,項目名稱:Stitch,代碼行數:45,代碼來源:StitchProcessor.java

示例15: matchSignature

import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
private boolean matchSignature(int numSkippedParameters, ExecutableElement method, TypeMirror[] signature, Map<ExecutableElement, String> nonMatches, boolean requiresInjectedStamp) {
    int sIdx = 0;
    int cIdx = numSkippedParameters;
    boolean missingStampArgument = requiresInjectedStamp;
    while (cIdx < method.getParameters().size()) {
        VariableElement parameter = method.getParameters().get(cIdx++);
        TypeMirror paramType = parameter.asType();
        if (parameter.getAnnotation(InjectedNodeParameter.class) != null) {
            if (missingStampArgument && env.getTypeUtils().isSameType(paramType, stampType())) {
                missingStampArgument = false;
            }
            // skip injected parameters
            continue;
        }
        if (missingStampArgument) {
            nonMatches.put(method, String.format("missing injected %s argument", stampType()));
            return false;
        }

        if (cIdx == method.getParameters().size() && paramType.getKind() == TypeKind.ARRAY) {
            // last argument of constructor is varargs, match remaining intrinsic arguments
            TypeMirror varargsType = ((ArrayType) paramType).getComponentType();
            while (sIdx < signature.length) {
                if (!isTypeCompatible(varargsType, signature[sIdx++])) {
                    nonMatches.put(method, String.format("the types of argument %d are incompatible: %s != %s", sIdx, varargsType, signature[sIdx - 1]));
                    return false;
                }
            }
        } else if (sIdx >= signature.length) {
            // too many arguments in intrinsic method
            nonMatches.put(method, "too many arguments");
            return false;
        } else if (!isTypeCompatible(paramType, signature[sIdx++])) {
            nonMatches.put(method, String.format("the type of argument %d is incompatible: %s != %s", sIdx, paramType, signature[sIdx - 1]));
            return false;
        }
    }
    if (missingStampArgument) {
        nonMatches.put(method, String.format("missing injected %s argument", stampType()));
        return false;
    }

    if (sIdx != signature.length) {
        nonMatches.put(method, "not enough arguments");
        return false;
    }
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:49,代碼來源:NodeIntrinsicVerifier.java


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