use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class PromoteTempToFieldRefactoring method checkTempTypeForLocalTypeUsage.
private RefactoringStatus checkTempTypeForLocalTypeUsage() {
VariableDeclarationStatement vds = getTempDeclarationStatement();
if (vds == null)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote);
Type type = vds.getType();
ITypeBinding binding = type.resolveBinding();
if (binding == null)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote);
IMethodBinding declaringMethodBinding = getMethodDeclaration().resolveBinding();
ITypeBinding[] methodTypeParameters = declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters();
LocalTypeAndVariableUsageAnalyzer analyzer = new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters);
type.accept(analyzer);
boolean usesLocalTypes = !analyzer.getUsageOfEnclosingNodes().isEmpty();
fTempTypeUsesClassTypeVariables = analyzer.getClassTypeVariablesUsed();
if (usesLocalTypes)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_uses_type_declared_locally);
return null;
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class ReplaceInvocationsRefactoring method createChange.
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
// TODO: update for fSelectionStart == -1
final Map<String, String> arguments = new HashMap<String, String>();
String project = null;
IJavaProject javaProject = fSelectionTypeRoot.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
final IMethodBinding binding = fSourceProvider.getDeclaration().resolveBinding();
int flags = RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
if (!Modifier.isPrivate(binding.getModifiers()))
flags |= RefactoringDescriptor.MULTI_CHANGE;
final String description = Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName()));
final String header = Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringClass(), JavaElementLabels.ALL_FULLY_QUALIFIED) });
final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
comment.addSetting(Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
if (!fTargetProvider.isSingle())
comment.addSetting(RefactoringCoreMessages.ReplaceInvocationsRefactoring_replace_references);
//REVIEW Unregistered ID!
final JavaRefactoringDescriptor descriptor = new JavaRefactoringDescriptor(ID_REPLACE_INVOCATIONS, project, description, comment.asString(), arguments, flags) {
};
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fSelectionTypeRoot));
//$NON-NLS-1$
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString());
arguments.put(ATTRIBUTE_MODE, new Integer(fTargetProvider.isSingle() ? 0 : 1).toString());
return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.ReplaceInvocationsRefactoring_change_name, fChangeManager.getAllChanges());
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class IntroduceFactoryRefactoring method createFactoryMethod.
/**
* Creates and returns a new MethodDeclaration that represents the factory method to be used in
* place of direct calls to the constructor in question.
*
* @param ast An AST used as a factory for various AST nodes
* @param ctorBinding binding for the constructor being wrapped
* @param unitRewriter the ASTRewrite to be used
* @return the new method declaration
* @throws CoreException if an exception occurs while accessing its corresponding resource
*/
private MethodDeclaration createFactoryMethod(AST ast, IMethodBinding ctorBinding, ASTRewrite unitRewriter) throws CoreException {
MethodDeclaration newMethod = ast.newMethodDeclaration();
SimpleName newMethodName = ast.newSimpleName(fNewMethodName);
ClassInstanceCreation newCtorCall = ast.newClassInstanceCreation();
ReturnStatement ret = ast.newReturnStatement();
Block body = ast.newBlock();
List<Statement> stmts = body.statements();
String retTypeName = ctorBinding.getName();
createFactoryMethodSignature(ast, newMethod);
newMethod.setName(newMethodName);
newMethod.setBody(body);
ITypeBinding declaringClass = fCtorBinding.getDeclaringClass();
ITypeBinding[] ctorOwnerTypeParameters = declaringClass.getTypeParameters();
setMethodReturnType(newMethod, retTypeName, ctorOwnerTypeParameters, ast);
newMethod.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.STATIC | Modifier.PUBLIC));
setCtorTypeArguments(newCtorCall, retTypeName, ctorOwnerTypeParameters, ast);
createFactoryMethodConstructorArgs(ast, newCtorCall);
if (Modifier.isAbstract(declaringClass.getModifiers())) {
AnonymousClassDeclaration decl = ast.newAnonymousClassDeclaration();
IMethodBinding[] unimplementedMethods = getUnimplementedMethods(declaringClass);
CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings(fCUHandle.getJavaProject());
ImportRewriteContext context = new ContextSensitiveImportRewriteContext(fFactoryCU, decl.getStartPosition(), fImportRewriter);
for (int i = 0; i < unimplementedMethods.length; i++) {
IMethodBinding unImplementedMethod = unimplementedMethods[i];
MethodDeclaration newMethodDecl = StubUtility2.createImplementationStub(fCUHandle, unitRewriter, fImportRewriter, context, unImplementedMethod, unImplementedMethod.getDeclaringClass().getName(), settings, false);
decl.bodyDeclarations().add(newMethodDecl);
}
newCtorCall.setAnonymousClassDeclaration(decl);
}
ret.setExpression(newCtorCall);
stmts.add(ret);
return newMethod;
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method endVisit.
@Override
public void endVisit(MethodInvocation node) {
IMethodBinding methodBinding = node.resolveMethodBinding();
if (methodBinding == null)
return;
Expression receiver;
if (JdtFlags.isStatic(methodBinding))
receiver = null;
else
receiver = node.getExpression();
if (isSpecialCloneInvocation(methodBinding, receiver)) {
ConstraintVariable2 expressionCv = getConstraintVariable(receiver);
// [retVal] =^= [receiver]:
setConstraintVariable(node, expressionCv);
} else if ("getClass".equals(methodBinding.getName()) && methodBinding.getParameterTypes().length == 0) {
//$NON-NLS-1$
//special case: see JLS3 4.3.2
ITypeBinding returnType = node.resolveTypeBinding();
ITypeBinding returnTypeDeclaration = returnType.getTypeDeclaration();
ParameterizedTypeVariable2 expressionCv = fTCModel.makeParameterizedTypeVariable(returnTypeDeclaration);
setConstraintVariable(node, expressionCv);
ConstraintVariable2 classTypeVariable = fTCModel.getElementVariable(expressionCv, returnTypeDeclaration.getTypeParameters()[0]);
//type of expression 'e.getClass()' is 'Class<? extends X>' where X is the static type of e
ITypeBinding capture = returnType.getTypeArguments()[0];
ITypeBinding wildcard = capture.getWildcard();
if (wildcard.getBound() == null)
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619
return;
ImmutableTypeVariable2 wildcardType = fTCModel.makeImmutableTypeVariable(wildcard, /*no boxing*/
null);
fTCModel.createSubtypeConstraint(classTypeVariable, wildcardType);
// ITypeBinding bound= wildcard.getBound();
// ImmutableTypeVariable2 boundType= fTCModel.makeImmutableTypeVariable(bound, node.getAST());
// fTCModel.createSubtypeConstraint(classTypeVariable, boundType);
} else {
Map<String, IndependentTypeVariable2> methodTypeVariables = createMethodTypeArguments(methodBinding);
doVisitMethodInvocationReturnType(node, methodBinding, receiver, methodTypeVariables);
doVisitMethodInvocationArguments(methodBinding, node.arguments(), receiver, methodTypeVariables, /*no created type*/
null);
}
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class SourceProvider method updateMethodTypeVariable.
private void updateMethodTypeVariable(ASTRewrite rewriter, CallContext context) {
IMethodBinding method = Invocations.resolveBinding(context.invocation);
if (method == null)
return;
rewriteReferences(rewriter, method.getTypeArguments(), fAnalyzer.getMethodTypeParameterReferences());
}
Aggregations