use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class SourceAnalyzer method checkActivation.
public RefactoringStatus checkActivation() throws JavaModelException {
RefactoringStatus result = new RefactoringStatus();
if (!fTypeRoot.isStructureKnown()) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_syntax_errors, JavaStatusContext.create(fTypeRoot));
return result;
}
IProblem[] problems = ASTNodes.getProblems(fDeclaration, ASTNodes.NODE_ONLY, ASTNodes.ERROR);
if (problems.length > 0) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_declaration_has_errors, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
}
final IMethodBinding declarationBinding = fDeclaration.resolveBinding();
if (declarationBinding != null) {
final int modifiers = declarationBinding.getModifiers();
if (Modifier.isAbstract(modifiers)) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_abstract_methods, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
} else if (Modifier.isNative(modifiers)) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_native_methods, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
}
} else {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_methoddeclaration_has_errors, JavaStatusContext.create(fTypeRoot));
return result;
}
ActivationAnalyzer analyzer = new ActivationAnalyzer();
fDeclaration.accept(analyzer);
result.merge(analyzer.status);
if (!result.hasFatalError()) {
List<SingleVariableDeclaration> parameters = fDeclaration.parameters();
fParameters = new HashMap<IVariableBinding, ParameterData>(parameters.size() * 2);
for (Iterator<SingleVariableDeclaration> iter = parameters.iterator(); iter.hasNext(); ) {
SingleVariableDeclaration element = iter.next();
IVariableBinding binding = element.resolveBinding();
if (binding == null) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_declaration_has_errors, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
}
fParameters.put(binding, (ParameterData) element.getProperty(ParameterData.PROPERTY));
}
fNames = new HashMap<IBinding, NameData>();
fImplicitReceivers = new ArrayList<Expression>(2);
fTypeParameterReferences = new ArrayList<NameData>(0);
fTypeParameterMapping = new HashMap<ITypeBinding, NameData>();
ITypeBinding declaringType = declarationBinding.getDeclaringClass();
if (declaringType == null) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_typedeclaration_has_errors, JavaStatusContext.create(fTypeRoot));
return result;
}
ITypeBinding[] typeParameters = declaringType.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
NameData data = new NameData(typeParameters[i].getName());
fTypeParameterReferences.add(data);
fTypeParameterMapping.put(typeParameters[i], data);
}
fMethodTypeParameterReferences = new ArrayList<NameData>(0);
fMethodTypeParameterMapping = new HashMap<ITypeBinding, NameData>();
IMethodBinding method = declarationBinding;
typeParameters = method.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
NameData data = new NameData(typeParameters[i].getName());
fMethodTypeParameterReferences.add(data);
fMethodTypeParameterMapping.put(typeParameters[i], data);
}
}
if (fDeclaration.isVarargs()) {
List<SingleVariableDeclaration> parameters = fDeclaration.parameters();
VarargAnalyzer vAnalyzer = new VarargAnalyzer(parameters.get(parameters.size() - 1).getName().resolveBinding());
fDeclaration.getBody().accept(vAnalyzer);
}
return result;
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class SourceProvider method updateImplicitReceivers.
private void updateImplicitReceivers(ASTRewrite rewriter, CallContext context) {
if (context.receiver == null)
return;
List<Expression> implicitReceivers = fAnalyzer.getImplicitReceivers();
for (Iterator<Expression> iter = implicitReceivers.iterator(); iter.hasNext(); ) {
ASTNode node = iter.next();
ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(node, context.importer);
if (node instanceof MethodInvocation) {
final MethodInvocation inv = (MethodInvocation) node;
rewriter.set(inv, MethodInvocation.EXPRESSION_PROPERTY, createReceiver(rewriter, context, (IMethodBinding) inv.getName().resolveBinding(), importRewriteContext), null);
} else if (node instanceof ClassInstanceCreation) {
final ClassInstanceCreation inst = (ClassInstanceCreation) node;
rewriter.set(inst, ClassInstanceCreation.EXPRESSION_PROPERTY, createReceiver(rewriter, context, inst.resolveConstructorBinding(), importRewriteContext), null);
} else if (node instanceof ThisExpression) {
rewriter.replace(node, rewriter.createStringPlaceholder(context.receiver, ASTNode.METHOD_INVOCATION), null);
} else if (node instanceof FieldAccess) {
final FieldAccess access = (FieldAccess) node;
rewriter.set(access, FieldAccess.EXPRESSION_PROPERTY, createReceiver(rewriter, context, access.resolveFieldBinding(), importRewriteContext), null);
} else if (node instanceof SimpleName && ((SimpleName) node).resolveBinding() instanceof IVariableBinding) {
IVariableBinding vb = (IVariableBinding) ((SimpleName) node).resolveBinding();
if (vb.isField()) {
Expression receiver = createReceiver(rewriter, context, vb, importRewriteContext);
if (receiver != null) {
FieldAccess access = node.getAST().newFieldAccess();
ASTNode target = rewriter.createMoveTarget(node);
access.setName((SimpleName) target);
access.setExpression(receiver);
rewriter.replace(node, access, null);
}
}
}
}
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class TargetProvider method create.
public static TargetProvider create(MethodDeclaration declaration) {
IMethodBinding method = declaration.resolveBinding();
if (method == null)
return new ErrorTargetProvider(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.TargetProvider_method_declaration_not_unique));
ITypeBinding type = method.getDeclaringClass();
if (type.isLocal()) {
if (((IType) type.getJavaElement()).isBinary()) {
return new ErrorTargetProvider(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.TargetProvider_cannot_local_method_in_binary));
} else {
IType declaringClassOfLocal = (IType) type.getDeclaringClass().getJavaElement();
return new LocalTypeTargetProvider(declaringClassOfLocal.getCompilationUnit(), declaration);
}
} else {
return new MemberTypeTargetProvider(declaration.resolveBinding());
}
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.
the class PromoteTempToFieldRefactoring method checkTempInitializerForLocalTypeUsage.
private void checkTempInitializerForLocalTypeUsage() {
Expression initializer = fTempDeclarationNode.getInitializer();
if (initializer == null)
return;
IMethodBinding declaringMethodBinding = getMethodDeclaration().resolveBinding();
ITypeBinding[] methodTypeParameters = declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters();
LocalTypeAndVariableUsageAnalyzer localTypeAnalyer = new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters);
initializer.accept(localTypeAnalyer);
fInitializerUsesLocalTypes = !localTypeAnalyer.getUsageOfEnclosingNodes().isEmpty();
}
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);
}
Aggregations