本文整理汇总了Java中javax.lang.model.element.TypeParameterElement类的典型用法代码示例。如果您正苦于以下问题:Java TypeParameterElement类的具体用法?Java TypeParameterElement怎么用?Java TypeParameterElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TypeParameterElement类属于javax.lang.model.element包,在下文中一共展示了TypeParameterElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: alligatorWithBounds
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
/**
* The type parameters to place on the builder, with the "extends ..." bounds.
*/
String alligatorWithBounds() {
List<TypeParameterElement> allParameters = allParameters();
if (allParameters.isEmpty()) {
return "";
}
StringBuilder alligator = new StringBuilder("<");
String separator = "";
for (TypeParameterElement param : allParameters) {
alligator.append(separator);
separator = ", ";
alligator.append(param.toString());
for (TypeMirror bound : param.getBounds()) {
alligator.append(" extends ").append(bound);
}
}
return alligator.append(">").toString();
}
示例2: getChildInstanceOfClassFromGeneric
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
private Map<TypeParameterElement, TypeMirror> getChildInstanceOfClassFromGeneric(final TypeElement typeElement, final Class<?> aClass) {
Map<TypeParameterElement, TypeMirror> result = new HashMap<>();
for (TypeParameterElement element : typeElement.getTypeParameters()) {
List<? extends TypeMirror> bounds = element.getBounds();
for (TypeMirror bound : bounds) {
if (bound instanceof DeclaredType && ((DeclaredType) bound).asElement() instanceof TypeElement) {
Collection<TypeMirror> viewsType = getViewsType((TypeElement) ((DeclaredType) bound).asElement());
boolean isViewType = false;
for (TypeMirror viewType : viewsType) {
if (((DeclaredType) viewType).asElement().toString().equals(aClass.getCanonicalName())) {
isViewType = true;
}
}
if (isViewType) {
result.put(element, bound);
break;
}
}
}
}
return result;
}
示例3: TypevarContext
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
TypevarContext(TypeElement element, String renderedTypeString) {
List<? extends TypeParameterElement> typeParameters = element.getTypeParameters();
if (!typeParameters.isEmpty()) {
this.arguments = SourceTypes.extract(renderedTypeString).getValue();
this.parameters = Lists.newArrayList();
for (TypeParameterElement p : typeParameters) {
parameters.add(p.getSimpleName().toString());
}
// we allow having no arguments in a string as raw type/unspecified argument scenario
Verify.verify(arguments.isEmpty() || (parameters.size() == arguments.size()), parameters + " =/> " + arguments);
} else {
this.parameters = Collections.emptyList();
this.arguments = Collections.emptyList();
}
}
示例4: processTypeParameters
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
private TypeExtractor processTypeParameters(ExecutableElement method, EncodedElement.Builder builder) {
boolean isStatic = method.getModifiers().contains(Modifier.STATIC);
TypeExtractor typesReader = isStatic
? new TypeExtractor(types, method)
: this.typesReader;
for (TypeParameterElement p : method.getTypeParameters()) {
String name = p.getSimpleName().toString();
ImmutableList<Defined> bounds = typesReader.getDefined(p.getBounds());
if (!isStatic) {
typesReader = typesReader.withParameter(name, bounds);
}
builder.addTypeParams(new EncodedElement.TypeParam.Builder()
.name(name)
.addAllBounds(bounds)
.build());
}
builder.typeParameters(typesReader.parameters);
return typesReader;
}
示例5: makeTypeParamsCopy
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
/**
* Makes a list of trees representing the given type parameter elements.
*/
private static List<TypeParameterTree> makeTypeParamsCopy(
List<? extends TypeParameterElement> typeParams,
TreeMaker maker) {
if (typeParams.isEmpty()) {
return Collections.emptyList();
}
int size = typeParams.size();
if (size == 1) {
return Collections.singletonList(makeCopy(typeParams.get(0), maker));
}
List<TypeParameterTree> result = new ArrayList(size);
for (TypeParameterElement typeParam : typeParams) {
result.add(makeCopy(typeParam, maker));
}
return result;
}
示例6: initialize
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
@Override
void initialize(final Element element, CompilationController info) {
final String labelText;
if(element.getKind() == ElementKind.TYPE_PARAMETER) {
labelText = UIUtilities.createHeader((TypeParameterElement) element, info.getElements().isDeprecated(element), false, false, true);
} else {
labelText = UIUtilities.createHeader((VariableElement) element, info.getElements().isDeprecated(element), false, false, true);
}
final Icon labelIcon = ElementIcons.getElementIcon(element.getKind(), element.getModifiers());
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Dimension preferredSize = label.getPreferredSize();
label.setText(labelText);
label.setIcon(labelIcon);
label.setPreferredSize(preferredSize);
label.setMinimumSize(preferredSize);
}
});
}
示例7: deepSearchTypes
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
private boolean deepSearchTypes(DeclaredType currentElement, TypeMirror orig, TypeMirror something, Map<TypeMirror, TypeParameterElement> mappings) {
Types types = workingCopy.getTypes();
List<? extends TypeMirror> directSupertypes = types.directSupertypes(currentElement);
for (TypeMirror superType : directSupertypes) {
DeclaredType type = (DeclaredType) superType;
List<? extends TypeMirror> typeArguments = type.getTypeArguments();
for (int i = 0; i < typeArguments.size(); i++) {
TypeMirror typeArgument = typeArguments.get(i);
if (something.equals(typeArgument)) {
TypeElement asElement = (TypeElement) type.asElement();
mappings.put(orig, asElement.getTypeParameters().get(i));
if (types.erasure(targetType.asType()).equals(types.erasure(superType))) {
return true;
}
if(deepSearchTypes(type, orig, typeArgument, mappings)) {
break;
}
}
}
if (types.erasure(targetType.asType()).equals(types.erasure(superType))) {
mappings.remove(orig);
return true;
}
}
return false;
}
示例8: visitType
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
public Boolean visitType(TypeElement arg0, Void arg1) {
for (TypeParameterElement e : arg0.getTypeParameters()) {
if (stop) {
return false;
}
for (TypeMirror b : e.getBounds()) {
if (stop) {
return false;
}
if (b.accept(this, arg1)) {
return true;
}
}
}
TypeMirror superclass = arg0.getSuperclass();
if (superclass.getKind() == TypeKind.DECLARED) {
if (!((DeclaredType) superclass).asElement().getKind().isInterface()) {
return false;
}
}
return superclass.accept(this, arg1);
}
示例9: completeTypeVarName
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
private void completeTypeVarName(Element forElement, String prefix, int substitutionOffset) {
if (prefix.length() > 0) {
if (prefix.charAt(0) == '<') {
prefix = prefix.substring(1, prefix.length());
} else {
// not type param
return;
}
}
List<? extends TypeParameterElement> tparams = (forElement.getKind().isClass() || forElement.getKind().isInterface())
? ((TypeElement) forElement).getTypeParameters()
: ((ExecutableElement) forElement).getTypeParameters();
for (TypeParameterElement typeVariable : tparams) {
String name = typeVariable.getSimpleName().toString();
if (name.startsWith(prefix)) {
items.add(JavadocCompletionItem.createNameItem(
'<' + name + '>', substitutionOffset));
}
}
}
示例10: dumpTypeArguments
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
private void dumpTypeArguments(List<? extends TypeParameterElement> list) {
if (list.isEmpty()) {
return ;
}
boolean addSpace = false;
result.append("<");
for (TypeParameterElement e : list) {
if (addSpace) {
result.append(", ");
}
result.append(getTypeName(info, e.asType(), true));
addSpace = true;
}
result.append(">");
}
示例11: generateComment
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
public String generateComment(TypeElement clazz, CompilationInfo javac) {
StringBuilder builder = new StringBuilder(
// "/**\n" + // NOI18N
"\n" // NOI18N
);
if (clazz.getNestingKind() == NestingKind.TOP_LEVEL) {
builder.append("@author ").append(author).append("\n"); // NOI18N
}
if (SourceVersion.RELEASE_5.compareTo(srcVersion) <= 0) {
for (TypeParameterElement param : clazz.getTypeParameters()) {
builder.append("@param <").append(param.getSimpleName().toString()).append("> \n"); // NOI18N
}
}
if (SourceVersion.RELEASE_5.compareTo(srcVersion) <= 0 &&
JavadocUtilities.isDeprecated(javac, clazz)) {
builder.append("@deprecated\n"); // NOI18N
}
// builder.append("*/\n"); // NOI18N
return builder.toString();
}
示例12: parse
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
public static Spec parse(Element element, ProcessingEnvironment processingEnv) {
Messager messager = processingEnv.getMessager();
if (element.getKind() != ElementKind.INTERFACE) {
messager.printMessage(
Diagnostic.Kind.ERROR, "@DataEnum can only be used on interfaces.", element);
return null;
}
TypeElement dataEnum = (TypeElement) element;
List<TypeVariableName> typeVariableNames = new ArrayList<>();
for (TypeParameterElement typeParameterElement : dataEnum.getTypeParameters()) {
typeVariableNames.add(TypeVariableName.get(typeParameterElement));
}
List<Value> values = ValuesParser.parse(dataEnum, processingEnv);
if (values == null) {
return null;
}
ClassName enumInterface = ClassName.get(dataEnum);
return new Spec(enumInterface, typeVariableNames, values);
}
示例13: printFormalTypeParameters
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
private void printFormalTypeParameters(Parameterizable e,
boolean pad) {
List<? extends TypeParameterElement> typeParams = e.getTypeParameters();
if (typeParams.size() > 0) {
writer.print("<");
boolean first = true;
for(TypeParameterElement tpe: typeParams) {
if (!first)
writer.print(", ");
printAnnotationsInline(tpe);
writer.print(tpe.toString());
first = false;
}
writer.print(">");
if (pad)
writer.print(" ");
}
}
示例14: writeType
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
void writeType(TypeElement e) {
if (!acceptType.test(task.getElements().getBinaryName(e).toString()))
return ;
try {
analyzeElement(e);
writeTypes(e.getInterfaces());
out.write(e.getNestingKind().toString());
out.write(e.getQualifiedName().toString());
write(e.getSuperclass());
for (TypeParameterElement param : e.getTypeParameters()) {
visit(param, null);
}
List<Element> defs = new ArrayList<>(e.getEnclosedElements()); //XXX: forcing ordering for members - not completely correct!
Collections.sort(defs, (e1, e2) -> e1.toString().compareTo(e2.toString()));
for (Element def : defs) {
visit(def, null);
}
out.write("\n");
} catch (IOException ex) {
ex.printStackTrace();
}
}
示例15: visitTypeVariable
import javax.lang.model.element.TypeParameterElement; //导入依赖的package包/类
@Override
public Boolean visitTypeVariable(TypeVariable a, EqualVisitorParam p) {
if (p.type.getKind().equals(TYPEVAR)) {
TypeVariable b = (TypeVariable) p.type;
TypeParameterElement aElement = (TypeParameterElement) a.asElement();
TypeParameterElement bElement = (TypeParameterElement) b.asElement();
Set<ComparedElements> newVisiting = visitingSetPlus(p.visiting, aElement, bElement);
if (newVisiting.equals(p.visiting)) {
// We're already visiting this pair of elements.
// This can happen with our friend Eclipse when looking at <T extends Comparable<T>>.
// It incorrectly reports the upper bound of T as T itself.
return true;
}
// We use aElement.getBounds() instead of a.getUpperBound() to avoid having to deal with
// the different way intersection types (like <T extends Number & Comparable<T>>) are
// represented before and after Java 8. We do have an issue that this code may consider
// that <T extends Foo & Bar> is different from <T extends Bar & Foo>, but it's very
// hard to avoid that, and not likely to be much of a problem in practice.
return equalLists(aElement.getBounds(), bElement.getBounds(), newVisiting)
&& equal(a.getLowerBound(), b.getLowerBound(), newVisiting)
&& a.asElement().getSimpleName().equals(b.asElement().getSimpleName());
}
return false;
}