protected Set<TypeElement> getElements( Collection<TypeMirror> types , CompilationInfo info ) { Set<TypeElement> result = new HashSet<TypeElement>(); for (TypeMirror typeMirror : types) { Element element = info.getTypes().asElement(typeMirror); if ( element instanceof TypeElement ){ result.add( (TypeElement)element); } } return result; }
protected boolean hasBeanType( Element subject, TypeMirror elementType, TypeMirror requiredBeanType,CompilationInfo compInfo ) { return compInfo.getTypes().isSubtype(elementType, requiredBeanType); }
@Override protected boolean hasBeanType( Element subject, TypeMirror returnType, TypeMirror requiredBeanType, CompilationInfo compInfo ) { return compInfo.getTypes().isSubtype(returnType, requiredBeanType); }
private boolean isSameTypeForVariableRemap(TypeMirror nodeType, TypeMirror pType) { //TODO: subtypes could be OK for remap? return info.getTypes().isSameType(nodeType, pType); }
private boolean matchTypes(CompilationInfo cinfo, List<? extends VariableElement> varElems, List<? extends TypeMirror> paramTypes) { if(varElems.size() == paramTypes.size()) { ListIterator<? extends VariableElement> elemsIter = varElems.listIterator(); ListIterator<? extends TypeMirror> typesIter = paramTypes.listIterator(); while(elemsIter.hasNext()) { if(!cinfo.getTypes().isSameType(elemsIter.next().asType(), typesIter.next())) { return false; } } return true; } return false; }
private String getSuperTypeClassName(TypeElement classElement, CompilationInfo ci) { String superClassName = null; TypeMirror superclass = classElement.getSuperclass(); if (superclass != null) { Element superclassElement = ci.getTypes().asElement(superclass); if ((superclassElement != null) && (superclassElement.getKind() == ElementKind.CLASS)) { String superclassName = ElementUtilities.getBinaryName((TypeElement) superclassElement); if (!superclassName.equals("java.lang.Object")) { superClassName = superclassName; } } } return superClassName; }
private void addAncestor( TypeMirror parent , Set<TypeElement> ancestors, CompilationInfo compInfo) { if ( parent == null ){ return; } Element parentElement = compInfo.getTypes().asElement( parent ); if ( parentElement instanceof TypeElement ){ if ( ancestors.contains( (TypeElement)parentElement)) { return; } ancestors.add( (TypeElement)parentElement); collectAncestors((TypeElement)parentElement, ancestors, compInfo); } }
private String getInterfaceNames(TypeElement classElement, CompilationInfo ci) { String ifcNames = null; List<? extends TypeMirror> ifcs = classElement.getInterfaces(); if (ifcs != null) { StringBuilder sb = new StringBuilder(); boolean firstRun = true; for (TypeMirror ifc : ifcs) { Element superclassElement = ci.getTypes().asElement(ifc); if ((superclassElement != null) && (superclassElement.getKind() == ElementKind.INTERFACE)) { if (!firstRun) { sb.append(", "); } sb.append(ElementUtilities.getBinaryName((TypeElement) superclassElement)); } } ifcNames = sb.toString(); } return ifcNames; }
/** Detects static final long SerialVersionUID * @return true if element is final static long serialVersionUID */ private static boolean isSerialSpecField(CompilationInfo info, Element el) { if (el.getModifiers().contains(Modifier.FINAL) && el.getModifiers().contains(Modifier.STATIC)) { if (!isInSerializableOrExternalizable(info, el)) { return false; } if (info.getTypes().getPrimitiveType(TypeKind.LONG).equals(el.asType()) && el.getSimpleName().toString().equals("serialVersionUID")) { return true; } if (el.getSimpleName().contentEquals("serialPersistentFields")) { return true; } } return false; }
public Object run(CompilationInfo cinfo) { TypeElement typeElement = typeElementHandle.resolve(cinfo); TypeMirror superType = cinfo.getElements().getTypeElement(typeName).asType(); if(superType.getKind() == TypeKind.DECLARED && cinfo.getTypes().isSubtype(typeElement.asType(), superType)) { return Boolean.TRUE; } return Boolean.FALSE; } }, fObj);
private static void collectDecoratedTypes( TypeMirror type, Collection<TypeMirror> result, TypeElement serializable, CompilationInfo info) { List<? extends TypeMirror> directSupertypes = info.getTypes(). directSupertypes(type); for (TypeMirror superType : directSupertypes) { Element element = info.getTypes().asElement(superType); if( element == null || element.equals( serializable) ) { continue; } if ( element.getKind() == ElementKind.INTERFACE ){ result.add( superType ); } collectDecoratedTypes(superType, result, serializable, info); } }
private boolean matchType(CompilationInfo cinfo, TypeMirror type, Class cls) { String typeName = type.toString(); //Use the raw type if the type represents paramaterized type TypeMirror compType = type; if(type.getKind() == TypeKind.ARRAY) { compType = ((ArrayType)type).getComponentType(); } if(isParameterizedType(compType)) { typeName = cinfo.getTypes().erasure(type).toString(); } if(cls.getCanonicalName().equals(typeName)) { return true; } return false; }
@Override public void analyze( Element element, TypeElement parent, AtomicBoolean cancel, CdiAnalysisResult result ) { VariableElement var = (VariableElement) element; TypeMirror varType = result.getInfo().getTypes().asMemberOf( (DeclaredType)parent.asType(), var ); for (FieldAnalyzer analyzer : ANALYZERS) { if ( cancel.get()){ return; } analyzer.analyze(var, varType, parent, cancel, result ); } }
public Void visitMethod(MethodTree node, Set<TypeMirror> p) { Set<TypeMirror> s = new LinkedHashSet<TypeMirror>(); scan(node.getBody(), s); for (ExpressionTree et : node.getThrows()) { TypeMirror t = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), et)); if (t != null && t.getKind() != TypeKind.ERROR) { for (Iterator<TypeMirror> it = s.iterator(); it.hasNext();) if (info.getTypes().isSubtype(it.next(), t)) it.remove(); } } p.addAll(s); return null; }
/** * Check whether given type has a setter method for the given field. * @param type to inspect * @param field to search setter for * @param codeStyle * @return true if setter method exists * * @since 0.136 */ public boolean hasSetter(TypeElement type, VariableElement field, CodeStyle codeStyle) { boolean isStatic = field.getModifiers().contains(Modifier.STATIC); String name = CodeStyleUtils.computeSetterName(field.getSimpleName(), isStatic, codeStyle); return delegate.alreadyDefinedIn(name, info.getTypes().getNoType(TypeKind.VOID), com.sun.tools.javac.util.List.<TypeMirror>of(field.asType()), type); }
/**Returns uncaught exceptions inside the given tree path. */ public Set<TypeMirror> getUncaughtExceptions(TreePath path) { Set<TypeMirror> set = new UnrelatedTypeMirrorSet(info.getTypes()); new UncaughtExceptionsVisitor(info).scan(path, set); return set; }
private void checkDelegateType( VariableElement element, int i, ExecutableElement method, TypeElement parent, CdiAnalysisResult result ) { ExecutableType methodType = (ExecutableType) result.getInfo().getTypes() .asMemberOf((DeclaredType) parent.asType(), method); List<? extends TypeMirror> parameterTypes = methodType .getParameterTypes(); TypeMirror parameterType = parameterTypes.get(i); Collection<TypeMirror> decoratedTypes = DelegateFieldAnalizer .getDecoratedTypes(parent, result.getInfo()); for (TypeMirror decoratedType : decoratedTypes) { if (!result.getInfo().getTypes().isSubtype(parameterType, decoratedType)) { result.addError(element, NbBundle.getMessage( DelegateMethodAnalyzer.class, "ERR_DelegateTypeHasNoDecoratedType")); // NOI18N return; } } }
private void checkDelegateType( VariableElement element, TypeMirror elementType, TypeElement parent, CdiAnalysisResult result ) { Collection<TypeMirror> decoratedTypes = getDecoratedTypes( parent , result.getInfo() ); for (TypeMirror decoratedType : decoratedTypes) { if ( !result.getInfo().getTypes().isSubtype( elementType,decoratedType )){ result.addError(element, NbBundle.getMessage( DelegateFieldAnalizer.class, "ERR_DelegateTypeHasNoDecoratedType")); // NOI18N return; } } }
private DeclaredType findCommonSubtype(DeclaredType type1, DeclaredType type2, Env<AttrContext> env) { List<DeclaredType> subtypes1 = getSubtypes(type1, env); List<DeclaredType> subtypes2 = getSubtypes(type2, env); if (subtypes1 == null || subtypes2 == null) return null; Types types = info.getTypes(); for (DeclaredType subtype1 : subtypes1) { for (DeclaredType subtype2 : subtypes2) { if (types.isSubtype(subtype1, subtype2)) return subtype1; if (types.isSubtype(subtype2, subtype1)) return subtype2; } } return null; }
public static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to) { Context c = ((JavacTaskImpl) info.impl.getJavacTask()).getContext(); if (from.getKind() == TypeKind.TYPEVAR) { Types types = Types.instance(c); TypeVar t = types.substBound((TypeVar)from, com.sun.tools.javac.util.List.of((Type)from), com.sun.tools.javac.util.List.of(types.boxedTypeOrType((Type)to))); return info.getTypes().isAssignable(t.getUpperBound(), to) || info.getTypes().isAssignable(to, t.getUpperBound()); } if (from.getKind() == TypeKind.WILDCARD) { from = Types.instance(c).wildUpperBound((Type)from); } return Check.instance(c).checkType(null, (Type)from, (Type)to).getKind() != TypeKind.ERROR; }