/** * In no classpath, the model of the super interface isn't always correct. */ private boolean isCorrectTypeReference(TypeReference ref) { if (ref.resolvedType == null) { return false; } if (!(ref.resolvedType instanceof ProblemReferenceBinding)) { return true; } final String[] compoundName = CharOperation.charArrayToStringArray(((ProblemReferenceBinding) ref.resolvedType).compoundName); final String[] typeName = CharOperation.charArrayToStringArray(ref.getTypeName()); if (compoundName.length == 0 || typeName.length == 0) { return false; } return compoundName[compoundName.length - 1].equals(typeName[typeName.length - 1]); }
String oName = new String(out[idx].type.getLastToken()); boolean found = false; for (IAnnotation i : in) {
public TypeBinding resolveType(BlockScope scope, boolean checkBounds, int location) { if (this.bound != null) { this.bound.resolveType(scope, checkBounds, Binding.DefaultLocationTypeBound); this.bits |= (this.bound.bits & ASTNode.HasTypeAnnotations); } return null; } // only invoked for improving resilience when unable to bind generic type from parameterized reference
for (int position = type.getTypeName().length - 1; position >= 0; position--) { if (currentReference == null) { break; if (type.getTypeArguments() != null && type.getTypeArguments().length - 1 <= position && type.getTypeArguments()[position] != null && type.getTypeArguments()[position].length > 0) { CtTypeReference<?> componentReference = getTypeReferenceOfArrayComponent(currentReference); componentReference.getActualTypeArguments().clear(); for (TypeReference typeArgument : type.getTypeArguments()[position]) { if (typeArgument instanceof Wildcard || typeArgument.resolvedType instanceof WildcardBinding || typeArgument.resolvedType instanceof TypeVariableBinding) { componentReference.addActualTypeArgument(buildTypeParameterReference(typeArgument, scope)); && !isTypeArgumentExplicit(type.getTypeArguments())) { for (CtTypeReference<?> actualTypeArgument : currentReference.getActualTypeArguments()) { actualTypeArgument.setImplicit(true);
final String[] namesParameterized = CharOperation.charArrayToStringArray(ref.getParameterizedTypeName()); String nameParameterized = CharOperation.toString(ref.getParameterizedTypeName()); String typeName = CharOperation.toString(ref.getTypeName());
private ReferenceBinding findSupertype(TypeReference typeReference) { CompilationUnitScope unitScope = compilationUnitScope(); LookupEnvironment env = unitScope.environment; try { env.missingClassFileLocation = typeReference; typeReference.aboutToResolve(this); // allows us to trap completion & selection nodes unitScope.recordQualifiedReference(typeReference.getTypeName()); this.superTypeReference = typeReference; ReferenceBinding superType = (ReferenceBinding) typeReference.resolveSuperType(this); return superType; } catch (AbortCompilation e) { SourceTypeBinding sourceType = this.referenceContext.binding; if (sourceType.superInterfaces == null) sourceType.superInterfaces = Binding.NO_SUPERINTERFACES; // be more resilient for hierarchies (144976) e.updateContext(typeReference, referenceCompilationUnit().compilationResult); throw e; } finally { env.missingClassFileLocation = null; this.superTypeReference = null; } }
/** * Checks if the given type reference represents a primitive type. */ public static boolean isPrimitive(TypeReference ref) { if (ref.dimensions() > 0) return false; return PRIMITIVE_TYPE_NAME_PATTERN.matcher(toQualifiedName(ref.getTypeName())).matches(); }
public TypeBinding resolveSuperType(ClassScope scope) { // assumes the implementation of resolveType(ClassScope) will call back to detect cycles TypeBinding superType = resolveType(scope); if (superType == null) return null; if (superType.isTypeVariable()) { if (this.resolvedType.isValidBinding()) { this.resolvedType = new ProblemReferenceBinding(getTypeName(), (ReferenceBinding)this.resolvedType, ProblemReasons.IllegalSuperTypeVariable); reportInvalidType(scope); } return null; } return superType; }
public void getAllAnnotationContexts(int targetType, List allAnnotationContexts) { AnnotationCollector collector = new AnnotationCollector(this, targetType, allAnnotationContexts); this.traverse(collector, (BlockScope) null); } public Annotation[][] getAnnotationsOnDimensions() {
final TypeDefinition resolvedType = targetType.resolve(); final MethodDefinition mainMethod = resolvedType.getDeclaredMethods().get(1); final MethodDefinition getTextMethod = resolvedType.getDeclaredMethods().get(2);
CtTypeReference<Object> getTypeParameterReference(TypeBinding binding, TypeReference ref) { CtTypeReference<Object> ctRef = getTypeReference(binding); if (ctRef != null && isCorrectTypeReference(ref)) { if (!(ctRef instanceof CtTypeParameterReference)) { CtTypeParameterReference typeParameterRef = this.jdtTreeBuilder.getFactory().Core().createTypeParameterReference(); typeParameterRef.setSimpleName(ctRef.getSimpleName()); typeParameterRef.setDeclaringType(ctRef.getDeclaringType()); typeParameterRef.setPackage(ctRef.getPackage()); ctRef = typeParameterRef; } insertGenericTypesInNoClasspathFromJDTInSpoon(ref, ctRef); return ctRef; } return getTypeParameterReference(CharOperation.toString(ref.getParameterizedTypeName())); }
public void checkBounds(Scope scope) { if (this.type != null) { this.type.checkBounds(scope); } if (this.bounds != null) { for (int i = 0, length = this.bounds.length; i < length; i++) { this.bounds[i].checkBounds(scope); } } }
public static final TypeReference baseTypeReference(int baseType, int dim) { return baseTypeReference(baseType, dim, null); }
private void formatLeadingDimensions(TypeReference typeReference) { int leadingDimensions = Math.min(getDimensions(), typeReference != null ? typeReference.dimensions() : 0); if (leadingDimensions != 0) formatDimensions(typeReference, 0, leadingDimensions); }
private ReferenceBinding findSupertype(TypeReference typeReference) { CompilationUnitScope unitScope = compilationUnitScope(); LookupEnvironment env = unitScope.environment; try { env.missingClassFileLocation = typeReference; typeReference.aboutToResolve(this); // allows us to trap completion & selection nodes unitScope.recordQualifiedReference(typeReference.getTypeName()); this.superTypeReference = typeReference; ReferenceBinding superType = (ReferenceBinding) typeReference.resolveSuperType(this); return superType; } catch (AbortCompilation e) { SourceTypeBinding sourceType = this.referenceContext.binding; if (sourceType.superInterfaces == null) sourceType.superInterfaces = Binding.NO_SUPERINTERFACES; // be more resilient for hierarchies (144976) e.updateContext(typeReference, referenceCompilationUnit().compilationResult); throw e; } finally { env.missingClassFileLocation = null; this.superTypeReference = null; } }
private static char[] getTypeName(TypeReference typeReference) { char[] typeName = CharOperation.concatWith(typeReference.getTypeName(), '.'); int dims = typeReference.dimensions(); if (dims > 0) { int length = typeName.length; int newLength = length + (dims*2); System.arraycopy(typeName, 0, typeName = new char[newLength], 0, length); for (int k = length; k < newLength; k += 2) { typeName[k] = '['; typeName[k+1] = ']'; } } return typeName; }
public void traverse( ASTVisitor visitor, ClassScope blockScope) { if (visitor.visit(this, blockScope)) { this.qualification.traverse(visitor, blockScope); } visitor.endVisit(this, blockScope); } }
typeRef.resolve(methScope); TypeBinding typeBinding = typeRef.resolvedType;
protected char[] getSuperclassName(TypeDeclaration typeDeclaration) { TypeReference superclass = typeDeclaration.superclass; return superclass != null ? CharOperation.concatWith(superclass.getParameterizedTypeName(), '.') : null; } protected char[][] getThrownExceptions(AbstractMethodDeclaration methodDeclaration) {
public void checkBounds(Scope scope) { if (this.type != null) { this.type.checkBounds(scope); } if (this.bounds != null) { for (int i = 0, length = this.bounds.length; i < length; i++) { this.bounds[i].checkBounds(scope); } } }