org.eclipse.jdt.internal.compiler.ast.TypeParameter Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.TypeParameter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void buildTypeVariables() {

	    SourceTypeBinding sourceType = this.referenceContext.binding;
		TypeParameter[] typeParameters = this.referenceContext.typeParameters;
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, If they exist at all, process type parameters irrespective of source level.
		if (typeParameters == null || typeParameters.length == 0) {
		    sourceType.setTypeVariables(Binding.NO_TYPE_VARIABLES);
		    return;
		}
		sourceType.setTypeVariables(Binding.NO_TYPE_VARIABLES); // safety

		if (sourceType.id == TypeIds.T_JavaLangObject) { // handle the case of redefining java.lang.Object up front
			problemReporter().objectCannotBeGeneric(this.referenceContext);
			return;
		}
		sourceType.setTypeVariables(createTypeVariables(typeParameters, sourceType));
		sourceType.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
	}
 
Example #2
Source File: RecoveredMethod.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
void attach(TypeParameter[] parameters, int startPos) {
	if(this.methodDeclaration.modifiers != ClassFileConstants.AccDefault) return;

	int lastParameterEnd = parameters[parameters.length - 1].sourceEnd;

	Parser parser = parser();
	Scanner scanner = parser.scanner;
	if(Util.getLineNumber(this.methodDeclaration.declarationSourceStart, scanner.lineEnds, 0, scanner.linePtr)
			!= Util.getLineNumber(lastParameterEnd, scanner.lineEnds, 0, scanner.linePtr)) return;

	if(parser.modifiersSourceStart > lastParameterEnd
			&& parser.modifiersSourceStart < this.methodDeclaration.declarationSourceStart) return;

	if (this.methodDeclaration instanceof MethodDeclaration) {
		((MethodDeclaration)this.methodDeclaration).typeParameters = parameters;
		this.methodDeclaration.declarationSourceStart = startPos;
	} else if (this.methodDeclaration instanceof ConstructorDeclaration){
		((ConstructorDeclaration)this.methodDeclaration).typeParameters = parameters;
		this.methodDeclaration.declarationSourceStart = startPos;
	}
}
 
Example #3
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
public static TypeReference cloneSelfType(EclipseNode context, ASTNode source) {
	int pS = source == null ? 0 : source.sourceStart, pE = source == null ? 0 : source.sourceEnd;
	long p = (long)pS << 32 | pE;
	EclipseNode type = context;
	TypeReference result = null;
	while (type != null && type.getKind() != Kind.TYPE) type = type.up();
	if (type != null && type.get() instanceof TypeDeclaration) {
		TypeDeclaration typeDecl = (TypeDeclaration) type.get();
		if (typeDecl.typeParameters != null && typeDecl.typeParameters.length > 0) {
			TypeReference[] refs = new TypeReference[typeDecl.typeParameters.length];
			int idx = 0;
			for (TypeParameter param : typeDecl.typeParameters) {
				TypeReference typeRef = new SingleTypeReference(param.name, (long)param.sourceStart << 32 | param.sourceEnd);
				if (source != null) setGeneratedBy(typeRef, source);
				refs[idx++] = typeRef;
			}
			result = new ParameterizedSingleTypeReference(typeDecl.name, refs, 0, p);
		} else {
			result = new SingleTypeReference(((TypeDeclaration)type.get()).name, p);
		}
	}
	if (result != null && source != null) setGeneratedBy(result, source);
	return result;
}
 
Example #4
Source File: HandleBuilder.java    From EasyMPermission with MIT License 6 votes vote down vote up
public MethodDeclaration generateBuilderMethod(String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) {
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long) pS << 32 | pE;
	
	MethodDeclaration out = new MethodDeclaration(
			((CompilationUnitDeclaration) type.top().get()).compilationResult);
	out.selector = builderMethodName.toCharArray();
	out.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic;
	out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
	out.typeParameters = copyTypeParams(typeParams, source);
	AllocationExpression invoke = new AllocationExpression();
	invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
	out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)};
	
	out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
	return out;
}
 
