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