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


Java TypeElement.getTypeParameters方法代碼示例

本文整理匯總了Java中javax.lang.model.element.TypeElement.getTypeParameters方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeElement.getTypeParameters方法的具體用法?Java TypeElement.getTypeParameters怎麽用?Java TypeElement.getTypeParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.lang.model.element.TypeElement的用法示例。


在下文中一共展示了TypeElement.getTypeParameters方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getChildInstanceOfClassFromGeneric

import javax.lang.model.element.TypeElement; //導入方法依賴的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

示例2: TypevarContext

import javax.lang.model.element.TypeElement; //導入方法依賴的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

示例3: paramElementFor

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
private static Element paramElementFor(Element methodOrClass, ParamTree ptag) {
    ElementKind kind = methodOrClass.getKind();
    List<? extends Element> params = Collections.emptyList();
    if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
        ExecutableElement ee = (ExecutableElement) methodOrClass;
        params = ptag.isTypeParameter()
                ? ee.getTypeParameters()
                : ee.getParameters();
    } else if (kind.isClass() || kind.isInterface()) {
        TypeElement te = (TypeElement) methodOrClass;
        params = te.getTypeParameters();
    }

    for (Element param : params) {
        if (param.getSimpleName().contentEquals(ptag.getName().getName())) {
            return param;
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:JavadocImports.java

示例4: visitType

import javax.lang.model.element.TypeElement; //導入方法依賴的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

示例5: generateComment

import javax.lang.model.element.TypeElement; //導入方法依賴的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

示例6: parse

import javax.lang.model.element.TypeElement; //導入方法依賴的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

示例7: writeType

import javax.lang.model.element.TypeElement; //導入方法依賴的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

示例8: getViewClassFromGeneric

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
private String getViewClassFromGeneric(TypeElement typeElement) {
	TypeMirror superclass = typeElement.asType();

	Map<String, String> parentTypes = Collections.emptyMap();

	if (!typeElement.getTypeParameters().isEmpty()) {
		MvpCompiler.getMessager().printMessage(Diagnostic.Kind.WARNING, "Your " + typeElement.getSimpleName() + " is typed. @InjectViewState may generate wrong code. Your can set view/view state class manually.");
	}

	while (superclass.getKind() != TypeKind.NONE) {
		TypeElement superclassElement = (TypeElement) ((DeclaredType) superclass).asElement();

		final List<? extends TypeMirror> typeArguments = ((DeclaredType) superclass).getTypeArguments();
		final List<? extends TypeParameterElement> typeParameters = superclassElement.getTypeParameters();

		if (typeArguments.size() > typeParameters.size()) {
			throw new IllegalArgumentException("Code generation for interface " + typeElement.getSimpleName() + " failed. Simplify your generics. (" + typeArguments + " vs " + typeParameters + ")");
		}

		Map<String, String> types = new HashMap<>();
		for (int i = 0; i < typeArguments.size(); i++) {
			types.put(typeParameters.get(i).toString(), fillGenerics(parentTypes, typeArguments.get(i)));
		}

		if (superclassElement.toString().equals(MVP_PRESENTER_CLASS)) {
			// MvpPresenter is typed only on View class
			return fillGenerics(parentTypes, typeArguments);
		}

		parentTypes = types;

		superclass = superclassElement.getSuperclass();
	}

	return "";
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:37,代碼來源:ViewStateProviderClassGenerator.java

示例9: checkParentMethod

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
/**
 * A Helper method for {@link #loadMethodDetails(TypeElement)} which does the hard work of actually
 * checking the types for the parents.
 *
 * @param declaredType The DeclaredType object for the interface which has the method
 * @param method       The method checking for types on
 * @return A method detail, either with the Generic return type, or the default return type
 */
private MethodDetail checkParentMethod(DeclaredType declaredType, ExecutableElement method) {
    // check to see if we have any type parameters at all, if we don't then we can just create
    // the standard method
    TypeElement typeElement = (TypeElement) (declaredType).asElement();
    List<? extends TypeParameterElement> typeParameters = typeElement.getTypeParameters();
    if (typeParameters.isEmpty()) {
        new MethodDetail(method);
    }

    // otherwise we need to check if our return type is actually one of our generic parameters
    // first we need to check if our method return type matches one of our Type Parameters
    Optional<? extends TypeParameterElement> element = typeParameters.stream()
            .filter(parameterElement -> parameterElement.asType().getKind().equals(method.getReturnType().getKind()))
            .findFirst();

    return element.map(matchingType -> {
        final List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
        final int parameterIndex = typeParameters.indexOf(matchingType);
        final TypeMirror returnType;

        if (typeArguments.size() > parameterIndex) {
            returnType = typeArguments.get(parameterIndex);
        } else {
            returnType = ((TypeVariable) matchingType.asType()).getUpperBound();
        }

        return new MethodDetail(method, Optional.of(returnType));
    }).orElse(new MethodDetail(method));
}
 
開發者ID:peckb1,項目名稱:autojackson,代碼行數:38,代碼來源:ImplementationCreator.java

示例10: formalTypeParametersString

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
String formalTypeParametersString(TypeElement type) {
  List<? extends TypeParameterElement> typeParameters = type.getTypeParameters();
  if (typeParameters.isEmpty()) {
    return "";
  } else {
    StringBuilder sb = new StringBuilder("<");
    String sep = "";
    for (TypeParameterElement typeParameter : typeParameters) {
      sb.append(sep);
      sep = ", ";
      appendTypeParameterWithBounds(sb, typeParameter);
    }
    return sb.append(">").toString();
  }
}
 
開發者ID:sopak,項目名稱:auto-value-step-builder,代碼行數:16,代碼來源:TypeSimplifier.java

示例11: iterateInterfaces

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
private List<Method> iterateInterfaces(int level, TypeElement parentElement, String parentDefaultStrategy, Map<String, String> parentTypes, List<Method> rootMethods, List<Method> superinterfacesMethods) {
	for (TypeMirror typeMirror : parentElement.getInterfaces()) {
		final TypeElement anInterface = (TypeElement) ((DeclaredType) typeMirror).asElement();

		final List<? extends TypeMirror> typeArguments = ((DeclaredType) typeMirror).getTypeArguments();
		final List<? extends TypeParameterElement> typeParameters = anInterface.getTypeParameters();

		if (typeArguments.size() > typeParameters.size()) {
			throw new IllegalArgumentException("Code generation for interface " + anInterface.getSimpleName() + " failed. Simplify your generics.");
		}

		Map<String, String> types = new HashMap<>();
		for (int i = 0; i < typeArguments.size(); i++) {
			types.put(typeParameters.get(i).toString(), typeArguments.get(i).toString());
		}

		Map<String, String> totalInterfaceTypes = new HashMap<>(typeParameters.size());
		for (int i = 0; i < typeArguments.size(); i++) {
			totalInterfaceTypes.put(typeParameters.get(i).toString(), fillGenerics(parentTypes, typeArguments.get(i)));
		}
		for (int i = typeArguments.size(); i < typeParameters.size(); i++) {
			if (typeParameters.get(i).getBounds().size() != 1) {
				throw new IllegalArgumentException("Code generation for interface " + anInterface.getSimpleName() + " failed. Simplify your generics.");
			}

			totalInterfaceTypes.put(typeParameters.get(i).toString(), typeParameters.get(i).getBounds().get(0).toString());
		}

		String defaultStrategy = parentDefaultStrategy != null ? parentDefaultStrategy : getStateStrategyType(anInterface);

		getMethods(totalInterfaceTypes, anInterface, defaultStrategy, rootMethods, superinterfacesMethods);

		iterateInterfaces(level + 1, anInterface, defaultStrategy, types, rootMethods, superinterfacesMethods);
	}

	return superinterfacesMethods;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:38,代碼來源:ViewStateClassGenerator.java

示例12: getDeclaredType

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
private DeclaredType getDeclaredType(TypeElement e, HashMap<? extends Element, ? extends TypeMirror> map, Types types) {
    List<? extends TypeParameterElement> tpes = e.getTypeParameters();
    TypeMirror[] targs = new TypeMirror[tpes.size()];
    int i = 0;
    for (Iterator<? extends TypeParameterElement> it = tpes.iterator(); it.hasNext();) {
        TypeParameterElement tpe = it.next();
        TypeMirror t = map.get(tpe);
        targs[i++] = t != null ? t : tpe.asType();
    }
    Element encl = e.getEnclosingElement();
    if ((encl.getKind().isClass() || encl.getKind().isInterface()) && !((TypeElement)encl).getTypeParameters().isEmpty())
            return types.getDeclaredType(getDeclaredType((TypeElement)encl, map, types), e, targs);
    return types.getDeclaredType(e, targs);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:ElementUtilities.java

示例13: createHtmlHeader

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
private static String createHtmlHeader(boolean deprecated, TypeElement e) {
    StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    if (deprecated) sb.append("<s>");
    sb.append(e.getSimpleName());
    if (deprecated) sb.append("</s>");
    List<? extends TypeParameterElement> typeParams = e.getTypeParameters();
    if (typeParams != null && !typeParams.isEmpty()) {
        sb.append("&lt;"); // NOI18N
        for(Iterator<? extends TypeParameterElement> it = typeParams.iterator(); it.hasNext();) {
            TypeParameterElement tp = it.next();
            sb.append(tp.getSimpleName());
            try {
                List<? extends TypeMirror> bounds = tp.getBounds();
                if (!bounds.isEmpty()) {
                    sb.append(translateToHTML(printBounds(bounds)));
                }
            }
            catch (NullPointerException npe) {
            }                    
            if (it.hasNext()) {
                sb.append(", "); // NOI18N
            }
        }
        sb.append("&gt;"); // NOI18N
    }
    return sb.toString();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:ElementNode.java

示例14: actualTypeParametersString

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
static String actualTypeParametersString(TypeElement type) {
  List<? extends TypeParameterElement> typeParameters = type.getTypeParameters();
  if (typeParameters.isEmpty()) {
    return "";
  } else {
    return typeParameters.stream()
        .map(e -> e.getSimpleName().toString())
        .collect(joining(", ", "<", ">"));
  }
}
 
開發者ID:sopak,項目名稱:auto-value-step-builder,代碼行數:11,代碼來源:TypeSimplifier.java

示例15: formalTypeParametersString

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
String formalTypeParametersString(TypeElement type) {
    List<? extends TypeParameterElement> typeParameters = type.getTypeParameters();
    if (typeParameters.isEmpty()) {
        return "";
    } else {
        StringBuilder sb = new StringBuilder("<");
        String sep = "";
        for (TypeParameterElement typeParameter : typeParameters) {
            sb.append(sep);
            sep = ", ";
            appendTypeParameterWithBounds(sb, typeParameter);
        }
        return sb.append(">").toString();
    }
}
 
開發者ID:ccheptea,項目名稱:auto-value-node,代碼行數:16,代碼來源:TypeSimplifier.java


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