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


Java TypeParameterElement類代碼示例

本文整理匯總了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();
}
 
開發者ID:google,項目名稱:CallBuilder,代碼行數:22,代碼來源:CallBuilderProcessor.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:PresenterInjectorRules.java

示例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();
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:TypeHierarchyCollector.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:Encodings.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:AbstractTestGenerator.java

示例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);
        }
    });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:WhereUsedPanelVariable.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:PullUpTransformer.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ExportNonAccessibleElement.java

示例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));
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:JavadocCompletionQuery.java

示例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("&lt;");
    
    for (TypeParameterElement e : list) {
        if (addSpace) {
            result.append(", ");
        }
        
        result.append(getTypeName(info, e.asType(), true));
        
        addSpace = true;
    }
        
    result.append("&gt;");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:GoToSupport.java

示例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();
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:JavadocGenerator.java

示例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);
}
 
開發者ID:spotify,項目名稱:dataenum,代碼行數:25,代碼來源:SpecParser.java

示例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(" ");
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:21,代碼來源:PrintingProcessor.java

示例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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:ElementStructureTest.java

示例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;
}
 
開發者ID:foodora,項目名稱:android-auto-mapper,代碼行數:25,代碼來源:MoreTypes.java


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