Example #5
Source File: SourceElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private TypeParameterInfo[] getTypeParameterInfos(TypeParameter[] typeParameters) {
	if (typeParameters == null) return null;
	int typeParametersLength = typeParameters.length;
	TypeParameterInfo[] result = new TypeParameterInfo[typeParametersLength];
	for (int i = 0; i < typeParametersLength; i++) {
		TypeParameter typeParameter = typeParameters[i];
		char[][] typeParameterBounds = getTypeParameterBounds(typeParameter);
		ISourceElementRequestor.TypeParameterInfo typeParameterInfo = new ISourceElementRequestor.TypeParameterInfo();
		typeParameterInfo.declarationStart = typeParameter.declarationSourceStart;
		typeParameterInfo.declarationEnd = typeParameter.declarationSourceEnd;
		typeParameterInfo.name = typeParameter.name;
		typeParameterInfo.nameSourceStart = typeParameter.sourceStart;
		typeParameterInfo.nameSourceEnd = typeParameter.sourceEnd;
		typeParameterInfo.bounds = typeParameterBounds;
		result[i] = typeParameterInfo;
	}
	return result;
}
 
Example #6
Source File: SourceElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected char[][] getTypeParameterBounds(TypeParameter typeParameter) {
	TypeReference firstBound = typeParameter.type;
	TypeReference[] otherBounds = typeParameter.bounds;
	char[][] typeParameterBounds = null;
	if (firstBound != null) {
		if (otherBounds != null) {
			int otherBoundsLength = otherBounds.length;
			char[][] boundNames = new char[otherBoundsLength+1][];
			boundNames[0] = CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.');
			for (int j = 0; j < otherBoundsLength; j++) {
				boundNames[j+1] =
					CharOperation.concatWith(otherBounds[j].getParameterizedTypeName(), '.');
			}
			typeParameterBounds = boundNames;
		} else {
			typeParameterBounds = new char[][] { CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.')};
		}
	} else {
		typeParameterBounds = CharOperation.NO_CHAR_CHAR;
	}

	return typeParameterBounds;
}
 
Example #7
Source File: TypeConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected TypeParameter createTypeParameter(char[] typeParameterName, char[][] typeParameterBounds, int start, int end) {

		TypeParameter parameter = new TypeParameter();
		parameter.name = typeParameterName;
		parameter.sourceStart = start;
		parameter.sourceEnd = end;
		if (typeParameterBounds != null) {
			int length = typeParameterBounds.length;
			if (length > 0) {
				parameter.type = createTypeReference(typeParameterBounds[0], start, end);
				if (length > 1) {
					parameter.bounds = new TypeReference[length-1];
					for (int i = 1; i < length; i++) {
						TypeReference bound = createTypeReference(typeParameterBounds[i], start, end);
						bound.bits |= ASTNode.IsSuperType;
						parameter.bounds[i-1] = bound;
					}
				}
			}
		}
		return parameter;
	}
 
Example #8
Source File: CompletionOnMethodTypeParameter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public CompletionOnMethodTypeParameter(TypeParameter[] typeParameters, CompilationResult compilationResult){
	super(compilationResult);
	this.selector = CharOperation.NO_CHAR;
	this.typeParameters = typeParameters;
	this.sourceStart = typeParameters[0].sourceStart;
	this.sourceEnd = typeParameters[typeParameters.length - 1].sourceEnd;
}
 
Example #9
Source File: TypeVariableBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private TypeReference findBound(TypeBinding bound, TypeParameter parameter) {
	if (parameter.type != null && TypeBinding.equalsEquals(parameter.type.resolvedType, bound))
		return parameter.type;
	TypeReference[] bounds = parameter.bounds;
	if (bounds != null) {
		for (int i = 0; i < bounds.length; i++) {
			if (TypeBinding.equalsEquals(bounds[i].resolvedType, bound))
				return bounds[i];
		}
	}
	return null;
}
 
Example #10
Source File: AndLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int match(TypeParameter node, MatchingNodeSet nodeSet) {
	int level = IMPOSSIBLE_MATCH;
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
		int newLevel = this.patternLocators[i].match(node, nodeSet);
		if (newLevel > level) {
			if (newLevel == ACCURATE_MATCH) return ACCURATE_MATCH;
			level = newLevel;
		}
	}
	return level;
}
 
Example #11
Source File: OrLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int match(TypeParameter node, MatchingNodeSet nodeSet) {
	int level = IMPOSSIBLE_MATCH;
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
		int newLevel = this.patternLocators[i].match(node, nodeSet);
		if (newLevel > level) {
			if (newLevel == ACCURATE_MATCH) return ACCURATE_MATCH;
			level = newLevel;
		}
	}
	return level;
}
 
