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


Java Types.erasure方法代碼示例

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


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

示例1: typeFor

import javax.lang.model.util.Types; //導入方法依賴的package包/類
public static Type typeFor(TypeMirror typeMirror, TypeMirror typeConverterType, Elements elements, Types types) {
    TypeMirror genericClassTypeMirror = types.erasure(typeMirror);
    boolean hasTypeConverter = typeConverterType != null && !typeConverterType.toString().equals("void");

    Type type;
    if (!hasTypeConverter && typeMirror instanceof ArrayType) {
        TypeMirror arrayTypeMirror = ((ArrayType)typeMirror).getComponentType();
        type = new ArrayCollectionType(Type.typeFor(arrayTypeMirror, null, elements, types));
    } else if (!hasTypeConverter && !genericClassTypeMirror.toString().equals(typeMirror.toString())) {
        type = CollectionType.collectionTypeFor(typeMirror, genericClassTypeMirror, elements, types);

        if (type == null) {
            if (typeMirror.toString().contains("?")) {
                throw new RuntimeException("Generic types with wildcards are currently not supported by LoganSquare.");
            }
            try {
                type = new ParameterizedTypeField(TypeName.get(typeMirror));
            } catch (Exception ignored) { }
        }
    } else {
        type = FieldType.fieldTypeFor(typeMirror, typeConverterType, elements, types);
    }

    return type;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:Type.java

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

示例3: replaceWithSuperType

import javax.lang.model.util.Types; //導入方法依賴的package包/類
private void replaceWithSuperType(TreePath path, VariableTree oldVarTree, VariableElement varElement, Element superTypeElement) {
    Types types = workingCopy.getTypes();
    TypeMirror supTypeErasure = types.erasure(superTypeElement.asType());
    DeclaredType varType = (DeclaredType) varElement.asType();
    TypeMirror theType = null;
    List<TypeMirror> supertypes = new LinkedList(types.directSupertypes(varType));
    while(!supertypes.isEmpty()) {
        TypeMirror supertype = supertypes.remove(0);
        if(types.isSameType(types.erasure(supertype), supTypeErasure)) {
            theType = supertype;
            break;
        }
        supertypes.addAll(types.directSupertypes(supertype));
    }
    
    if(theType == null) {
        theType = supTypeErasure;
    }
    Tree superTypeTree = make.Type(theType);
  
    ExpressionTree oldInitTree = oldVarTree.getInitializer();
    ModifiersTree oldModifiers = oldVarTree.getModifiers();
    Tree newTree = make.Variable(oldModifiers, oldVarTree.getName(), 
            superTypeTree, oldInitTree);
    rewrite(oldVarTree, newTree);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:UseSuperTypeRefactoringPlugin.java

示例4: visitClass

import javax.lang.model.util.Types; //導入方法依賴的package包/類
@Override
public Tree visitClass(ClassTree node, Element elementToFind) {
    if (workingCopy.getTreeUtilities().isSynthetic(getCurrentPath())) {
        return super.visitClass(node, elementToFind);
    }
    Trees trees = workingCopy.getTrees();
    Types types = workingCopy.getTypes();
    TypeMirror type2 = elementToFind.asType();
    type2 = types.erasure(type2);
    
    if (recursive) {
        TypeMirror type1 = trees.getTypeMirror(getCurrentPath());
        if (type1 != null) {
            type1 = types.erasure(type1);
            if (isSubtype(type1, type2)) {
                addUsage(getCurrentPath());
            }
        }
    } else {
        TypeElement el = (TypeElement) workingCopy.getTrees().getElement(getCurrentPath());
        if (el != null && el.getSuperclass()!=null && types.isSameType(types.erasure(el.getSuperclass()), type2) || containsType(el.getInterfaces(), type2)) {
            addUsage(getCurrentPath());
        }
    }
    return super.visitClass(node, elementToFind);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:FindSubtypesVisitor.java

示例5: visitLambdaExpression

import javax.lang.model.util.Types; //導入方法依賴的package包/類
@Override
public Tree visitLambdaExpression(LambdaExpressionTree node, Element elementToFind) {
    if (workingCopy.getTreeUtilities().isSynthetic(getCurrentPath())) {
        return super.visitLambdaExpression(node, elementToFind);
    }
    Trees trees = workingCopy.getTrees();
    Types types = workingCopy.getTypes();
    TypeMirror type1 = trees.getTypeMirror(getCurrentPath());
    if(type1 == null) {
        return super.visitLambdaExpression(node, elementToFind);
    }
    type1 = types.erasure(type1);
    TypeMirror type2 = elementToFind.asType();
    type2 = types.erasure(type2);
    
    if (types.isSameType(type1, type2) || (recursive && isSubtype(type1, type2))) {
        addUsage(getCurrentPath());
    }
    return super.visitLambdaExpression(node, elementToFind);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:FindSubtypesVisitor.java

示例6: run

import javax.lang.model.util.Types; //導入方法依賴的package包/類
@Override
public List<Fix> run(CompilationInfo compilationInfo, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    if (treePath.getLeaf().getKind() == Kind.METHOD) {
        MethodTree mt = (MethodTree) treePath.getLeaf();
        TreePath parentPath = treePath.getParentPath();
        ClassTree ct = (ClassTree) parentPath.getLeaf();
        Trees trees = compilationInfo.getTrees();
        Types types = compilationInfo.getTypes();
        TreeUtilities tu = compilationInfo.getTreeUtilities();
        TypeMirror type = types.erasure(trees.getTypeMirror(treePath));
        if (!Utilities.isValidType(type)) {
            return null;
        }
        for (Tree member : ct.getMembers()) {
            TreePath memberPath = new TreePath(parentPath, member);
            if (member.getKind() == Kind.METHOD && "<init>".contentEquals(((MethodTree)member).getName()) //NOI18N
                    && !tu.isSynthetic(memberPath) && types.isSameType(types.erasure(trees.getTypeMirror(memberPath)), type)) {
                return null;
            }
        }
        RenameConstructorFix fix = new RenameConstructorFix(compilationInfo.getSnapshot().getSource(), TreePathHandle.create(treePath, compilationInfo), offset, mt.getName(), ct.getSimpleName());
        return Collections.<Fix>singletonList(fix);
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:RenameConstructor.java

示例7: findOverridableMethods

import javax.lang.model.util.Types; //導入方法依賴的package包/類
/**Find all methods in given type and its supertypes, which are overridable.
 * 
 * @param type to inspect
 * @return list of all overridable methods
 *
 * @since 0.136
 */
public List<? extends ExecutableElement> findOverridableMethods(TypeElement type) {
    List<ExecutableElement> overridable = new ArrayList<>();
    final Set<Modifier> notOverridable = EnumSet.copyOf(NOT_OVERRIDABLE);
    if (!type.getModifiers().contains(Modifier.ABSTRACT)) {
        notOverridable.add(Modifier.ABSTRACT);
    }
    DeclaredType dt = (DeclaredType)type.asType();
    Types types = JavacTypes.instance(ctx);
    Set<String> typeStrings = new HashSet<>();
    for (ExecutableElement ee : ElementFilter.methodsIn(info.getElements().getAllMembers(type))) {
        
        TypeMirror methodType = types.erasure(types.asMemberOf(dt, ee));
        String methodTypeString = ee.getSimpleName().toString() + methodType.toString();
        if (typeStrings.contains(methodTypeString)) {
            continue;
        }
        Set<Modifier> set = EnumSet.copyOf(notOverridable);                
        set.removeAll(ee.getModifiers());                
        if (set.size() == notOverridable.size()
                && !overridesPackagePrivateOutsidePackage(ee, type) //do not offer package private methods in case they're from different package
                && !isOverridden(ee, type)) {
            overridable.add(ee);
            if (ee.getModifiers().contains(Modifier.ABSTRACT)) {
                typeStrings.add(methodTypeString);
            }
        }
    }
    Collections.reverse(overridable);
    return overridable;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:38,代碼來源:ElementUtilities.java

示例8: asMemberOf

import javax.lang.model.util.Types; //導入方法依賴的package包/類
TypeMirror asMemberOf(Element element, TypeMirror type, Types types) {
    TypeMirror ret = element.asType();
    TypeMirror enclType = element.getEnclosingElement().asType();
    if (enclType.getKind() == TypeKind.DECLARED) {
        enclType = types.erasure(enclType);
    }
    while (type != null && type.getKind() == TypeKind.DECLARED) {
        if ((enclType.getKind() != TypeKind.DECLARED || ((DeclaredType) enclType).asElement().getSimpleName().length() > 0) && types.isSubtype(type, enclType)) {
            ret = types.asMemberOf((DeclaredType) type, element);
            break;
        }
        type = ((DeclaredType) type).getEnclosingType();
    }
    return ret;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:BaseTask.java

示例9: hint

import javax.lang.model.util.Types; //導入方法依賴的package包/類
@TriggerPatterns({
    @TriggerPattern(value="if ($var instanceof $instanceofClass) {" +
                          "$type $name = ($castClass) $var;" +
                          "$stmts$;" +
                          "}"),
    @TriggerPattern(value="if ($var instanceof $instanceofClass) {" +
                          "final $type $name = ($castClass) $var;" +
                          "$stmts$;" +
                          "}"),
    @TriggerPattern(value="if ($var instanceof $instanceofClass) {" +
                          "$name = ($castClass) $var;" +
                          "$stmts$;" +
                          "}")
})
public static ErrorDescription hint(HintContext ctx) {
    TypeMirror tm1 = ctx.getInfo().getTrees().getTypeMirror(ctx.getVariables().get("$instanceofClass"));
    TreePath castClass = ctx.getVariables().get("$castClass");
    TypeMirror tm2 = ctx.getInfo().getTrees().getTypeMirror(castClass);
    Types t = ctx.getInfo().getTypes();

    if (!(Utilities.isValidType(tm1) && Utilities.isValidType(tm2))) {
        return null;
    }

    tm1 = t.erasure(tm1);
    tm2 = t.erasure(tm2);

    if (t.isSubtype(tm1, tm2)) {
        return null;
    }

    if (t.isSubtype(tm2, tm1)) {
        return null;
    }

    return ErrorDescriptionFactory.forTree(ctx, castClass, NbBundle.getMessage(CastVSInstanceOf.class,"ERR_CastVSInstanceOf"));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:38,代碼來源:CastVSInstanceOf.java

示例10: asMemberOf

import javax.lang.model.util.Types; //導入方法依賴的package包/類
private static TypeMirror asMemberOf(Element element, TypeMirror type, Types types) {
    TypeMirror ret = element.asType();
    TypeMirror enclType = element.getEnclosingElement().asType();
    if (enclType.getKind() == TypeKind.DECLARED)
        enclType = types.erasure(enclType);
    while(type != null && type.getKind() == TypeKind.DECLARED) {
        if (types.isSubtype(type, enclType)) {
            ret = types.asMemberOf((DeclaredType)type, element);
            break;
        }
        type = ((DeclaredType)type).getEnclosingType();
    }
    return ret;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:JavadocCompletionQuery.java

示例11: createSignature

import javax.lang.model.util.Types; //導入方法依賴的package包/類
private static String createSignature(ExecutableElement elm, Types types) {
    StringBuilder signature = new StringBuilder("(");
    for (VariableElement param : elm.getParameters()) {
        TypeMirror pt = param.asType();
        pt = types.erasure(pt);
        String paramType = getTypeBinaryName(pt);
        signature.append(getSignature(paramType));
    }
    signature.append(')');
    String returnType = getTypeBinaryName(types.erasure(elm.getReturnType()));
    signature.append(getSignature(returnType));
    return signature.toString();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:EditorContextSupport.java

示例12: isSameRawType

import javax.lang.model.util.Types; //導入方法依賴的package包/類
public boolean isSameRawType(TypeMirror type1, String type2ElementName) {
    TypeElement type2Element = getCompilationInfo().getElements().getTypeElement(type2ElementName);
    if (type2Element != null) {
        Types types = getCompilationInfo().getTypes();
        TypeMirror type2 = types.erasure(type2Element.asType());
        return types.isSameType(types.erasure(type1), type2);
    }
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:AnnotationHelper.java

示例13: visitDeclared

import javax.lang.model.util.Types; //導入方法依賴的package包/類
@Override
public TypeMirror visitDeclared(DeclaredType t, Types types) {
    if (TypeModeler.isSubElement((TypeElement) t.asElement(), collectionType)
            || TypeModeler.isSubElement((TypeElement) t.asElement(), mapType)) {
        Collection<? extends TypeMirror> args = t.getTypeArguments();
        TypeMirror[] safeArgs = new TypeMirror[args.size()];
        int i = 0;
        for (TypeMirror arg : args) {
            safeArgs[i++] = visit(arg, types);
        }
        return types.getDeclaredType((TypeElement) t.asElement(), safeArgs);
    }
    return types.erasure(t);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:MakeSafeTypeVisitor.java

示例14: erasure

import javax.lang.model.util.Types; //導入方法依賴的package包/類
public TypeMirror erasure(TypeMirror t) {
    Types tu = env.getTypeUtils();
    t = tu.erasure(t);
    if (t.getKind().equals(TypeKind.DECLARED)) {
        DeclaredType dt = (DeclaredType)t;
        if (!dt.getTypeArguments().isEmpty())
            return tu.getDeclaredType((TypeElement) dt.asElement());
    }
    return t;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:11,代碼來源:ApNavigator.java

示例15: defaultAction

import javax.lang.model.util.Types; //導入方法依賴的package包/類
@Override
protected TypeMirror defaultAction(TypeMirror e, Types types) {
    return types.erasure(e);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:MakeSafeTypeVisitor.java


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