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


Java Types類代碼示例

本文整理匯總了Java中javax.lang.model.util.Types的典型用法代碼示例。如果您正苦於以下問題:Java Types類的具體用法?Java Types怎麽用?Java Types使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: createOrUpdateFieldHolder

import javax.lang.model.util.Types; //導入依賴的package包/類
private void createOrUpdateFieldHolder(Element element, Elements elements, Types types, JsonObjectHolder objectHolder) {
    JsonIgnore ignoreAnnotation = element.getAnnotation(JsonIgnore.class);
    boolean shouldParse = ignoreAnnotation == null || ignoreAnnotation.ignorePolicy() == IgnorePolicy.SERIALIZE_ONLY;
    boolean shouldSerialize = ignoreAnnotation == null || ignoreAnnotation.ignorePolicy() == IgnorePolicy.PARSE_ONLY;

    if (shouldParse || shouldSerialize) {
        JsonFieldHolder fieldHolder = objectHolder.fieldMap.get(element.getSimpleName().toString());
        if (fieldHolder == null) {
            fieldHolder = new JsonFieldHolder();
            objectHolder.fieldMap.put(element.getSimpleName().toString(), fieldHolder);
        }

        String error = fieldHolder.fill(element, elements, types, null, null, objectHolder, shouldParse, shouldSerialize);
        if (!TextUtils.isEmpty(error)) {
            error(element, error);
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:JsonObjectProcessor.java

示例2: isOfKindAndType

import javax.lang.model.util.Types; //導入依賴的package包/類
private boolean isOfKindAndType(TypeMirror type, Element e, EnumSet<ElementKind> kinds, TypeMirror base, Scope scope, Trees trees, Types types) {
    if (type.getKind() != TypeKind.ERROR && kinds.contains(e.getKind())) {
        if (base == null)
            return true;
        if (types.isSubtype(type, base))
            return true;
    }
    if ((e.getKind().isClass() || e.getKind().isInterface()) && 
        (kinds.contains(ANNOTATION_TYPE) || kinds.contains(CLASS) || kinds.contains(ENUM) || kinds.contains(INTERFACE))) {
        DeclaredType dt = (DeclaredType)e.asType();
        for (Element ee : e.getEnclosedElements())
            if (trees.isAccessible(scope, ee, dt) && isOfKindAndType(ee.asType(), ee, kinds, base, scope, trees, types))
                return true;
    }
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:JavadocCompletionQuery.java

示例3: addMarkerAnnotationInstance

import javax.lang.model.util.Types; //導入依賴的package包/類
/**
 * Adds a statement creating a new MarkerAnnotation instance to builder.
 * Returns the name of the instance.
 * @param builder The builder to add to.
 * @param annotation The service annotation to gather info from.
 * @return The name of the new instance.
 */
public static String addMarkerAnnotationInstance(MethodSpec.Builder builder,
                                                 UserMarkerAnnotation annotation,
                                                 Types types,
                                                 Elements elements) {

    String siName =
            ((TypeElement)types.asElement(annotation.getServiceInterfaceType())).getQualifiedName().toString();
    builder.addComment("The following values were gathered from the original @Service annotation parameters,");
    builder.addComment("and included here for this specialized service processor.");
    builder.addStatement("$T marker = new $T($S, $S, $S, $S)",
            MARKER_ANNOTATION_CLASS_NAME,
            MARKER_ANNOTATION_CLASS_NAME,
            siName,
            annotation.getServiceInterfaceName(),
            annotation.getIndividualNameKey(),
            annotation.getOutputPackage(elements));

    return "marker";
}
 
開發者ID:c0d3d,項目名稱:easy-plugins,代碼行數:27,代碼來源:MarkerAnnotation.java

示例4: detectKind

import javax.lang.model.util.Types; //導入依賴的package包/類
private static KindOfType detectKind(CompilationInfo info, TypeMirror tm) {
    if (tm.getKind().isPrimitive()) {
        return KindOfType.valueOf(tm.getKind().name());
    }

    if (tm.getKind() == TypeKind.ARRAY) {
        return ((ArrayType) tm).getComponentType().getKind().isPrimitive() ? KindOfType.ARRAY_PRIMITIVE : KindOfType.ARRAY;
    }

    if (tm.getKind() == TypeKind.DECLARED) {
        Types t = info.getTypes();
        TypeElement en = info.getElements().getTypeElement("java.lang.Enum");

        if (en != null) {
            if (t.isSubtype(tm, t.erasure(en.asType()))) {
                return KindOfType.ENUM;
            }
        }

        if (((DeclaredType)tm).asElement().getKind().isClass() && ((TypeElement) ((DeclaredType) tm).asElement()).getQualifiedName().contentEquals("java.lang.String")) {
            return KindOfType.STRING;
        }
    }

    return KindOfType.OTHER;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:EqualsHashCodeGenerator.java

示例5: testAddImport14

import javax.lang.model.util.Types; //導入依賴的package包/類
public void testAddImport14() throws IOException {
    testFile = getFile(getSourceDir(), getSourcePckg() + "ImportsTest3.java");
    JavaSource src = getJavaSource(testFile);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            MethodTree node = (MethodTree) clazz.getMembers().get(0);
            BlockTree body = node.getBody();
            List<StatementTree> stats = new ArrayList<StatementTree>();
            for (StatementTree st : body.getStatements()) {
                stats.add(st);
            }
            TypeElement list = workingCopy.getElements().getTypeElement("java.util.Map.Entry");
            Types types = workingCopy.getTypes();
            TypeMirror tm = types.getArrayType(types.erasure(list.asType()));
            stats.add(make.Variable(make.Modifiers(Collections.<Modifier>emptySet()), "entry", make.Type(tm), null));
            workingCopy.rewrite(body, make.Block(stats, false));
        }
    };
    src.runModificationTask(task).commit();
    assertFiles("testAddImport14.pass");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ImportAnalysisTest.java

示例6: testAddImportOrder1

import javax.lang.model.util.Types; //導入依賴的package包/類
public void testAddImportOrder1() throws IOException {
    testFile = getFile(getSourceDir(), getSourcePckg() + "ImportsTest7.java");
    JavaSource src = getJavaSource(testFile);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
            MethodTree node = (MethodTree) clazz.getMembers().get(0);
            BlockTree body = node.getBody();
            List<StatementTree> stats = new ArrayList<StatementTree>();
            for (StatementTree st : body.getStatements()) {
                stats.add(st);
            }
            TypeElement list = workingCopy.getElements().getTypeElement("java.util.LinkedList");
            Types types = workingCopy.getTypes();
            TypeMirror tm = types.getArrayType(types.erasure(list.asType()));
            stats.add(make.Variable(make.Modifiers(Collections.<Modifier>emptySet()), "s", make.Type(tm), null));
            workingCopy.rewrite(body, make.Block(stats, false));
        }
    };
    src.runModificationTask(task).commit();
    assertFiles("testAddImportOrder1.pass");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ImportAnalysisTest.java

示例7: isOfKindAndType

import javax.lang.model.util.Types; //導入依賴的package包/類
private boolean isOfKindAndType(TypeMirror type, Element e, EnumSet<ElementKind> kinds, TypeMirror base, Scope scope, Trees trees, Types types) {
    if (type.getKind() != TypeKind.ERROR && kinds.contains(e.getKind())) {
        if (base == null) {
            return true;
        }
        if (types.isSubtype(type, base)) {
            return true;
        }
    }
    if ((e.getKind().isClass() || e.getKind().isInterface())
            && (kinds.contains(ANNOTATION_TYPE) || kinds.contains(CLASS) || kinds.contains(ENUM) || kinds.contains(INTERFACE))) {
        DeclaredType dt = (DeclaredType) e.asType();
        for (Element ee : e.getEnclosedElements()) {
            if (trees.isAccessible(scope, ee, dt) && isOfKindAndType(ee.asType(), ee, kinds, base, scope, trees, types)) {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:JavaCompletionTask.java

示例8: testGetFirstTypeArgument

import javax.lang.model.util.Types; //導入依賴的package包/類
public void testGetFirstTypeArgument() throws Exception {
    ClasspathInfo cpi = ClasspathInfo.create(srcFO);
    final AnnotationModelHelper helper = AnnotationModelHelper.create(cpi);
    helper.runJavaSourceTask(new Runnable() {
        public void run() {
            Elements elements = helper.getCompilationController().getElements();
            Types types = helper.getCompilationController().getTypes();
            TypeElement typeElement = elements.getTypeElement("java.util.Collection");
            // Collection<E>
            assertNull(EntityMappingsUtilities.getFirstTypeArgument(typeElement.asType()));
            // Collection
            assertNull(EntityMappingsUtilities.getFirstTypeArgument(types.erasure(typeElement.asType())));
            // Collection<String>
            TypeMirror stringType = elements.getTypeElement("java.lang.String").asType();
            TypeElement argTypeElement = EntityMappingsUtilities.getFirstTypeArgument(types.getDeclaredType(typeElement, stringType));
            assertTrue(argTypeElement.getQualifiedName().contentEquals("java.lang.String"));
        }
    });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:EntityMappingsUtilitiesTest.java

示例9: checkForUsagesOutsideOfType

import javax.lang.model.util.Types; //導入依賴的package包/類
private void checkForUsagesOutsideOfType(final Element target, TreePath currentPath, TreePathHandle elementBeingMoved) {
    final Types types = workingCopy.getTypes();
    TypeMirror targetType = target.asType();
    TreePath enclosingPath = JavaRefactoringUtils.findEnclosingClass(workingCopy, currentPath, true, true, true, true, false);
    Element enclosingEl = null;
    if(enclosingPath != null) {
        enclosingEl = workingCopy.getTrees().getElement(enclosingPath);
    }
    if(enclosingEl != null) {
        TypeMirror enclosingType = enclosingEl.asType();
        if(!(enclosedBy(targetType, enclosingType) || enclosedBy(enclosingType, targetType)) && !types.isSameType(enclosingType, targetType)) {
            usageOutsideOfType.put(elementBeingMoved, Boolean.TRUE);
        }
    } else {
        usageOutsideOfType.put(elementBeingMoved, Boolean.TRUE);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:MoveMembersTransformer.java

示例10: findExecutableMember

import javax.lang.model.util.Types; //導入依賴的package包/類
private ExecutableElement findExecutableMember(TypeElement clazz, String methodName, List<TypeMirror> paramTypes, Types types) {
    List<ExecutableElement> members = methodName.contentEquals(clazz.getSimpleName())
            ? ElementFilter.constructorsIn(clazz.getEnclosedElements())
            : ElementFilter.methodsIn(clazz.getEnclosedElements());
    outer: for (ExecutableElement ee : members) {
        if (ee.getKind() == ElementKind.CONSTRUCTOR || methodName.contentEquals(ee.getSimpleName())) {
            List<? extends TypeMirror> memberParamTypes = ((ExecutableType) ee.asType()).getParameterTypes();
            if (memberParamTypes.size() == paramTypes.size()) {
                Iterator<TypeMirror> it = paramTypes.iterator();
                for (TypeMirror memberParamType : memberParamTypes) {
                    TypeMirror type = it.next();
                    if (types.isSameType(type, memberParamType)) {
                        continue outer;
                    }
                }
                return ee;
            }
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:JavaReference.java

示例11: visitTypeCast

import javax.lang.model.util.Types; //導入依賴的package包/類
@Override
public Tree visitTypeCast(TypeCastTree castTree, Element elementToMatch) {
    TreePath path = getCurrentPath();
    Types types = workingCopy.getTypes();
    TypeMirror castTypeErasure = types.erasure(workingCopy.getTrees().getTypeMirror(path));
    TypeMirror elToMatchErasure = types.erasure(subTypeElement.asType());
    path = path.getParentPath();
    Element element = workingCopy.getTrees().getElement(path);
    if (element instanceof VariableElement && types.isSameType(castTypeErasure, elToMatchErasure)) {
        VariableElement varElement = (VariableElement)element;
        TypeMirror varTypeErasure = types.erasure(varElement.asType());
        if (types.isSameType(varTypeErasure, elToMatchErasure) && isReplaceCandidate(varElement)) {
            TypeCastTree newTree = make.TypeCast(
                make.Identifier(superTypeElement), castTree.getExpression());
            rewrite(castTree, newTree);
        }
    }
    return super.visitTypeCast(castTree, elementToMatch);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:UseSuperTypeRefactoringPlugin.java

示例12: processGlobalSetting

import javax.lang.model.util.Types; //導入依賴的package包/類
public static boolean processGlobalSetting(Types mTypes, List<? extends AnnotationMirror> annoMirrors, ProcessorPrinter pp) {
    for (AnnotationMirror am : annoMirrors) {
        //if not my want. ignore
        if (!isValidAnnotation(am, pp)) {
            continue;
        }
        Map<? extends ExecutableElement, ? extends AnnotationValue> methodMap = am.getElementValues();
        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> en : methodMap.entrySet()) {
            ExecutableElement key = en.getKey();//the method of annotation
            switch (key.getSimpleName().toString()) {
                case KEY_GSON_CONFIG: {
                    Object value = en.getValue().getValue(); //@GsonConfig
                    AnnotationMirror am2 = (AnnotationMirror) value;
                    handleGsonConfig(am2, pp);
                }

                default:
                    //next to do
                    break;
            }
        }
    }
    return true;
}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:25,代碼來源:ElementHelper.java

示例13: isInTypes

import javax.lang.model.util.Types; //導入依賴的package包/類
private static boolean isInTypes(Types types, TypeMirror tm, List<TypeMirror>[] sTypes, int from) {
    if (from >= sTypes.length) {
        return true;
    }
    for (TypeMirror testTM : sTypes[from]) {
        if (types.isSameType(tm, testTM)) {
            return isInTypes(types, tm, sTypes, from + 1);
        }
    }
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:AST2Bytecode.java

示例14: addEffectivelyFinalAutoCloseables

import javax.lang.model.util.Types; //導入依賴的package包/類
private void addEffectivelyFinalAutoCloseables(final Env env) throws IOException {
    final CompilationController controller = env.getController();
    final Elements elements = controller.getElements();
    final TypeElement te = elements.getTypeElement("java.lang.AutoCloseable"); //NOI18N
    if (te != null) {
        final Types types = controller.getTypes();
        final ElementUtilities eu = controller.getElementUtilities();
        final Scope scope = env.getScope();
        final Set<? extends TypeMirror> smartTypes = options.contains(Options.ALL_COMPLETION) ? null : getSmartTypes(env);
        final TypeElement enclClass = scope.getEnclosingClass();
        for (Element e : getLocalMembersAndVars(env)) {
            switch (e.getKind()) {
                case EXCEPTION_PARAMETER:
                case LOCAL_VARIABLE:
                case RESOURCE_VARIABLE:
                case PARAMETER:
                    if (types.isSubtype(e.asType(), te.asType()) && eu.isEffectivelyFinal((VariableElement) e)) {
                        results.add(itemFactory.createVariableItem(env.getController(), (VariableElement) e, e.asType(), anchorOffset, null, env.getScope().getEnclosingClass() != e.getEnclosingElement(), elements.isDeprecated(e), isOfSmartType(env, e.asType(), smartTypes), env.assignToVarPos()));
                    }
                    break;
                case FIELD:
                    if (types.isSubtype(e.asType(), te.asType())) {
                        String name = e.getSimpleName().toString();
                        if (THIS_KEYWORD.equals(name) || SUPER_KEYWORD.equals(name)) {
                            results.add(itemFactory.createKeywordItem(name, null, anchorOffset, isOfSmartType(env, e.asType(), smartTypes)));
                        } else {
                            TypeMirror tm = asMemberOf(e, enclClass != null ? enclClass.asType() : null, types);
                            results.add(itemFactory.createVariableItem(env.getController(), (VariableElement) e, tm, anchorOffset, null, env.getScope().getEnclosingClass() != e.getEnclosingElement(), elements.isDeprecated(e), isOfSmartType(env, tm, smartTypes), env.assignToVarPos()));
                        }
                    }
                    break;
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,代碼來源:JavaCompletionTask.java

示例15: getTargetTypeKind

import javax.lang.model.util.Types; //導入依賴的package包/類
public static TargetTypeKind getTargetTypeKind(Elements elements, Types types, TypeElement enclosingElement) {
    if (isInActivity(elements, types, enclosingElement)) {
        return TargetTypeKind.ACTIVITY;
    }
    if (isInFragment(elements, types, enclosingElement)) {
        return TargetTypeKind.FRAGMENT;
    }

    if (isInProvider(elements, types, enclosingElement)) {
        return TargetTypeKind.PROVIDER;
    }

    return TargetTypeKind.UNKNOWN;
}
 
開發者ID:chiclaim,項目名稱:MRouter,代碼行數:15,代碼來源:ProcessorUtils.java


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