当前位置: 首页>>代码示例>>Java>>正文


Java TypeMirror类代码示例

本文整理汇总了Java中javax.lang.model.type.TypeMirror的典型用法代码示例。如果您正苦于以下问题:Java TypeMirror类的具体用法?Java TypeMirror怎么用?Java TypeMirror使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TypeMirror类属于javax.lang.model.type包,在下文中一共展示了TypeMirror类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rewriteNewArrayTree

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
private void rewriteNewArrayTree(WorkingCopy copy, TreeMaker mk, TreePath natPath, TypeMirror compType) {
    NewArrayTree nat = (NewArrayTree)natPath.getLeaf();
    TypeMirror existing = copy.getTrees().getTypeMirror(natPath);
    int existingDim = numberOfDimensions(existing);
    int newDim = numberOfDimensions(compType);
    
    if (existingDim == newDim + 1 /* newDim is counted from component type, lacks the enclosing array */) {
        // simple, number of dimensions does not change
        copy.rewrite(nat.getType(), mk.Type(compType));
        return;
    }
    List<ExpressionTree> l = new ArrayList<ExpressionTree>(nat.getDimensions().subList(
            0, Math.min(newDim + 1, nat.getDimensions().size())));
    Tree replacement = mk.NewArray(mk.Type(compType), l, null);
    GeneratorUtilities.get(copy).copyComments(nat, replacement, true);
    GeneratorUtilities.get(copy).copyComments(nat, replacement, false);
    
    copy.rewrite(nat, replacement);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SuspiciousToArray.java

示例2: handleVarDef

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
private void handleVarDef(final JCVariableDecl node, final boolean endStatement) {
	final TreePath path = trees.getPath(compilationUnit, node);
	final TypeMirror typeMirror = trees.getElement(path).asType();

	printExpr(node.mods);
	print(substitutionInventory.applyTypeSubstitution(typeMirror));
	print(" ");
	print(node.name); // variable name
	if (node.init != null) {
		print(" = ");
		printExpr(node.init);
	}
	if (endStatement) {
		print(";");
	}
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:17,代码来源:AstSubstitutionProcessor.java

示例3: addToExceptionsMap

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
private void addToExceptionsMap(TypeMirror key, Tree value) {
    if (key == null || value == null)
        return ;
    
    Map<TypeMirror, List<Tree>> map = exceptions2HighlightsStack.peek();
    
    if (map == null) {
        map = new HashMap<TypeMirror, List<Tree>>();
        exceptions2HighlightsStack.pop();
        exceptions2HighlightsStack.push(map);
    }
    
    List<Tree> l = map.get(key);
    
    if (l == null) {
        map.put(key, l = new ArrayList<Tree>());
    }
    
    l.add(value);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:MethodExitDetector.java

示例4: processGetters

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
private void processGetters() {
    // Check presence !
    TypeMirror listType = compilationInfo.getElements().getTypeElement(LIST_CLASS).asType();
    TypeMirror mapType = compilationInfo.getElements().getTypeElement(MAP_CLASS).asType();
    for (ExecutableElement m : getters) {
        String n = getPropertyName(m.getSimpleName().toString());
        if (allProperties.containsKey(n)) {
            continue;
        }
        TypeMirror retType = m.getReturnType();
        TypeMirror erasure = compilationInfo.getTypes().erasure(retType);
        if (compilationInfo.getTypes().isAssignable(erasure, listType)) {
            addListProperty(m, n);
        } else if (compilationInfo.getTypes().isAssignable(erasure, mapType)) {
            addMapProperty(m, n);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:BeanModelBuilder.java

示例5: printInterfaces

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
private void printInterfaces(TypeElement e) {
    ElementKind kind = e.getKind();

    if(kind != ANNOTATION_TYPE) {
        List<? extends TypeMirror> interfaces = e.getInterfaces();
        if (interfaces.size() > 0) {
            writer.print((kind.isClass() ? " implements" : " extends"));

            boolean first = true;
            for(TypeMirror interf: interfaces) {
                if (!first)
                    writer.print(",");
                writer.print(" ");
                writer.print(interf.toString());
                first = false;
            }
        }
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:20,代码来源:PrintingProcessor.java

示例6: createCompleter

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
@Override
public Completer createCompleter(CompletionContext ctx) {
    FxProperty p = ctx.getEnclosingProperty();
    if (p == null || p.getType() == null) {
        return null;
    }
    TypeMirror m = p.getType().resolve(ctx.getCompilationInfo());
    if (m.getKind() == TypeKind.BOOLEAN) {
        return new EnumValueCompleter(ctx);
    }
    if (m.getKind() != TypeKind.DECLARED) {
        return null;
    }
    DeclaredType t = (DeclaredType)m;
    TypeElement tel = (TypeElement)t.asElement();
    if (tel.getQualifiedName().contentEquals("java.lang.Boolean")) {
        return new EnumValueCompleter(ctx);
    }
    if (tel.getKind() == ElementKind.ENUM) {
        return new EnumValueCompleter(ctx, tel);
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:EnumValueCompleter.java

示例7: addDependency

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
private void addDependency(TypeMirror tm) {
    if (tm.getKind() == TypeKind.ARRAY) {
        addDependency(((ArrayType)tm).getComponentType());
    } else if (tm.getKind() == TypeKind.WILDCARD) {
        WildcardType wt = (WildcardType)tm;
        TypeMirror bound = wt.getSuperBound();
        if (bound == null) {
            bound = wt.getExtendsBound();
        }
        addDependency(bound);
    } else if (tm.getKind() == TypeKind.DECLARED) {
        addDependency(
            ((TypeElement)compilationInfo.getTypes().asElement(tm)).getQualifiedName().toString()
        );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:BeanModelBuilder.java

示例8: genericIsAssignableTo

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
/**
 * Checks whether passed typeElement is assignable to passed genericType.
 *
 * @param typeMirror  the type element to check
 * @param genericType the genric type to check
 * @return true if typeElement is assignable to genericType otherwise false.
 */
public boolean genericIsAssignableTo(TypeMirror typeMirror, GenericType genericType) {

    if (typeMirror == null || genericType == null) {
        return false;
    }

    TypeMirror typeMirrorToCompareWith = genericType.getRawType();
    if (typeMirrorToCompareWith == null) {
        return false;
    }

    // Compare raw types - this will not work for super wildcard type since it has Object as raw type
    if (!typeComparison.isAssignableTo(getTypes().erasure(typeMirror), getTypes().erasure(typeMirrorToCompareWith))) {
        return false;
    }

    return isAssignableToGenericTypeRecursively(typeMirror, genericType);
}
 
开发者ID:toolisticon,项目名称:annotation-processor-toolkit,代码行数:26,代码来源:TypeUtils.java

示例9: visitCatch

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
@Override
public Boolean visitCatch(CatchTree tree, Stack<Tree> d) {
    TypeMirror type1 = info.getTrees().getTypeMirror(new TreePath(new TreePath(getCurrentPath(), tree.getParameter()), tree.getParameter().getType()));
    Types t = info.getTypes();
    
    if (type1 != null) {
        Set<TypeMirror> toRemove = new HashSet<TypeMirror>();
        Map<TypeMirror, List<Tree>> exceptions2Highlights = exceptions2HighlightsStack.peek();
        
        if (exceptions2Highlights != null) {
            for (TypeMirror type2 : exceptions2Highlights.keySet()) {
                if (t.isAssignable(type2, type1)) {
                    toRemove.add(type2);
                }
            }
            
            for (TypeMirror type : toRemove) {
                exceptions2Highlights.remove(type);
            }
        }
        
    }
    
    scan(tree.getParameter(), d);
    return scan(tree.getBlock(), d);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:MethodExitDetector.java

示例10: getArrayResourceMethodName

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
/**
 * Returns a method name from the {@link android.content.res.Resources} class for array resource
 * binding, null if the element type is not supported.
 */
private static FieldResourceBinding.Type getArrayResourceMethodName(Element element) {
  TypeMirror typeMirror = element.asType();
  if (TYPED_ARRAY_TYPE.equals(typeMirror.toString())) {
    return FieldResourceBinding.Type.TYPED_ARRAY;
  }
  if (TypeKind.ARRAY.equals(typeMirror.getKind())) {
    ArrayType arrayType = (ArrayType) typeMirror;
    String componentType = arrayType.getComponentType().toString();
    if (STRING_TYPE.equals(componentType)) {
      return FieldResourceBinding.Type.STRING_ARRAY;
    } else if ("int".equals(componentType)) {
      return FieldResourceBinding.Type.INT_ARRAY;
    } else if ("java.lang.CharSequence".equals(componentType)) {
      return FieldResourceBinding.Type.TEXT_ARRAY;
    }
  }
  return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:ButterKnifeProcessor.java

示例11: nonObjectSuperclass

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
/**
 * Returns the non-object superclass of the type with the proper type parameters.
 * An absent Optional is returned if there is no non-Object superclass.
 */
public static Optional<DeclaredType> nonObjectSuperclass(final Types types, Elements elements,
                                                         DeclaredType type) {
    checkNotNull(types);
    checkNotNull(elements);
    checkNotNull(type);

    final TypeMirror objectType =
            elements.getTypeElement(Object.class.getCanonicalName()).asType();
    // It's guaranteed there's only a single CLASS superclass because java doesn't have multiple
    // class inheritance.
    TypeMirror superclass = getOnlyElement(FluentIterable.from(types.directSupertypes(type))
            .filter(new Predicate<TypeMirror>() {
                @Override
                public boolean apply(TypeMirror input) {
                    return input.getKind().equals(TypeKind.DECLARED)
                            && (MoreElements.asType(
                            MoreTypes.asDeclared(input).asElement())).getKind().equals(ElementKind.CLASS)
                            && !types.isSameType(objectType, input);
                }
            }), null);
    return superclass != null
            ? Optional.of(MoreTypes.asDeclared(superclass))
            : Optional.<DeclaredType>absent();
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:29,代码来源:MoreTypes.java

示例12: computeMethodInvocation

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
private static List<? extends TypeMirror> computeMethodInvocation(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf();
    boolean errorInRealArguments = false;
    
    for (Tree param : nat.getArguments()) {
        errorInRealArguments |= param == error;
    }
    
    if (errorInRealArguments) {
        List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
        int[] proposedIndex = new int[1];
        List<ExecutableElement> ee = fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
        
        if (ee.isEmpty()) { //cannot be resolved
            return null;
        }
        
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return proposedTypes;
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CreateElementUtilities.java

示例13: builderIncludedTypes

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
@Value.Lazy
List<TypeElement> builderIncludedTypes() {
  Optional<FIncludeMirror> includes = builderInclude();

  ImmutableList<TypeMirror> typeMirrors = includes.isPresent()
      ? ImmutableList.copyOf(includes.get().valueMirror())
      : ImmutableList.<TypeMirror>of();

  FluentIterable<TypeElement> typeElements = FluentIterable.from(typeMirrors)
      .filter(DeclaredType.class)
      .transform(DeclatedTypeToElement.FUNCTION);

  ImmutableSet<String> uniqueTypeNames = typeElements
      .filter(IsPublic.PREDICATE)
      .transform(ElementToName.FUNCTION)
      .toSet();

  if (uniqueTypeNames.size() != typeMirrors.size()) {
    report().annotationNamed(IncludeMirror.simpleName())
        .warning("Some types were ignored, non-supported for inclusion: duplicates,"
            + " non declared reference types, non-public");
  }

  return typeElements.toList();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:Proto.java

示例14: testGetFirstTypeArgument

import javax.lang.model.type.TypeMirror; //导入依赖的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

示例15: visitDeclared

import javax.lang.model.type.TypeMirror; //导入依赖的package包/类
@Override
public TypeMirror visitDeclared(DeclaredType t, CompilationInfo p) {
    if (t.getTypeArguments().isEmpty()) {
        return t;
    }
    List<TypeMirror> newArgs = new ArrayList<TypeMirror>(t.getTypeArguments().size());
    for (TypeMirror tm : t.getTypeArguments()) {
        newArgs.add(visit(tm, p));
    }
    
    TypeMirror enclosing = t.getEnclosingType();
    if (enclosing != null) {
        enclosing = visit(enclosing, p);
    }
    
    return p.getTypes().getDeclaredType(
        (DeclaredType)enclosing,
        (TypeElement)t.asElement(), 
        newArgs.toArray(new TypeMirror[newArgs.size()]));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ControllerGenerator.java


注:本文中的javax.lang.model.type.TypeMirror类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。