本文整理匯總了Java中javax.lang.model.util.Types.isSameType方法的典型用法代碼示例。如果您正苦於以下問題:Java Types.isSameType方法的具體用法?Java Types.isSameType怎麽用?Java Types.isSameType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.lang.model.util.Types
的用法示例。
在下文中一共展示了Types.isSameType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sameMethod
import javax.lang.model.util.Types; //導入方法依賴的package包/類
protected boolean sameMethod(ExecutableElement method1, ExecutableElement method2) {
if (!method1.getSimpleName().equals(method2.getSimpleName()))
return false;
Types typeUtils = builder.getProcessingEnvironment().getTypeUtils();
if(!typeUtils.isSameType(method1.getReturnType(), method2.getReturnType())
&& !typeUtils.isSubtype(method2.getReturnType(), method1.getReturnType()))
return false;
List<? extends VariableElement> parameters1 = method1.getParameters();
List<? extends VariableElement> parameters2 = method2.getParameters();
if (parameters1.size() != parameters2.size())
return false;
for (int i = 0; i < parameters1.size(); i++) {
if (!typeUtils.isSameType(parameters1.get(i).asType(), parameters2.get(i).asType()))
return false;
}
return true;
}
示例2: containsSuiteMethod
import javax.lang.model.util.Types; //導入方法依賴的package包/類
/**
* Finds whether the given {@code TypeElement} or any of its type
* ancestor contains an accessible static no-arg method
* of the given name.
*
* @param typeElement {@code TypeElement} to search
* @param methodName name of the method to be found
* @param elements support instance to be used for the search
* @return {@code true} if the given {@code TypeElement} contains,
* whether inherited or declared directly,
* a static no-argument method of the given name,
* {@code false} otherwise
*/
private boolean containsSuiteMethod(TypeElement typeElement,
Elements elements,
Types types,
TypeMirror testType) {
List<ExecutableElement> allMethods
= ElementFilter.methodsIn(elements.getAllMembers(typeElement));
for (ExecutableElement method : allMethods) {
if (method.getSimpleName().contentEquals("suite") //NOI18N
&& method.getParameters().isEmpty()) {
return method.getModifiers().contains(Modifier.STATIC)
&& types.isSameType(method.getReturnType(),
testType);
}
}
return false;
}
示例3: findExecutableMember
import javax.lang.model.util.Types; //導入方法依賴的package包/類
private ExecutableElement findExecutableMember(TypeElement clazz, String methodName, List<TypeMirror> paramTypes, Types types) {
List<ExecutableElement> members = methodName.contentEquals(clazz.getSimpleName())
? ElementFilter.constructorsIn(clazz.getEnclosedElements())
: ElementFilter.methodsIn(clazz.getEnclosedElements());
outer: for (ExecutableElement ee : members) {
if (ee.getKind() == ElementKind.CONSTRUCTOR || methodName.contentEquals(ee.getSimpleName())) {
List<? extends TypeMirror> memberParamTypes = ((ExecutableType) ee.asType()).getParameterTypes();
if (memberParamTypes.size() == paramTypes.size()) {
Iterator<TypeMirror> it = paramTypes.iterator();
for (TypeMirror memberParamType : memberParamTypes) {
TypeMirror type = it.next();
if (types.isSameType(type, memberParamType)) {
continue outer;
}
}
return ee;
}
}
}
return null;
}
示例4: visitTypeCast
import javax.lang.model.util.Types; //導入方法依賴的package包/類
@Override
public Tree visitTypeCast(TypeCastTree castTree, Element elementToMatch) {
TreePath path = getCurrentPath();
Types types = workingCopy.getTypes();
TypeMirror castTypeErasure = types.erasure(workingCopy.getTrees().getTypeMirror(path));
TypeMirror elToMatchErasure = types.erasure(subTypeElement.asType());
path = path.getParentPath();
Element element = workingCopy.getTrees().getElement(path);
if (element instanceof VariableElement && types.isSameType(castTypeErasure, elToMatchErasure)) {
VariableElement varElement = (VariableElement)element;
TypeMirror varTypeErasure = types.erasure(varElement.asType());
if (types.isSameType(varTypeErasure, elToMatchErasure) && isReplaceCandidate(varElement)) {
TypeCastTree newTree = make.TypeCast(
make.Identifier(superTypeElement), castTree.getExpression());
rewrite(castTree, newTree);
}
}
return super.visitTypeCast(castTree, elementToMatch);
}
示例5: replaceWithSuperType
import javax.lang.model.util.Types; //導入方法依賴的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);
}
示例6: visitClass
import javax.lang.model.util.Types; //導入方法依賴的package包/類
@Override
public Tree visitClass(ClassTree node, Element elementToFind) {
if (workingCopy.getTreeUtilities().isSynthetic(getCurrentPath())) {
return super.visitClass(node, elementToFind);
}
Trees trees = workingCopy.getTrees();
Types types = workingCopy.getTypes();
TypeMirror type2 = elementToFind.asType();
type2 = types.erasure(type2);
if (recursive) {
TypeMirror type1 = trees.getTypeMirror(getCurrentPath());
if (type1 != null) {
type1 = types.erasure(type1);
if (isSubtype(type1, type2)) {
addUsage(getCurrentPath());
}
}
} else {
TypeElement el = (TypeElement) workingCopy.getTrees().getElement(getCurrentPath());
if (el != null && el.getSuperclass()!=null && types.isSameType(types.erasure(el.getSuperclass()), type2) || containsType(el.getInterfaces(), type2)) {
addUsage(getCurrentPath());
}
}
return super.visitClass(node, elementToFind);
}
示例7: isSameType
import javax.lang.model.util.Types; //導入方法依賴的package包/類
private static boolean isSameType (
@NonNull Types types,
@NullAllowed final TypeMirror t1,
@NonNull final TypeMirror t2,
final boolean rawType) {
return t1 == null ||
types.isSameType(
t1,
rawType ? types.erasure(t2) : t2);
}
示例8: isInTypes
import javax.lang.model.util.Types; //導入方法依賴的package包/類
private static boolean isInTypes(Types types, TypeMirror tm, List<TypeMirror>[] sTypes, int from) {
if (from >= sTypes.length) {
return true;
}
for (TypeMirror testTM : sTypes[from]) {
if (types.isSameType(tm, testTM)) {
return isInTypes(types, tm, sTypes, from + 1);
}
}
return false;
}
示例9: isValueSpecMarker
import javax.lang.model.util.Types; //導入方法依賴的package包/類
private static boolean isValueSpecMarker(
TypeMirror returnType, ProcessingEnvironment processingEnvironment) {
Types types = processingEnvironment.getTypeUtils();
Elements elements = processingEnvironment.getElementUtils();
return types.isSameType(
returnType, elements.getTypeElement(dataenum_case.class.getCanonicalName()).asType());
}
示例10: check
import javax.lang.model.util.Types; //導入方法依賴的package包/類
public Collection<ErrorDescription> check(JPAProblemContext ctx, HintContext hc, AttributeWrapper attrib) {
if (attrib.getModelElement() instanceof Version) {
TreeUtilities treeUtils = ctx.getCompilationInfo().getTreeUtilities();
Types types = ctx.getCompilationInfo().getTypes();
TypeMirror attrType = attrib.getType();
for (String typeName : validVersionTypes) {
TypeMirror type = treeUtils.parseType(typeName,
ctx.getJavaClass());
if (type != null && types.isSameType(attrType, type)) {
return null;
}
}
Tree elementTree = ctx.getCompilationInfo().getTrees().getTree(attrib.getJavaElement());
Utilities.TextSpan underlineSpan = Utilities.getUnderlineSpan(
ctx.getCompilationInfo(), elementTree);
ErrorDescription error = ErrorDescriptionFactory.forSpan(
hc,
underlineSpan.getStartOffset(),
underlineSpan.getEndOffset(),
NbBundle.getMessage(ValidVersionType.class, "MSG_InvalidVersionType"));//TODO: may need to have "error" fo some/ warning for another
return Collections.singleton(error);
}
return null;
}
示例11: isSameRawType
import javax.lang.model.util.Types; //導入方法依賴的package包/類
public boolean isSameRawType(TypeMirror type1, String type2ElementName) {
TypeElement type2Element = getCompilationInfo().getElements().getTypeElement(type2ElementName);
if (type2Element != null) {
Types types = getCompilationInfo().getTypes();
TypeMirror type2 = types.erasure(type2Element.asType());
return types.isSameType(types.erasure(type1), type2);
}
return false;
}
示例12: getMatchingMirror
import javax.lang.model.util.Types; //導入方法依賴的package包/類
static AnnotationMirror getMatchingMirror(TypeMirror serviceAnnotationMirror,
List<? extends AnnotationMirror> mirrors,
Types t) {
for (AnnotationMirror mirror : mirrors) {
if (t.isSameType(mirror.getAnnotationType().asElement().asType(), serviceAnnotationMirror)) {
return mirror;
}
}
return null;
}
示例13: isSameType
import javax.lang.model.util.Types; //導入方法依賴的package包/類
private boolean isSameType(TypeMirror t1, TypeMirror t2, Types types) {
if (types.isSameType(t1, t2)) {
return true;
}
if (t1.getKind().isPrimitive() && types.isSameType(types.boxedClass((PrimitiveType)t1).asType(), t2)) {
return true;
}
return t2.getKind().isPrimitive() && types.isSameType(t1, types.boxedClass((PrimitiveType)t1).asType());
}
示例14: getOtherSideOfRelation
import javax.lang.model.util.Types; //導入方法依賴的package包/類
public static ExecutableElement getOtherSideOfRelation(CompilationController controller, ExecutableElement executableElement, boolean isFieldAccess) {
TypeMirror passedReturnType = executableElement.getReturnType();
if (TypeKind.DECLARED != passedReturnType.getKind() || !(passedReturnType instanceof DeclaredType)) {
return null;
}
Types types = controller.getTypes();
TypeMirror passedReturnTypeStripped = stripCollection((DeclaredType)passedReturnType, types);
if (passedReturnTypeStripped == null) {
return null;
}
TypeElement passedReturnTypeStrippedElement = (TypeElement) types.asElement(passedReturnTypeStripped);
//try to find a mappedBy annotation element on the possiblyAnnotatedElement
Element possiblyAnnotatedElement = isFieldAccess ? JpaControllerUtil.guessField(executableElement) : executableElement;
String mappedBy = null;
AnnotationMirror persistenceAnnotation = JpaControllerUtil.findAnnotation(possiblyAnnotatedElement, "javax.persistence.OneToOne"); //NOI18N"
if (persistenceAnnotation == null) {
persistenceAnnotation = JpaControllerUtil.findAnnotation(possiblyAnnotatedElement, "javax.persistence.OneToMany"); //NOI18N"
}
if (persistenceAnnotation == null) {
persistenceAnnotation = JpaControllerUtil.findAnnotation(possiblyAnnotatedElement, "javax.persistence.ManyToOne"); //NOI18N"
}
if (persistenceAnnotation == null) {
persistenceAnnotation = JpaControllerUtil.findAnnotation(possiblyAnnotatedElement, "javax.persistence.ManyToMany"); //NOI18N"
}
if (persistenceAnnotation != null) {
mappedBy = JpaControllerUtil.findAnnotationValueAsString(persistenceAnnotation, "mappedBy"); //NOI18N
}
for (ExecutableElement method : JpaControllerUtil.getEntityMethods(passedReturnTypeStrippedElement)) {
if (mappedBy != null && mappedBy.length() > 0) {
String tail = mappedBy.length() > 1 ? mappedBy.substring(1) : "";
String getterName = "get" + mappedBy.substring(0,1).toUpperCase() + tail;
if (getterName.equals(method.getSimpleName().toString())) {
return method;
}
}
else {
TypeMirror iteratedReturnType = method.getReturnType();
iteratedReturnType = stripCollection(iteratedReturnType, types);
TypeMirror executableElementEnclosingType = executableElement.getEnclosingElement().asType();
if (types.isSameType(executableElementEnclosingType, iteratedReturnType)) {
return method;
}
}
}
return null;
}
示例15: createBindings
import javax.lang.model.util.Types; //導入方法依賴的package包/類
private Map<String, Object> createBindings(TypeElement clazz, ExecutableElement element) {
CodeStyle cs = DiffContext.getCodeStyle(copy);
Map<String, Object> bindings = new HashMap<>();
if (clazz != null) {
bindings.put(CLASS_NAME, clazz.getQualifiedName().toString());
bindings.put(SIMPLE_CLASS_NAME, clazz.getSimpleName().toString());
}
if (element != null) {
bindings.put(METHOD_NAME, element.getSimpleName().toString());
bindings.put(METHOD_RETURN_TYPE, element.getReturnType().toString()); //NOI18N
Object value;
switch(element.getReturnType().getKind()) {
case BOOLEAN:
value = "false"; //NOI18N
break;
case BYTE:
case CHAR:
case DOUBLE:
case FLOAT:
case INT:
case LONG:
case SHORT:
value = 0;
break;
default:
value = "null"; //NOI18N
}
bindings.put(DEFAULT_RETURN_TYPE_VALUE, value);
}
if (clazz != null && element != null) {
StringBuilder sb = new StringBuilder();
if (element.isDefault() && element.getEnclosingElement().getKind().isInterface()) {
Types types = copy.getTypes();
Context ctx = ((JavacTaskImpl) copy.impl.getJavacTask()).getContext();
com.sun.tools.javac.code.Types typesImpl = com.sun.tools.javac.code.Types.instance(ctx);
TypeMirror enclType = typesImpl.asSuper((Type)clazz.asType(), ((Type)element.getEnclosingElement().asType()).tsym);
if (!types.isSubtype(clazz.getSuperclass(), enclType)) {
TypeMirror selected = enclType;
for (TypeMirror iface : clazz.getInterfaces()) {
if (types.isSubtype(iface, selected) &&
!types.isSameType(iface, enclType)) {
selected = iface;
break;
}
}
sb.append(((DeclaredType)selected).asElement().getSimpleName()).append('.');
}
}
sb.append("super.").append(element.getSimpleName()).append('('); //NOI18N
for (Iterator<? extends VariableElement> it = element.getParameters().iterator(); it.hasNext();) {
VariableElement ve = it.next();
sb.append(addParamPrefixSuffix(removeParamPrefixSuffix(ve, cs), cs));
if (it.hasNext())
sb.append(","); //NOI18N
}
sb.append(')'); //NOI18N
bindings.put(SUPER_METHOD_CALL, sb);
}
return bindings;
}