Example #12
Source File: CompletionElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected char[][] getTypeParameterBounds(TypeParameter typeParameter) {
	TypeReference firstBound = typeParameter.type;
	TypeReference[] otherBounds = typeParameter.bounds;
	char[][] typeParameterBounds = null;
	if (firstBound != null) {
		if (otherBounds != null) {
			int otherBoundsLength = otherBounds.length;
			char[][] boundNames = new char[otherBoundsLength+1][];
			int boundCount = 0;
			if (!CompletionUnitStructureRequestor.hasEmptyName(firstBound, this.assistNode)) {
				boundNames[boundCount++] = CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.');
			}
			for (int j = 0; j < otherBoundsLength; j++) {
				TypeReference otherBound = otherBounds[j];
				if (!CompletionUnitStructureRequestor.hasEmptyName(otherBound, this.assistNode)) {
					boundNames[boundCount++] =
						CharOperation.concatWith(otherBound.getParameterizedTypeName(), '.');
				}
			}

			if (boundCount == 0) {
				boundNames = CharOperation.NO_CHAR_CHAR;
			} else if (boundCount < otherBoundsLength + 1){
				System.arraycopy(boundNames, 0, boundNames = new char[boundCount][], 0, boundCount);
			}
			typeParameterBounds = boundNames;
		} else {
			if (!CompletionUnitStructureRequestor.hasEmptyName(firstBound, this.assistNode)) {
				typeParameterBounds = new char[][] { CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.')};
			} else {
				typeParameterBounds = CharOperation.NO_CHAR_CHAR;
			}
		}
	} else {
		typeParameterBounds = CharOperation.NO_CHAR_CHAR;
	}

	return typeParameterBounds;
}
 
Example #13
Source File: JavaDerivedStateComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmDeclaredType createType(TypeDeclaration type, String packageName) {
	JvmDeclaredType jvmType = null;
	switch (TypeDeclaration.kind(type.modifiers)) {
	case TypeDeclaration.CLASS_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmGenericType();
		break;
	case TypeDeclaration.INTERFACE_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmGenericType();
		((JvmGenericType) jvmType).setInterface(true);
		break;
	case TypeDeclaration.ENUM_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmEnumerationType();
		break;
	case TypeDeclaration.ANNOTATION_TYPE_DECL:
		jvmType = TypesFactory.eINSTANCE.createJvmAnnotationType();
		break;
	default:
		throw new IllegalArgumentException("Cannot handle type " + type.toString());
	}
	jvmType.setPackageName(packageName);
	jvmType.setSimpleName(String.valueOf(type.name));
	if (jvmType instanceof JvmGenericType) {
		if (type.typeParameters != null) {
			for (TypeParameter typeParam : type.typeParameters) {
				JvmTypeParameter jvmTypeParam = TypesFactory.eINSTANCE.createJvmTypeParameter();
				jvmTypeParam.setName(String.valueOf(typeParam.name));
				((JvmGenericType) jvmType).getTypeParameters().add(jvmTypeParam);
			}
		}
	}
	if (type.memberTypes != null) {
		for (TypeDeclaration nestedType : type.memberTypes) {
			JvmDeclaredType nested = createType(nestedType, null);
			jvmType.getMembers().add(nested);
		}
	}
	return jvmType;
}
 
Example #14
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
	Annotation[] annotations = methodDeclaration.annotations;
	if (annotations != null) {
		MethodBinding methodBinding = methodDeclaration.binding;
		if (methodBinding == null) {
			return false;
		}
		((SourceTypeBinding) methodBinding.declaringClass).resolveTypesFor(methodBinding);
		this.resolveAnnotations(
				methodDeclaration.scope,
				annotations,
				methodBinding);
	}
	
	TypeParameter[] typeParameters = methodDeclaration.typeParameters;
	if (typeParameters != null) {
		int typeParametersLength = typeParameters.length;
		for (int i = 0; i < typeParametersLength; i++) {
			typeParameters[i].traverse(this, methodDeclaration.scope);
		}
	}
	
	Argument[] arguments = methodDeclaration.arguments;
	if (arguments != null) {
		int argumentLength = arguments.length;
		for (int i = 0; i < argumentLength; i++) {
			arguments[i].traverse(this, methodDeclaration.scope);
		}
	}
	return false;
}
 
