本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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"));
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
示例15: defaultAction
import javax.lang.model.util.Types; //导入方法依赖的package包/类
@Override
protected TypeMirror defaultAction(TypeMirror e, Types types) {
return types.erasure(e);
}