use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class FullConstraintCreator method create.
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodDeclaration)
*/
@Override
public ITypeConstraint[] create(MethodDeclaration declaration) {
List<ITypeConstraint> result = new ArrayList<ITypeConstraint>();
IMethodBinding methodBinding = declaration.resolveBinding();
if (methodBinding == null)
return new ITypeConstraint[0];
ITypeConstraint[] constraints = fTypeConstraintFactory.createDefinesConstraint(fConstraintVariableFactory.makeDeclaringTypeVariable(methodBinding), fConstraintVariableFactory.makeRawBindingVariable(methodBinding.getDeclaringClass()));
result.addAll(Arrays.asList(constraints));
if (!methodBinding.isConstructor() && !methodBinding.getReturnType().isPrimitive()) {
ConstraintVariable returnTypeBindingVariable = fConstraintVariableFactory.makeReturnTypeVariable(methodBinding);
ConstraintVariable returnTypeVariable = fConstraintVariableFactory.makeTypeVariable(declaration.getReturnType2());
ITypeConstraint[] defines = fTypeConstraintFactory.createDefinesConstraint(returnTypeBindingVariable, returnTypeVariable);
result.addAll(Arrays.asList(defines));
}
for (int i = 0, n = declaration.parameters().size(); i < n; i++) {
SingleVariableDeclaration paramDecl = (SingleVariableDeclaration) declaration.parameters().get(i);
ConstraintVariable parameterTypeVariable = fConstraintVariableFactory.makeParameterTypeVariable(methodBinding, i);
ConstraintVariable parameterNameVariable = fConstraintVariableFactory.makeExpressionOrTypeVariable(paramDecl.getName(), getContext());
ITypeConstraint[] constraint = fTypeConstraintFactory.createDefinesConstraint(parameterTypeVariable, parameterNameVariable);
result.addAll(Arrays.asList(constraint));
}
if (MethodChecks.isVirtual(methodBinding)) {
Collection<ITypeConstraint> constraintsForOverriding = getConstraintsForOverriding(methodBinding);
result.addAll(constraintsForOverriding);
}
return result.toArray(new ITypeConstraint[result.size()]);
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class FullConstraintCreator method getRootDefs.
//--- RootDef ----//
protected static IMethodBinding[] getRootDefs(IMethodBinding methodBinding) {
Set<ITypeBinding> declaringSuperTypes = getDeclaringSuperTypes(methodBinding);
Set<IMethodBinding> result = new LinkedHashSet<IMethodBinding>();
for (Iterator<ITypeBinding> iter = declaringSuperTypes.iterator(); iter.hasNext(); ) {
ITypeBinding type = iter.next();
if (!containsASuperType(type, declaringSuperTypes))
result.add(findMethod(methodBinding, type));
}
if (result.size() == 0) {
result.add(methodBinding);
}
return result.toArray(new IMethodBinding[result.size()]);
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class FullConstraintCreator method create.
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
*/
@Override
public ITypeConstraint[] create(MethodInvocation invocation) {
List<Expression> arguments = invocation.arguments();
List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
IMethodBinding methodBinding = invocation.resolveMethodBinding();
if (methodBinding == null)
return new ITypeConstraint[0];
ITypeConstraint[] returnTypeConstraint = getReturnTypeConstraint(invocation, methodBinding);
result.addAll(Arrays.asList(returnTypeConstraint));
result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
if (invocation.getExpression() != null) {
if (MethodChecks.isVirtual(methodBinding)) {
IMethodBinding[] rootDefs = getRootDefs(methodBinding);
Assert.isTrue(rootDefs.length > 0);
ConstraintVariable expressionVar = fConstraintVariableFactory.makeExpressionOrTypeVariable(invocation.getExpression(), getContext());
if (rootDefs.length == 1) {
result.addAll(Arrays.asList(fTypeConstraintFactory.createSubtypeConstraint(expressionVar, fConstraintVariableFactory.makeDeclaringTypeVariable(rootDefs[0]))));
} else {
Collection<ITypeConstraint> constraints = new ArrayList<ITypeConstraint>();
for (int i = 0; i < rootDefs.length; i++) {
ConstraintVariable rootDefTypeVar = fConstraintVariableFactory.makeDeclaringTypeVariable(rootDefs[i]);
ITypeConstraint[] tc = fTypeConstraintFactory.createSubtypeConstraint(expressionVar, rootDefTypeVar);
constraints.addAll(Arrays.asList(tc));
}
ITypeConstraint[] constraintsArray = constraints.toArray(new ITypeConstraint[constraints.size()]);
if (constraintsArray.length > 0) {
result.add(fTypeConstraintFactory.createCompositeOrTypeConstraint(constraintsArray));
}
}
} else {
ConstraintVariable typeVar = fConstraintVariableFactory.makeDeclaringTypeVariable(methodBinding);
ConstraintVariable expressionVar = fConstraintVariableFactory.makeExpressionOrTypeVariable(invocation.getExpression(), getContext());
result.addAll(Arrays.asList(fTypeConstraintFactory.createSubtypeConstraint(expressionVar, typeVar)));
}
}
return result.toArray(new ITypeConstraint[result.size()]);
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class FullConstraintCreator method create.
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ClassInstanceCreation)
*/
@Override
public ITypeConstraint[] create(ClassInstanceCreation instanceCreation) {
List<Expression> arguments = instanceCreation.arguments();
List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
IMethodBinding methodBinding = instanceCreation.resolveConstructorBinding();
result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
if (instanceCreation.getAnonymousClassDeclaration() == null) {
ConstraintVariable constructorVar = fConstraintVariableFactory.makeExpressionOrTypeVariable(instanceCreation, getContext());
ConstraintVariable typeVar = fConstraintVariableFactory.makeRawBindingVariable(instanceCreation.resolveTypeBinding());
result.addAll(Arrays.asList(fTypeConstraintFactory.createDefinesConstraint(constructorVar, typeVar)));
}
return result.toArray(new ITypeConstraint[result.size()]);
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class FullConstraintCreator method create.
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SuperConstructorInvocation)
*/
@Override
public ITypeConstraint[] create(SuperConstructorInvocation invocation) {
List<Expression> arguments = invocation.arguments();
List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
IMethodBinding methodBinding = invocation.resolveConstructorBinding();
result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
return result.toArray(new ITypeConstraint[result.size()]);
}
Aggregations