Example #15
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(TypeParameter typeParameter, BlockScope scope) {
	Annotation[] annotations = typeParameter.annotations;
	if (annotations != null) {
		TypeVariableBinding binding = typeParameter.binding;
		if (binding == null) {
			return false;
		}
		// when we get here, it is guaranteed that class type parameters are connected, but method type parameters may not be.			
		MethodBinding methodBinding = (MethodBinding) binding.declaringElement;
		((SourceTypeBinding) methodBinding.declaringClass).resolveTypesFor(methodBinding);
		this.resolveAnnotations(scope, annotations, binding);
	}
	return false;
}
 
Example #16
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(TypeParameter typeParameter, ClassScope scope) {
	Annotation[] annotations = typeParameter.annotations;
	if (annotations != null) {
		TypeVariableBinding binding = typeParameter.binding;
		if (binding == null) {
			return false;
		}
		this.resolveAnnotations(scope.referenceContext.initializerScope, annotations, binding);
	}
	return false;
}
 
Example #17
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) {
	Annotation[] annotations = constructorDeclaration.annotations;
	if (annotations != null) {
		MethodBinding constructorBinding = constructorDeclaration.binding;
		if (constructorBinding == null) {
			return false;
		}
		((SourceTypeBinding) constructorBinding.declaringClass).resolveTypesFor(constructorBinding);
		this.resolveAnnotations(
				constructorDeclaration.scope,
				annotations,
				constructorBinding);
	}
	
	TypeParameter[] typeParameters = constructorDeclaration.typeParameters;
	if (typeParameters != null) {
		int typeParametersLength = typeParameters.length;
		for (int i = 0; i < typeParametersLength; i++) {
			typeParameters[i].traverse(this, constructorDeclaration.scope);
		}
	}
	
	Argument[] arguments = constructorDeclaration.arguments;
	if (arguments != null) {
		int argumentLength = arguments.length;
		for (int i = 0; i < argumentLength; i++) {
			arguments[i].traverse(this, constructorDeclaration.scope);
		}
	}
	return false;
}
 
Example #18
Source File: HandleBuilder.java    From EasyMPermission with MIT License 5 votes vote down vote up
public EclipseNode makeBuilderClass(EclipseNode tdParent, String builderClassName, TypeParameter[] typeParams, ASTNode source) {
	TypeDeclaration parent = (TypeDeclaration) tdParent.get();
	TypeDeclaration builder = new TypeDeclaration(parent.compilationResult);
	builder.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
	builder.modifiers |= ClassFileConstants.AccPublic | ClassFileConstants.AccStatic;
	builder.typeParameters = copyTypeParams(typeParams, source);
	builder.name = builderClassName.toCharArray();
	builder.traverse(new SetGeneratedByVisitor(source), (ClassScope) null);
	return injectType(tdParent, builder);
}
 
Example #19
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 5 votes vote down vote up
public static TypeReference namePlusTypeParamsToTypeReference(char[] typeName, TypeParameter[] params, long p) {
	if (params != null && params.length > 0) {
		TypeReference[] refs = new TypeReference[params.length];
		int idx = 0;
		for (TypeParameter param : params) {
			TypeReference typeRef = new SingleTypeReference(param.name, p);
			refs[idx++] = typeRef;
		}
		return new ParameterizedSingleTypeReference(typeName, refs, 0, p);
	}
	
	return new SingleTypeReference(typeName, p);
}
 
Example #20
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 5 votes vote down vote up
/**
 * You can't share TypeParameter objects or bad things happen; for example, one 'T' resolves differently
 * from another 'T', even for the same T in a single class file. Unfortunately the TypeParameter type hierarchy
 * is complicated and there's no clone method on TypeParameter itself. This method can clone them.
 */
public static TypeParameter[] copyTypeParams(TypeParameter[] params, ASTNode source) {
	if (params == null) return null;
	TypeParameter[] out = new TypeParameter[params.length];
	int idx = 0;
	for (TypeParameter param : params) {
		TypeParameter o = new TypeParameter();
		setGeneratedBy(o, source);
		o.annotations = param.annotations;
		o.bits = param.bits;
		o.modifiers = param.modifiers;
		o.name = param.name;
		o.type = copyType(param.type, source);
		o.sourceStart = param.sourceStart;
		o.sourceEnd = param.sourceEnd;
		o.declarationEnd = param.declarationEnd;
		o.declarationSourceStart = param.declarationSourceStart;
		o.declarationSourceEnd = param.declarationSourceEnd;
		if (param.bounds != null) {
			TypeReference[] b = new TypeReference[param.bounds.length];
			int idx2 = 0;
			for (TypeReference ref : param.bounds) b[idx2++] = copyType(ref, source);
			o.bounds = b;
		}
		out[idx++] = o;
	}
	return out;
}
 
