Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 378028
Collapse All | Expand All

(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallContext.java (+1 lines)
Lines 22-27 import org.eclipse.jdt.internal.corext.dom.CodeScopeBuilder; Link Here
22
public class CallContext {
22
public class CallContext {
23
23
24
	public ASTNode invocation;
24
	public ASTNode invocation;
25
	public boolean methodStaticallyImported;
25
	public Expression[] arguments;
26
	public Expression[] arguments;
26
	public String receiver;
27
	public String receiver;
27
	public boolean receiverIsStatic;
28
	public boolean receiverIsStatic;
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java (-1 / +17 lines)
Lines 92-97 import org.eclipse.jdt.internal.corext.dom.CodeScopeBuilder; Link Here
92
import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor;
92
import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor;
93
import org.eclipse.jdt.internal.corext.dom.LocalVariableIndex;
93
import org.eclipse.jdt.internal.corext.dom.LocalVariableIndex;
94
import org.eclipse.jdt.internal.corext.dom.NecessaryParenthesesChecker;
94
import org.eclipse.jdt.internal.corext.dom.NecessaryParenthesesChecker;
95
import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
95
import org.eclipse.jdt.internal.corext.dom.Selection;
96
import org.eclipse.jdt.internal.corext.dom.Selection;
96
import org.eclipse.jdt.internal.corext.dom.TypeBindingVisitor;
97
import org.eclipse.jdt.internal.corext.dom.TypeBindingVisitor;
97
import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
98
import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
Lines 302-307 public class CallInliner { Link Here
302
		return result;
303
		return result;
303
	}
304
	}
304
305
306
	public boolean hasStaticallyImported() {
307
		return fContext.methodStaticallyImported;
308
	}
309
305
	private void initializeRewriteState() {
310
	private void initializeRewriteState() {
306
		fFieldInitializer= false;
311
		fFieldInitializer= false;
307
		ASTNode parent= fInvocation.getParent();
312
		ASTNode parent= fInvocation.getParent();
Lines 565-572 public class CallInliner { Link Here
565
570
566
	private void computeReceiver() throws BadLocationException {
571
	private void computeReceiver() throws BadLocationException {
567
		Expression receiver= Invocations.getExpression(fInvocation);
572
		Expression receiver= Invocations.getExpression(fInvocation);
568
		if (receiver == null)
573
		if (receiver == null) {
574
			MethodInvocation inv= (MethodInvocation)fInvocation;
575
			IMethodBinding methodBinding= inv.resolveMethodBinding().getMethodDeclaration();
576
			if(methodBinding == null)
577
				return;
578
			ITypeBinding declaringClass= methodBinding.getDeclaringClass();
579
			if (declaringClass != null && !declaringClass.isLocal() && Modifier.isStatic(methodBinding.getModifiers())) {
580
				ASTNode root= fInvocation.getRoot();
581
				if (!new ScopeAnalyzer(root instanceof CompilationUnit ? (CompilationUnit)root : null).isDeclaredInScope(methodBinding, inv.getName(), ScopeAnalyzer.METHODS | ScopeAnalyzer.CHECK_VISIBILITY))
582
					fContext.methodStaticallyImported = true;
583
			}
569
			return;
584
			return;
585
		}
570
		final boolean isName= receiver instanceof Name;
586
		final boolean isName= receiver instanceof Name;
571
		if (isName)
587
		if (isName)
572
			fContext.receiverIsStatic= ((Name)receiver).resolveBinding() instanceof ITypeBinding;
588
			fContext.receiverIsStatic= ((Name)receiver).resolveBinding() instanceof ITypeBinding;
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineMethodRefactoring.java (+7 lines)
Lines 297-302 public class InlineMethodRefactoring extends Refactoring { Link Here
297
				BodyDeclaration[] bodies= fTargetProvider.getAffectedBodyDeclarations(unit, new SubProgressMonitor(pm, 1));
297
				BodyDeclaration[] bodies= fTargetProvider.getAffectedBodyDeclarations(unit, new SubProgressMonitor(pm, 1));
298
				if (bodies.length == 0)
298
				if (bodies.length == 0)
299
					continue;
299
					continue;
300
				boolean hasStaticallyImported= false;
300
				inliner= new CallInliner(unit, (CompilationUnit) bodies[0].getRoot(), fSourceProvider);
301
				inliner= new CallInliner(unit, (CompilationUnit) bodies[0].getRoot(), fSourceProvider);
301
				for (int b= 0; b < bodies.length; b++) {
302
				for (int b= 0; b < bodies.length; b++) {
302
					BodyDeclaration body= bodies[b];
303
					BodyDeclaration body= bodies[b];
Lines 307-312 public class InlineMethodRefactoring extends Refactoring { Link Here
307
					for (int i= 0; i < invocations.length; i++) {
308
					for (int i= 0; i < invocations.length; i++) {
308
						ASTNode invocation= invocations[i];
309
						ASTNode invocation= invocations[i];
309
						result.merge(inliner.initialize(invocation, fTargetProvider.getStatusSeverity()));
310
						result.merge(inliner.initialize(invocation, fTargetProvider.getStatusSeverity()));
311
						hasStaticallyImported= hasStaticallyImported || inliner.hasStaticallyImported();
310
						if (result.hasFatalError())
312
						if (result.hasFatalError())
311
							break;
313
							break;
312
						if (result.getSeverity() < fTargetProvider.getStatusSeverity()) {
314
						if (result.getSeverity() < fTargetProvider.getStatusSeverity()) {
Lines 330-335 public class InlineMethodRefactoring extends Refactoring { Link Here
330
				} else {
332
				} else {
331
					root.addChild(inliner.getModifications());
333
					root.addChild(inliner.getModifications());
332
					ImportRewrite rewrite= inliner.getImportEdit();
334
					ImportRewrite rewrite= inliner.getImportEdit();
335
					if (hasStaticallyImported && fDeleteSource && fCurrentMode == Mode.INLINE_ALL && fInitialNode instanceof MethodInvocation) {
336
						MethodInvocation inv= (MethodInvocation)fInitialNode;
337
						String methodFqn= inv.resolveMethodBinding().getDeclaringClass().getQualifiedName() + '.' + inv.getName();
338
						rewrite.removeStaticImport(methodFqn);
339
					}
333
					if (rewrite.hasRecordedChanges()) {
340
					if (rewrite.hasRecordedChanges()) {
334
						TextEdit edit= rewrite.rewriteImports(null);
341
						TextEdit edit= rewrite.rewriteImports(null);
335
						if (edit instanceof MultiTextEdit ? ((MultiTextEdit)edit).getChildrenSize() > 0 : true) {
342
						if (edit instanceof MultiTextEdit ? ((MultiTextEdit)edit).getChildrenSize() > 0 : true) {
(-)a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/SourceProvider.java (-5 / +14 lines)
Lines 484-490 public class SourceProvider { Link Here
484
	}
484
	}
485
485
486
	private void updateImplicitReceivers(ASTRewrite rewriter, CallContext context) {
486
	private void updateImplicitReceivers(ASTRewrite rewriter, CallContext context) {
487
		if (context.receiver == null)
487
		if (context.receiver == null && !context.methodStaticallyImported)
488
			return;
488
			return;
489
		List<Expression> implicitReceivers= fAnalyzer.getImplicitReceivers();
489
		List<Expression> implicitReceivers= fAnalyzer.getImplicitReceivers();
490
		for (Iterator<Expression> iter= implicitReceivers.iterator(); iter.hasNext();) {
490
		for (Iterator<Expression> iter= implicitReceivers.iterator(); iter.hasNext();) {
Lines 554-577 public class SourceProvider { Link Here
554
	}
554
	}
555
555
556
	private Expression createReceiver(ASTRewrite rewriter, CallContext context, IMethodBinding method, ImportRewriteContext importRewriteContext) {
556
	private Expression createReceiver(ASTRewrite rewriter, CallContext context, IMethodBinding method, ImportRewriteContext importRewriteContext) {
557
		String receiver= getReceiver(context, method.getModifiers(), importRewriteContext);
557
		String receiver= getReceiver(context, method, importRewriteContext);
558
		if (receiver == null)
558
		if (receiver == null)
559
			return null;
559
			return null;
560
		return (Expression)rewriter.createStringPlaceholder(receiver, ASTNode.METHOD_INVOCATION);
560
		return (Expression)rewriter.createStringPlaceholder(receiver, ASTNode.METHOD_INVOCATION);
561
	}
561
	}
562
562
563
	private Expression createReceiver(ASTRewrite rewriter, CallContext context, IVariableBinding field, ImportRewriteContext importRewriteContext) {
563
	private Expression createReceiver(ASTRewrite rewriter, CallContext context, IVariableBinding field, ImportRewriteContext importRewriteContext) {
564
		String receiver= getReceiver(context, field.getModifiers(), importRewriteContext);
564
		String receiver= getReceiver(context, field, importRewriteContext);
565
		if (receiver == null)
565
		if (receiver == null)
566
			return null;
566
			return null;
567
		return (Expression)rewriter.createStringPlaceholder(receiver, ASTNode.SIMPLE_NAME);
567
		return (Expression)rewriter.createStringPlaceholder(receiver, ASTNode.SIMPLE_NAME);
568
	}
568
	}
569
569
570
	private String getReceiver(CallContext context, int modifiers, ImportRewriteContext importRewriteContext) {
570
	private String getReceiver(CallContext context, IBinding binding, ImportRewriteContext importRewriteContext) {
571
		int modifiers = binding.getModifiers();
571
		String receiver= context.receiver;
572
		String receiver= context.receiver;
572
		ITypeBinding invocationType= ASTNodes.getEnclosingType(context.invocation);
573
		ITypeBinding invocationType= ASTNodes.getEnclosingType(context.invocation);
573
		ITypeBinding sourceType= fDeclaration.resolveBinding().getDeclaringClass();
574
		ITypeBinding sourceType= fDeclaration.resolveBinding().getDeclaringClass();
574
		if (!context.receiverIsStatic && Modifier.isStatic(modifiers)) {
575
		if(context.methodStaticallyImported) {
576
			receiver = context.importer.addStaticImport(binding, new ContextSensitiveImportRewriteContext(context.invocation, context.importer));
577
			if(binding.getName().equals(receiver))
578
				receiver = null;
579
			else {
580
				receiver = receiver.substring(0, receiver.lastIndexOf('.'));
581
			}
582
		}
583
		else if (!context.receiverIsStatic && Modifier.isStatic(modifiers)) {
575
			if ("this".equals(receiver) && invocationType != null && Bindings.equals(invocationType, sourceType)) { //$NON-NLS-1$
584
			if ("this".equals(receiver) && invocationType != null && Bindings.equals(invocationType, sourceType)) { //$NON-NLS-1$
576
				receiver= null;
585
				receiver= null;
577
			} else {
586
			} else {

Return to bug 378028