当前位置: 首页>>代码示例>>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;未经允许,请勿转载。