Example #21
Source File: SetGeneratedByVisitor.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override public boolean visit(TypeParameter node, ClassScope scope) {
	fixPositions(setGeneratedBy(node, source));
	return super.visit(node, scope);
}
 
Example #22
Source File: SetGeneratedByVisitor.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override public boolean visit(TypeParameter node, BlockScope scope) {
	fixPositions(setGeneratedBy(node, source));
	return super.visit(node, scope);
}
 
Example #23
Source File: RecoveredType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void add(TypeParameter[] parameters, int startPos) {
	this.pendingTypeParameters = parameters;
	this.pendingTypeParametersStart = startPos;
}
 
Example #24
Source File: ClassScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
void resolveTypeParameter(TypeParameter typeParameter) {
	typeParameter.resolve(this);
}
 
Example #25
Source File: ClassScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void checkParameterizedSuperTypeCollisions() {
	// check for parameterized interface collisions (when different parameterizations occur)
	SourceTypeBinding sourceType = this.referenceContext.binding;
	ReferenceBinding[] interfaces = sourceType.superInterfaces;
	Map invocations = new HashMap(2);
	ReferenceBinding itsSuperclass = sourceType.isInterface() ? null : sourceType.superclass;
	nextInterface: for (int i = 0, length = interfaces.length; i < length; i++) {
		ReferenceBinding one =  interfaces[i];
		if (one == null) continue nextInterface;
		if (itsSuperclass != null && hasErasedCandidatesCollisions(itsSuperclass, one, invocations, sourceType, this.referenceContext))
			continue nextInterface;
		nextOtherInterface: for (int j = 0; j < i; j++) {
			ReferenceBinding two = interfaces[j];
			if (two == null) continue nextOtherInterface;
			if (hasErasedCandidatesCollisions(one, two, invocations, sourceType, this.referenceContext))
				continue nextInterface;
		}
	}

	TypeParameter[] typeParameters = this.referenceContext.typeParameters;
	nextVariable : for (int i = 0, paramLength = typeParameters == null ? 0 : typeParameters.length; i < paramLength; i++) {
		TypeParameter typeParameter = typeParameters[i];
		TypeVariableBinding typeVariable = typeParameter.binding;
		if (typeVariable == null || !typeVariable.isValidBinding()) continue nextVariable;

		TypeReference[] boundRefs = typeParameter.bounds;
		if (boundRefs != null) {
			boolean checkSuperclass = TypeBinding.equalsEquals(typeVariable.firstBound, typeVariable.superclass);
			for (int j = 0, boundLength = boundRefs.length; j < boundLength; j++) {
				TypeReference typeRef = boundRefs[j];
				TypeBinding superType = typeRef.resolvedType;
				if (superType == null || !superType.isValidBinding()) continue;

				// check against superclass
				if (checkSuperclass)
					if (hasErasedCandidatesCollisions(superType, typeVariable.superclass, invocations, typeVariable, typeRef))
						continue nextVariable;
				// check against superinterfaces
				for (int index = typeVariable.superInterfaces.length; --index >= 0;)
					if (hasErasedCandidatesCollisions(superType, typeVariable.superInterfaces[index], invocations, typeVariable, typeRef))
						continue nextVariable;
			}
		}
	}

	ReferenceBinding[] memberTypes = this.referenceContext.binding.memberTypes;
	if (memberTypes != null && memberTypes != Binding.NO_MEMBER_TYPES)
		for (int i = 0, size = memberTypes.length; i < size; i++)
			 ((SourceTypeBinding) memberTypes[i]).scope.checkParameterizedSuperTypeCollisions();
}
 
