aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-09-02 23:36:31 (EDT)
committerzzhongwei2012-09-02 23:36:31 (EDT)
commita4e3aec88a44d1488aa760ede1a5d7262792e99d (patch)
tree0aaa6c321a46ec534e867bc196666eba2de0f7ce
parentcfc21613c40ba0cf9622517fd465e3ab9d9c8fa8 (diff)
downloadorg.eclipse.pdt-a4e3aec88a44d1488aa760ede1a5d7262792e99d.zip
org.eclipse.pdt-a4e3aec88a44d1488aa760ede1a5d7262792e99d.tar.gz
org.eclipse.pdt-a4e3aec88a44d1488aa760ede1a5d7262792e99d.tar.bz2
388655: Extract Local Variable breaks the code in certain cases
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388655
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/nodes/TraitUseStatement.java4
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/ASTFragmentFactory.java56
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/AssociativeInfixExpressionFragment.java16
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/SimpleFragment.java4
4 files changed, 53 insertions, 27 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/nodes/TraitUseStatement.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/nodes/TraitUseStatement.java
index 926a379..1c35a3d 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/nodes/TraitUseStatement.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/nodes/TraitUseStatement.java
@@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.php.internal.core.compiler.ast.nodes;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.dltk.ast.ASTVisitor;
@@ -70,6 +71,9 @@ public class TraitUseStatement extends Statement {
}
public List<TraitStatement> getTsList() {
+ if (tsList == null) {
+ tsList = new ArrayList<TraitStatement>();
+ }
return tsList;
}
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/ASTFragmentFactory.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/ASTFragmentFactory.java
index fe4dcb6..31b28ca 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/ASTFragmentFactory.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/ASTFragmentFactory.java
@@ -61,18 +61,18 @@ public class ASTFragmentFactory {
*/
public static IASTFragment createFragmentForSourceRange(SourceRange range,
ASTNode scope, IDocument document) throws Exception {
- SelectionAnalyzer sa = new SelectionAnalyzer(Selection
- .createFromStartLength(range.getOffset(), range.getLength()),
- false);
+ SelectionAnalyzer sa = new SelectionAnalyzer(
+ Selection.createFromStartLength(range.getOffset(),
+ range.getLength()), false);
scope.accept(sa);
if (isSingleNodeSelected(sa, range, document, scope))
- return ASTFragmentFactory.createFragmentForFullSubtree(sa
- .getFirstSelectedNode());
+ return ASTFragmentFactory.createFragmentForFullSubtree(
+ sa.getFirstSelectedNode(), null);
if (isEmptySelectionCoveredByANode(range, sa))
- return ASTFragmentFactory.createFragmentForFullSubtree(sa
- .getLastCoveringNode());
- return ASTFragmentFactory.createFragmentForSubPartBySourceRange(sa
- .getLastCoveringNode(), range, scope, document);
+ return ASTFragmentFactory.createFragmentForFullSubtree(
+ sa.getLastCoveringNode(), null);
+ return ASTFragmentFactory.createFragmentForSubPartBySourceRange(
+ sa.getLastCoveringNode(), range, scope, document);
}
/**
@@ -99,8 +99,8 @@ public class ASTFragmentFactory {
SourceRange range, IDocument document, ASTNode scope)
throws BadLocationException {
return sa.getSelectedNodes().length == 1
- && !rangeIncludesNonWhitespaceOutsideNode(range, sa
- .getFirstSelectedNode(), document, scope);
+ && !rangeIncludesNonWhitespaceOutsideNode(range,
+ sa.getFirstSelectedNode(), document, scope);
}
private static boolean rangeIncludesNonWhitespaceOutsideNode(
@@ -117,10 +117,13 @@ public class ASTFragmentFactory {
* be <code>node</code>.
*
* XXX: more doc (current assertions about input vs. output)
+ *
+ * @param astFragment
*/
- public static IASTFragment createFragmentForFullSubtree(ASTNode node) {
- IASTFragment result = FragmentForFullSubtreeFactory
- .createFragmentFor(node);
+ public static IASTFragment createFragmentForFullSubtree(ASTNode node,
+ IASTFragment astFragment) {
+ IASTFragment result = FragmentForFullSubtreeFactory.createFragmentFor(
+ node, astFragment);
Assert.isNotNull(result);
return result;
}
@@ -160,7 +163,7 @@ public class ASTFragmentFactory {
fRange = range;
fScope = scope;
fDocument = document;
- IASTFragment result = createFragment(node);
+ IASTFragment result = createFragment(node, null);
if (modelException != null)
throw modelException;
return result;
@@ -176,8 +179,10 @@ public class ASTFragmentFactory {
private static class FragmentForFullSubtreeFactory extends FragmentFactory {
- public static IASTFragment createFragmentFor(ASTNode node) {
- return new FragmentForFullSubtreeFactory().createFragment(node);
+ public static IASTFragment createFragmentFor(ASTNode node,
+ IASTFragment astFragment) {
+ return new FragmentForFullSubtreeFactory().createFragment(node,
+ astFragment);
}
public boolean visit(InfixExpression node) {
@@ -190,6 +195,14 @@ public class ASTFragmentFactory {
.createFragmentForFullSubtree(node);
if (fragment == null)
return visit((Expression) node);
+ if (oldFragment instanceof AssociativeInfixExpressionFragment
+ && fragment instanceof AssociativeInfixExpressionFragment) {
+ AssociativeInfixExpressionFragment f1 = (AssociativeInfixExpressionFragment) oldFragment;
+ AssociativeInfixExpressionFragment f2 = (AssociativeInfixExpressionFragment) fragment;
+ if (f1.getOperands().size() != f2.getOperands().size()) {
+ return visit((Expression) node);
+ }
+ }
setFragment(fragment);
return false;
@@ -208,8 +221,11 @@ public class ASTFragmentFactory {
private static abstract class FragmentFactory extends HierarchicalVisitor {
private IASTFragment fFragment;
+ protected IASTFragment oldFragment;
- protected IASTFragment createFragment(ASTNode node) {
+ protected IASTFragment createFragment(ASTNode node,
+ IASTFragment astFragment) {
+ oldFragment = astFragment;
fFragment = null;
node.accept(this);
return fFragment;
@@ -233,4 +249,8 @@ public class ASTFragmentFactory {
}
}
+ public static IASTFragment createFragmentForFullSubtree(ASTNode node) {
+ return createFragmentForFullSubtree(node, null);
+ }
+
}
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/AssociativeInfixExpressionFragment.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/AssociativeInfixExpressionFragment.java
index 58d1a21..dd45376 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/AssociativeInfixExpressionFragment.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/AssociativeInfixExpressionFragment.java
@@ -66,13 +66,14 @@ public class AssociativeInfixExpressionFragment extends ASTFragment implements
if (!isAssociativeInfix(node))
return null;
+ // InfixExpression groupRoot = findGroupRoot(node);
InfixExpression groupRoot = findGroupRoot(node);
Assert.isTrue(isAGroupRoot(groupRoot));
List<Expression> groupMembers = AssociativeInfixExpressionFragment
.findGroupMembersInOrderFor(node);
- return new AssociativeInfixExpressionFragment(groupRoot, groupMembers);
+ return new AssociativeInfixExpressionFragment(node, groupMembers);
}
private static InfixExpression findGroupRoot(InfixExpression node) {
@@ -159,7 +160,7 @@ public class AssociativeInfixExpressionFragment extends ASTFragment implements
public IASTFragment[] getMatchingFragmentsWithNode(ASTNode node) {
IASTFragment fragmentForNode = ASTFragmentFactory
- .createFragmentForFullSubtree(node);
+ .createFragmentForFullSubtree(node, this);
if (fragmentForNode instanceof AssociativeInfixExpressionFragment) {
AssociativeInfixExpressionFragment kin = (AssociativeInfixExpressionFragment) fragmentForNode;
return kin.getSubFragmentsWithMyNodeMatching(this);
@@ -215,8 +216,8 @@ public class AssociativeInfixExpressionFragment extends ASTFragment implements
int startPosition = getStartPosition();
// TODO - Check if it's working
String source = fGroupRoot.getProgramRoot().getSourceModule()
- .getSource().substring(startPosition,
- getLength() + startPosition);
+ .getSource()
+ .substring(startPosition, getLength() + startPosition);
// String source= cu.getBuffer().getText(getStartPosition(),
// getLength());
return (Expression) rewrite.createStringPlaceholder(source,
@@ -288,7 +289,7 @@ public class AssociativeInfixExpressionFragment extends ASTFragment implements
private AssociativeInfixExpressionFragment(InfixExpression groupRoot,
List/* <Expression> */operands) {
- Assert.isTrue(isAGroupRoot(groupRoot));
+ // Assert.isTrue(isAGroupRoot(groupRoot));
Assert.isTrue(operands.size() >= 2);
fGroupRoot = groupRoot;
fOperands = Collections.unmodifiableList(operands);
@@ -355,8 +356,9 @@ public class AssociativeInfixExpressionFragment extends ASTFragment implements
IASTFragment[] result = new IASTFragment[0];
for (Iterator iter = getOperands().iterator(); iter.hasNext();) {
ASTNode operand = (ASTNode) iter.next();
- result = union(result, ASTMatchingFragmentFinder
- .findMatchingFragments(operand, (ASTFragment) toMatch));
+ result = union(result,
+ ASTMatchingFragmentFinder.findMatchingFragments(operand,
+ (ASTFragment) toMatch));
}
return result;
}
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/SimpleFragment.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/SimpleFragment.java
index ad0997e..834ab6b 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/SimpleFragment.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/corext/dom/fragments/SimpleFragment.java
@@ -31,8 +31,8 @@ class SimpleFragment extends ASTFragment {
if (!PHPASTMatcher.doNodesMatch(getAssociatedNode(), node))
return new IASTFragment[0];
- IASTFragment match = ASTFragmentFactory
- .createFragmentForFullSubtree(node);
+ IASTFragment match = ASTFragmentFactory.createFragmentForFullSubtree(
+ node, this);
Assert.isTrue(match.matches(this) || this.matches(match));
return new IASTFragment[] { match };
}