本文整理汇总了Java中javax.lang.model.type.DeclaredType.getEnclosingType方法的典型用法代码示例。如果您正苦于以下问题:Java DeclaredType.getEnclosingType方法的具体用法?Java DeclaredType.getEnclosingType怎么用?Java DeclaredType.getEnclosingType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.type.DeclaredType
的用法示例。
在下文中一共展示了DeclaredType.getEnclosingType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enclosedBy
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
private boolean enclosedBy(TypeMirror t1, TypeMirror t2) {
if(t1.getKind() == TypeKind.DECLARED) {
if(workingCopy.getTypes().isSameType(t1, t2)) {
return true;
}
DeclaredType dt = (DeclaredType) t1;
TypeMirror enclosingType = dt.getEnclosingType();
if(enclosingType.getKind() == TypeKind.NONE) {
return false;
} else {
return enclosedBy(enclosingType, t2);
}
} else {
return false;
}
}
示例2: visitDeclared
import javax.lang.model.type.DeclaredType; //导入方法依赖的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()]));
}
示例3: visitNewClass
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
@Override
public List<? extends TypeMirror> visitNewClass(NewClassTree node, Object p) {
TypeMirror tm = info.getTrees().getTypeMirror(getCurrentPath());
if (tm == null || tm.getKind() != TypeKind.DECLARED) {
return null;
}
Element el = info.getTrees().getElement(getCurrentPath());
if (el == null) {
return null;
}
if (theExpression.getLeaf() != node.getEnclosingExpression()) {
ExecutableType execType = (ExecutableType)info.getTypes().asMemberOf((DeclaredType)tm, el);
return visitMethodOrNew(node, p, node.getArguments(), execType);
} else {
DeclaredType dt = (DeclaredType)tm;
if (dt.getEnclosingType() == null) {
return null;
}
return Collections.singletonList(dt.getEnclosingType());
}
}
示例4: resolveCapturedTypeInt
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
/**
* Note: may return {@code null}, if an intersection type is encountered, to indicate a
* real type cannot be created.
*/
private static TypeMirror resolveCapturedTypeInt(CompilationInfo info, TypeMirror tm) {
if (tm == null) return tm;
TypeMirror orig = SourceUtils.resolveCapturedType(tm);
if (orig != null) {
tm = orig;
}
if (tm.getKind() == TypeKind.WILDCARD) {
TypeMirror extendsBound = ((WildcardType) tm).getExtendsBound();
TypeMirror superBound = ((WildcardType) tm).getSuperBound();
if (extendsBound != null || superBound != null) {
TypeMirror rct = resolveCapturedTypeInt(info, extendsBound != null ? extendsBound : superBound);
if (rct != null) {
switch (rct.getKind()) {
case WILDCARD:
return rct;
case ARRAY:
case DECLARED:
case ERROR:
case TYPEVAR:
case OTHER:
return info.getTypes().getWildcardType(
extendsBound != null ? rct : null, superBound != null ? rct : null);
}
} else {
// propagate failure out of all wildcards
return null;
}
}
} else if (tm.getKind() == TypeKind.INTERSECTION) {
return null;
}
if (tm.getKind() == TypeKind.DECLARED) {
DeclaredType dt = (DeclaredType) tm;
List<TypeMirror> typeArguments = new LinkedList<TypeMirror>();
for (TypeMirror t : dt.getTypeArguments()) {
TypeMirror targ = resolveCapturedTypeInt(info, t);
if (targ == null) {
// bail out, if the type parameter is a wildcard, it's probably not possible
// to create a proper parametrized type from it
if (t.getKind() == TypeKind.WILDCARD || t.getKind() == TypeKind.INTERSECTION) {
return null;
}
// use rawtype
typeArguments.clear();
break;
}
typeArguments.add(targ);
}
final TypeMirror enclosingType = dt.getEnclosingType();
if (enclosingType.getKind() == TypeKind.DECLARED) {
return info.getTypes().getDeclaredType((DeclaredType) enclosingType, (TypeElement) dt.asElement(), typeArguments.toArray(new TypeMirror[0]));
} else {
if (dt.asElement() == null) return dt;
return info.getTypes().getDeclaredType((TypeElement) dt.asElement(), typeArguments.toArray(new TypeMirror[0]));
}
}
if (tm.getKind() == TypeKind.ARRAY) {
ArrayType at = (ArrayType) tm;
TypeMirror tm2 = resolveCapturedTypeInt(info, at.getComponentType());
return info.getTypes().getArrayType(tm2 != null ? tm2 : tm);
}
return tm;
}
示例5: resolveCapturedTypeInt
import javax.lang.model.type.DeclaredType; //导入方法依赖的package包/类
private static TypeMirror resolveCapturedTypeInt(CompilationInfo info, TypeMirror tm) {
if (tm == null) {
return tm;
}
TypeMirror orig = resolveCapturedType(tm);
if (orig != null) {
tm = orig;
}
if (tm.getKind() == TypeKind.WILDCARD) {
TypeMirror extendsBound = ((WildcardType) tm).getExtendsBound();
TypeMirror rct = resolveCapturedTypeInt(info, extendsBound != null ? extendsBound : ((WildcardType) tm).getSuperBound());
if (rct != null) {
return rct.getKind() == TypeKind.WILDCARD ? rct : info.getTypes().getWildcardType(extendsBound != null ? rct : null, extendsBound == null ? rct : null);
}
}
if (tm.getKind() == TypeKind.DECLARED) {
DeclaredType dt = (DeclaredType) tm;
TypeElement el = (TypeElement) dt.asElement();
if (((DeclaredType)el.asType()).getTypeArguments().size() != dt.getTypeArguments().size()) {
return info.getTypes().getDeclaredType(el);
}
List<TypeMirror> typeArguments = new LinkedList<>();
for (TypeMirror t : dt.getTypeArguments()) {
typeArguments.add(resolveCapturedTypeInt(info, t));
}
final TypeMirror enclosingType = dt.getEnclosingType();
if (enclosingType.getKind() == TypeKind.DECLARED) {
return info.getTypes().getDeclaredType((DeclaredType) enclosingType, el, typeArguments.toArray(new TypeMirror[0]));
} else {
return info.getTypes().getDeclaredType(el, typeArguments.toArray(new TypeMirror[0]));
}
}
if (tm.getKind() == TypeKind.ARRAY) {
ArrayType at = (ArrayType) tm;
TypeMirror componentType = resolveCapturedTypeInt(info, at.getComponentType());
switch (componentType.getKind()) {
case VOID:
case EXECUTABLE:
case WILDCARD: // heh!
case PACKAGE:
break;
default:
return info.getTypes().getArrayType(componentType);
}
}
return tm;
}