Example #26
Source File: MethodVerifier15.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
void checkTypeVariableMethods(TypeParameter typeParameter) {
	char[][] methodSelectors = this.inheritedMethods.keyTable;
	nextSelector : for (int s = methodSelectors.length; --s >= 0;) {
		if (methodSelectors[s] == null) continue nextSelector;
		MethodBinding[] inherited = (MethodBinding[]) this.inheritedMethods.valueTable[s];
		if (inherited.length == 1) continue nextSelector;

		int index = -1;
		MethodBinding[] matchingInherited = new MethodBinding[inherited.length];
		for (int i = 0, length = inherited.length; i < length; i++) {
			while (index >= 0) matchingInherited[index--] = null; // clear the previous contents of the matching methods
			MethodBinding inheritedMethod = inherited[i];
			if (inheritedMethod != null) {
				matchingInherited[++index] = inheritedMethod;
				for (int j = i + 1; j < length; j++) {
					MethodBinding otherInheritedMethod = inherited[j];
					if (canSkipInheritedMethods(inheritedMethod, otherInheritedMethod))
						continue;
					otherInheritedMethod = computeSubstituteMethod(otherInheritedMethod, inheritedMethod);
					if (otherInheritedMethod != null && isSubstituteParameterSubsignature(inheritedMethod, otherInheritedMethod)) {
						matchingInherited[++index] = otherInheritedMethod;
						inherited[j] = null; // do not want to find it again
					}
				}
			}
			if (index > 0) {
				MethodBinding first = matchingInherited[0];
				int count = index + 1;
				while (--count > 0) {
					MethodBinding match = matchingInherited[count];
					// https://bugs.eclipse.org/bugs/show_bug.cgi?id=314556
					MethodBinding interfaceMethod = null, implementation = null;
					if (first.declaringClass.isInterface()) {
						interfaceMethod = first;
					} else if (first.declaringClass.isClass()) {
						implementation = first;
					}
					if (match.declaringClass.isInterface()) {
						interfaceMethod = match;
					} else if (match.declaringClass.isClass()) {
						implementation = match;
					}
					if (interfaceMethod != null && implementation != null && !isAsVisible(implementation, interfaceMethod))
						problemReporter().inheritedMethodReducesVisibility(typeParameter, implementation, new MethodBinding [] {interfaceMethod});
					
					if (areReturnTypesCompatible(first, match)) continue;
					// unrelated interfaces - check to see if return types are compatible
					if (first.declaringClass.isInterface() && match.declaringClass.isInterface() && areReturnTypesCompatible(match, first))
						continue;
					break;
				}
				if (count > 0) {  // All inherited methods do NOT have the same vmSignature
					problemReporter().inheritedMethodsHaveIncompatibleReturnTypes(typeParameter, matchingInherited, index + 1);
					continue nextSelector;
				}
			}
		}
	}
}
 
Example #27
Source File: PatchDelegate.java    From EasyMPermission with MIT License 4 votes vote down vote up
public static void checkConflictOfTypeVarNames(BindingTuple binding, EclipseNode typeNode) throws CantMakeDelegates {
	TypeVariableBinding[] typeVars = binding.parameterized.typeVariables();
	if (typeVars == null || typeVars.length == 0) return;
	
	Set<String> usedInOurType = new HashSet<String>();
	EclipseNode enclosingType = typeNode;
	while (enclosingType != null) {
		if (enclosingType.getKind() == Kind.TYPE) {
			TypeParameter[] typeParameters = ((TypeDeclaration)enclosingType.get()).typeParameters;
			if (typeParameters != null) {
				for (TypeParameter param : typeParameters) {
					if (param.name != null) usedInOurType.add(new String(param.name));
				}
			}
		}
		enclosingType = enclosingType.up();
	}
	
	Set<String> usedInMethodSig = new HashSet<String>();
	for (TypeVariableBinding var : typeVars) {
		char[] sourceName = var.sourceName();
		if (sourceName != null) usedInMethodSig.add(new String(sourceName));
	}
	
	usedInMethodSig.retainAll(usedInOurType);
	if (usedInMethodSig.isEmpty()) return;
	
	// We might be delegating a List<T>, and we are making method <T> toArray(). A conflict is possible.
	// But only if the toArray method also uses type vars from its class, otherwise we're only shadowing,
	// which is okay as we'll add a @SuppressWarnings.
	
	TypeVarFinder finder = new TypeVarFinder();
	finder.visitRaw(binding.base);
	
	Set<String> names = new HashSet<String>(finder.getTypeVariables());
	names.removeAll(usedInMethodSig);
	if (!names.isEmpty()) {
		// We have a confirmed conflict. We could dig deeper as this may still be a false alarm, but its already an exceedingly rare case.
		CantMakeDelegates cmd = new CantMakeDelegates();
		cmd.conflicted = usedInMethodSig;
		throw cmd;
	}
}