use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(ClassInstanceCreation node) {
Expression receiver = node.getExpression();
Type createdType = node.getType();
ConstraintVariable2 typeCv;
if (node.getAnonymousClassDeclaration() == null) {
typeCv = getConstraintVariable(createdType);
} else {
typeCv = fTCModel.makeImmutableTypeVariable(createdType.resolveBinding(), null);
setConstraintVariable(createdType, typeCv);
}
setConstraintVariable(node, typeCv);
IMethodBinding methodBinding = node.resolveConstructorBinding();
Map<String, IndependentTypeVariable2> methodTypeVariables = createMethodTypeArguments(methodBinding);
List<Expression> arguments = node.arguments();
doVisitMethodInvocationArguments(methodBinding, arguments, receiver, methodTypeVariables, createdType);
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(MethodDeclaration node) {
IMethodBinding methodBinding = node.resolveBinding();
if (methodBinding == null)
//TODO: emit error?
return;
int parameterCount = node.parameters().size();
ConstraintVariable2[] parameterTypeCvs = new ConstraintVariable2[parameterCount];
for (int i = 0; i < parameterCount; i++) {
SingleVariableDeclaration paramDecl = (SingleVariableDeclaration) node.parameters().get(i);
//parameterTypeVariable currently not used, but need to register in order to store source range
ConstraintVariable2 parameterTypeCv = fTCModel.makeDeclaredParameterTypeVariable(methodBinding, i, fCU);
parameterTypeCvs[i] = parameterTypeCv;
if (parameterTypeCv == null)
continue;
//creating equals constraint between parameterTypeVariable's elements and the Type's elements
ConstraintVariable2 typeCv = getConstraintVariable(paramDecl.getType());
fTCModel.createElementEqualsConstraints(parameterTypeCv, typeCv);
//TODO: should avoid having a VariableVariable as well as a ParameterVariable for a parameter
ConstraintVariable2 nameCv = getConstraintVariable(paramDecl.getName());
fTCModel.createElementEqualsConstraints(parameterTypeCv, nameCv);
}
ConstraintVariable2 returnTypeCv = null;
if (!methodBinding.isConstructor()) {
//TODO: should only create return type variable if type is generic?
ConstraintVariable2 returnTypeBindingCv = fTCModel.makeDeclaredReturnTypeVariable(methodBinding, fCU);
if (returnTypeBindingCv != null) {
returnTypeCv = getConstraintVariable(node.getReturnType2());
fTCModel.createElementEqualsConstraints(returnTypeBindingCv, returnTypeCv);
}
}
if (MethodChecks.isVirtual(methodBinding)) {
//TODO: RippleMethod constraints for corner cases: see testCuRippleMethods3, bug 41989
addConstraintsForOverriding(methodBinding, returnTypeCv, parameterTypeCvs);
}
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(ReturnStatement node) {
Expression expression = node.getExpression();
if (expression == null)
return;
ConstraintVariable2 expressionCv = getConstraintVariable(expression);
if (expressionCv == null)
return;
MethodDeclaration methodDeclaration = (MethodDeclaration) ASTNodes.getParent(node, ASTNode.METHOD_DECLARATION);
if (methodDeclaration == null)
return;
IMethodBinding methodBinding = methodDeclaration.resolveBinding();
if (methodBinding == null)
return;
ReturnTypeVariable2 returnTypeCv = fTCModel.makeReturnTypeVariable(methodBinding);
if (returnTypeCv == null)
return;
fTCModel.createElementEqualsConstraints(returnTypeCv, expressionCv);
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method addConstraintsForOverriding.
private void addConstraintsForOverriding(IMethodBinding methodBinding, ConstraintVariable2 returnTypeCv, ConstraintVariable2[] parameterTypeCvs) {
boolean hasParameterElementCvs = false;
for (int i = 0; i < parameterTypeCvs.length; i++) if (parameterTypeCvs[i] != null)
hasParameterElementCvs = true;
if (returnTypeCv == null && !hasParameterElementCvs)
return;
ITypeBinding[] allSuperTypes = Bindings.getAllSuperTypes(methodBinding.getDeclaringClass());
for (int i = 0; i < allSuperTypes.length; i++) {
ITypeBinding superType = allSuperTypes[i];
IMethodBinding superMethod = Bindings.findOverriddenMethodInType(superType, methodBinding);
if (superMethod == null)
continue;
for (int p = 0; p < parameterTypeCvs.length; p++) {
if (parameterTypeCvs[p] == null)
continue;
ParameterTypeVariable2 parameterTypeCv = fTCModel.makeParameterTypeVariable(superMethod, p);
fTCModel.createElementEqualsConstraints(parameterTypeCv, parameterTypeCvs[p]);
}
if (returnTypeCv != null) {
ReturnTypeVariable2 superMethodReturnTypeCv = fTCModel.makeReturnTypeVariable(superMethod);
fTCModel.createElementEqualsConstraints(superMethodReturnTypeCv, returnTypeCv);
}
}
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class ModifierCorrectionSubProcessor method addRemoveInvalidModifiersProposal.
public static void addRemoveInvalidModifiersProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals, int relevance) {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (selectedNode instanceof MethodDeclaration) {
selectedNode = ((MethodDeclaration) selectedNode).getName();
}
if (!(selectedNode instanceof SimpleName)) {
return;
}
IBinding binding = ((SimpleName) selectedNode).resolveBinding();
if (binding != null) {
String methodName = BasicElementLabels.getJavaElementName(binding.getName());
String label = null;
int problemId = problem.getProblemId();
int excludedModifiers = 0;
int includedModifiers = 0;
switch(problemId) {
case IProblem.CannotHideAnInstanceMethodWithAStaticMethod:
case IProblem.UnexpectedStaticModifierForMethod:
excludedModifiers = Modifier.STATIC;
label = Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changemethodtononstatic_description, methodName);
break;
case IProblem.UnexpectedStaticModifierForField:
excludedModifiers = Modifier.STATIC;
label = Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changefieldmodifiertononstatic_description, methodName);
break;
case IProblem.IllegalModifierCombinationFinalVolatileForField:
excludedModifiers = Modifier.VOLATILE;
label = CorrectionMessages.ModifierCorrectionSubProcessor_removevolatile_description;
break;
case IProblem.IllegalModifierForInterfaceMethod:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.ABSTRACT);
break;
case IProblem.IllegalModifierForInterfaceMethod18:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.STRICTFP | Modifier.DEFAULT | Modifier.STATIC);
break;
case IProblem.IllegalModifierForInterface:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.STRICTFP);
break;
case IProblem.IllegalModifierForClass:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.ABSTRACT | Modifier.FINAL | Modifier.STRICTFP);
break;
case IProblem.IllegalModifierForInterfaceField:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL);
break;
case IProblem.IllegalModifierForMemberInterface:
case IProblem.IllegalVisibilityModifierForInterfaceMemberType:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.STATIC | Modifier.STRICTFP);
break;
case IProblem.IllegalModifierForMemberClass:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | Modifier.STATIC | Modifier.ABSTRACT | Modifier.FINAL | Modifier.STRICTFP);
break;
case IProblem.IllegalModifierForLocalClass:
excludedModifiers = ~(Modifier.ABSTRACT | Modifier.FINAL | Modifier.STRICTFP);
break;
case IProblem.IllegalModifierForArgument:
excludedModifiers = ~Modifier.FINAL;
break;
case IProblem.IllegalModifierForField:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL | Modifier.VOLATILE | Modifier.TRANSIENT);
break;
case IProblem.IllegalModifierForMethod:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | Modifier.STATIC | Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE | Modifier.STRICTFP | Modifier.SYNCHRONIZED);
break;
case IProblem.IllegalModifierForConstructor:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE);
break;
case IProblem.IllegalModifierForVariable:
excludedModifiers = ~Modifier.FINAL;
break;
case IProblem.IllegalModifierForEnum:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.STRICTFP);
break;
case IProblem.IllegalModifierForEnumConstant:
excludedModifiers = ~Modifier.NONE;
break;
case IProblem.IllegalModifierForEnumConstructor:
excludedModifiers = ~Modifier.PRIVATE;
break;
case IProblem.IllegalModifierForMemberEnum:
excludedModifiers = ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED | Modifier.STATIC | Modifier.STRICTFP);
break;
default:
//$NON-NLS-1$
Assert.isTrue(false, "not supported");
return;
}
if (label == null)
label = Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_removeinvalidmodifiers_description, methodName);
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
proposals.add(new ModifierChangeCorrectionProposal(label, cu, binding, selectedNode, includedModifiers, excludedModifiers, relevance, image));
if (problemId == IProblem.IllegalModifierCombinationFinalVolatileForField) {
proposals.add(new ModifierChangeCorrectionProposal(CorrectionMessages.ModifierCorrectionSubProcessor_removefinal_description, cu, binding, selectedNode, 0, Modifier.FINAL, relevance + 1, image));
}
if (problemId == IProblem.UnexpectedStaticModifierForField && binding instanceof IVariableBinding) {
ITypeBinding declClass = ((IVariableBinding) binding).getDeclaringClass();
if (declClass.isMember()) {
proposals.add(new ModifierChangeCorrectionProposal(CorrectionMessages.ModifierCorrectionSubProcessor_changemodifiertostaticfinal_description, cu, binding, selectedNode, Modifier.FINAL, Modifier.VOLATILE, relevance + 1, image));
ASTNode parentType = context.getASTRoot().findDeclaringNode(declClass);
if (parentType != null) {
proposals.add(new ModifierChangeCorrectionProposal(CorrectionMessages.ModifierCorrectionSubProcessor_addstatictoparenttype_description, cu, declClass, parentType, Modifier.STATIC, 0, relevance - 1, image));
}
}
}
if (problemId == IProblem.UnexpectedStaticModifierForMethod && binding instanceof IMethodBinding) {
ITypeBinding declClass = ((IMethodBinding) binding).getDeclaringClass();
if (declClass.isMember()) {
ASTNode parentType = context.getASTRoot().findDeclaringNode(declClass);
if (parentType != null) {
proposals.add(new ModifierChangeCorrectionProposal(CorrectionMessages.ModifierCorrectionSubProcessor_addstatictoparenttype_description, cu, declClass, parentType, Modifier.STATIC, 0, relevance - 1, image));
}
}
}
}
}
Aggregations