本文整理汇总了Java中javax.lang.model.type.DeclaredType类的典型用法代码示例。如果您正苦于以下问题:Java DeclaredType类的具体用法?Java DeclaredType怎么用?Java DeclaredType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeclaredType类属于javax.lang.model.type包,在下文中一共展示了DeclaredType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findMethod
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
public static ExecutableElement findMethod(CompilationInfo javac, TypeElement clazz, String name, List<? extends VariableElement> params, boolean includeSupertypes) {
if (name == null || name.length() == 0) {
return null;
}
TypeElement c = clazz;
while (true) {
for (Element elm : c.getEnclosedElements()) {
if (ElementKind.METHOD == elm.getKind()) {
ExecutableElement m = (ExecutableElement) elm;
if (name.contentEquals(m.getSimpleName())
&& compareParams(javac, params, m.getParameters())
&& isAccessible(javac, clazz, m)) {
return m;
}
}
}
TypeMirror superType = c.getSuperclass();
if (!includeSupertypes || superType.getKind() == TypeKind.NONE) {
return null;
}
c = (TypeElement) ((DeclaredType) superType).asElement();
}
}
示例2: validate
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
public void validate(CompilationInfo info) {
TypeElement test = info.getElements().getTypeElement("test.Test");
VariableElement var = ElementFilter.fieldsIn(test.getEnclosedElements()).get(0);
List<? extends ExecutableElement> methods = ElementFilter.methodsIn(test.getEnclosedElements());
assertEquals(1, methods.size());
ExecutableElement method = methods.get(0);
TypeMirror type = info.getTypes().asMemberOf((DeclaredType)test.asType(), var);
if (getter) {
assertTrue(info.getTypes().isSameType(type, method.getReturnType()));
assertEquals(type.getKind() == TypeKind.BOOLEAN ? "isTest" : "getTest", method.getSimpleName().toString());
assertEquals(0, method.getParameters().size());
} else {
assertTrue(info.getTypes().isSameType(info.getTypes().getNoType(TypeKind.VOID), method.getReturnType()));
assertEquals("setTest", method.getSimpleName().toString());
assertEquals(1, method.getParameters().size());
assertTrue(info.getTypes().isSameType(type, method.getParameters().get(0).asType()));
}
}
示例3: visitClass
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
@Override
public Void visitClass(ClassTree node, Void p) {
TypeElement te = (TypeElement) trees.getElement(getCurrentPath());
Set<PhaseDescription> expected = new HashSet<>();
for (AnnotationMirror am : getTriggersCompleteAnnotation(te)) {
TypeMirror of = (TypeMirror) findAttribute(am, "of").getValue();
Name ofName = elements.getBinaryName((TypeElement) ((DeclaredType) of).asElement());
Element at = (Element) findAttribute(am, "at").getValue();
Phase phase = Phase.valueOf(at.getSimpleName().toString());
expected.add(new PhaseDescription(ofName.toString(), phase));
}
if (!expected.isEmpty())
topLevel2Expected.put(elements.getBinaryName(te).toString(), expected);
return super.visitClass(node, p);
}
示例4: unboxBoxed
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
/**
* Unbox a wrapper type into a TypeKind. Some additional types are mapped to TypeKinds which cannot really appear in
* expressions (at least I hope)
*
* @param tm
* @return
*/
private static TypeKind unboxBoxed(TypeMirror tm) {
TypeElement te = (TypeElement)((DeclaredType)tm).asElement();
String qn = te.getQualifiedName().toString();
if (!qn.startsWith("java.lang.")) { // NO18N
if (qn.equals("java.math.BigInteger")) { // NOI18N
return TypeKind.WILDCARD;
}
return null;
}
switch (qn.substring(10)) {
case "Short": return TypeKind.SHORT; // NOI18N
case "Long": return TypeKind.LONG; // NOI18N
case "Byte": return TypeKind.BYTE; // NOI18N
case "Integer": return TypeKind.INT; // NOI18N
case "Double": return TypeKind.DOUBLE; // NOI18N
case "Float": return TypeKind.FLOAT; // NOI18N
case "Character": return TypeKind.CHAR; // NOI18N
case "String": return TypeKind.OTHER; // NOI18N
case "Object": return TypeKind.PACKAGE; // NOI18N
}
return null;
}
示例5: convertIfAnonymous
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
/**
* Convert typemirror of an anonymous class to supertype/iface
*
* @return typemirror of supertype/iface, initial tm if not anonymous
*/
public static TypeMirror convertIfAnonymous(TypeMirror tm) {
//anonymous class?
Set<ElementKind> fm = EnumSet.of(ElementKind.METHOD, ElementKind.FIELD);
if (tm instanceof DeclaredType) {
Element el = ((DeclaredType) tm).asElement();
//XXX: the null check is needed for lambda type, not covered by test:
if (el != null && (el.getSimpleName().length() == 0 || fm.contains(el.getEnclosingElement().getKind()))) {
List<? extends TypeMirror> interfaces = ((TypeElement) el).getInterfaces();
if (interfaces.isEmpty()) {
tm = ((TypeElement) el).getSuperclass();
} else {
tm = interfaces.get(0);
}
}
}
return tm;
}
示例6: findViewTypeOfPresenter
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
private String findViewTypeOfPresenter(TypeElement presenterElement) {
TypeElement currentClass = presenterElement;
while (currentClass != null) {
if (currentClass.getSuperclass() instanceof DeclaredType) {
List<? extends TypeMirror> superClassParameters =
((DeclaredType) currentClass.getSuperclass()).getTypeArguments();
if (superClassParameters.size() == 1) {
String type = superClassParameters.get(0).toString();
if (!"V".equals(type)) return type;
}
}
currentClass = getSuperClass(currentClass);
}
return "";
}
示例7: visitDeclared
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
@Override
public StringBuilder visitDeclared(DeclaredType t, Boolean p) {
Element e = t.asElement();
if (e instanceof TypeElement) {
TypeElement te = (TypeElement)e;
DEFAULT_VALUE.append((p ? te.getQualifiedName() : te.getSimpleName()).toString());
Iterator<? extends TypeMirror> it = t.getTypeArguments().iterator();
if (it.hasNext()) {
DEFAULT_VALUE.append("<"); //NOI18N
while(it.hasNext()) {
visit(it.next(), p);
if (it.hasNext())
DEFAULT_VALUE.append(", "); //NOI18N
}
DEFAULT_VALUE.append(">"); //NOI18N
}
return DEFAULT_VALUE;
} else {
return DEFAULT_VALUE.append(UNKNOWN); //NOI18N
}
}
示例8: createCompleter
import javax.lang.model.type.DeclaredType; //导入依赖的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;
}
}
示例9: createTypeHierarchyCollector
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
TypeHierarchyCollector createTypeHierarchyCollector(final Reporter reporter, final Element element) {
return new TypeHierarchyCollector() {
@Override
protected String stringify(DeclaredType input, TypevarContext context) {
TypeStringProvider provider = new TypeStringProvider(
reporter,
element,
input,
newTypeStringResolver(),
context.parameters.toArray(new String[0]),
context.arguments.toArray(new String[0]));
provider.collectUnresolvedYetArgumentsTo(this.unresolvedYetArguments);
provider.process();
return provider.returnTypeName();
}
};
}
示例10: resolveReturnType
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
static TypeMirror resolveReturnType(
ProcessingEnvironment processing,
ExecutableElement method,
TypeElement typeElement) {
method = CachingElements.getDelegate(method);
TypeMirror returnType = method.getReturnType();
// We do not support parametrized accessor methods,
// but we do support inheriting parametrized accessors, which
// we supposedly parametrized with actual type parameters as
// our target class could not define formal type parameters also.
if (returnType.getKind() == TypeKind.TYPEVAR) {
return asInheritedMemberReturnType(processing, typeElement, method);
} else if (returnType.getKind() == TypeKind.DECLARED
|| returnType.getKind() == TypeKind.ERROR) {
if (!((DeclaredType) returnType).getTypeArguments().isEmpty()) {
return asInheritedMemberReturnType(processing, typeElement, method);
}
}
return returnType;
}
示例11: includedTypes
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
@Value.Lazy
List<TypeElement> includedTypes() {
Optional<IncludeMirror> includes = include();
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();
}
示例12: makeOverrideMethod
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
private MethodSpec makeOverrideMethod(ExecutableElement method) {
TypeName requestTypeName = getRequestClassName(method);
DeclaredType responseReturnType = (DeclaredType) method.getReturnType();
TypeMirror responseBean = responseReturnType.getTypeArguments().get(0);
MethodSpec.Builder request = MethodSpec.methodBuilder(method.getSimpleName().toString())
.returns(ParameterizedTypeName.get(ClassName.get(Response.class), ClassName.get(responseBean)))
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class);
String initializeStatement = "return new " + processorElement.simpleName() + "_" + method.getSimpleName();
if (!method.getParameters().isEmpty()) {
request.addParameter(requestTypeName, "request");
request.addStatement(initializeStatement + "(request)");
} else
request.addStatement(initializeStatement + "($T.VOID_REQUEST)", RequestBean.class);
return request.build();
}
示例13: appendTypeArguments
import javax.lang.model.type.DeclaredType; //导入依赖的package包/类
private void appendTypeArguments(TypeMirror type, DeclaredType declaredType) {
List<? extends TypeMirror> arguments = declaredType.getTypeArguments();
if (!arguments.isEmpty()) {
buffer.append('<');
boolean notFirst = false;
for (TypeMirror argument : arguments) {
typeAnnotationHandle(argument);
if (notFirst) {
buffer.append(',').append(' ');
}
notFirst = true;
int mark = buffer.length();
caseType(argument);
cutTypeArgument(type, mark);
}
buffer.append('>');
}
}
示例14: 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()]));
}
示例15: replaceWithSuperType
import javax.lang.model.type.DeclaredType; //导入依赖的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);
}