當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。