From af3dca32847ec5b3363f946db029e62fab590fcf Mon Sep 17 00:00:00 2001 From: Erlend Kristiansen Date: Thu, 27 Feb 2014 17:44:59 +0100 Subject: [PATCH] TextSelectionsGenerator: now handling labeled statements --- .../ifi/refaktor/tests/TextSelectionsGeneratorTest.java | 5 +++++ .../refaktor/analyze/analyzers/StatementListsCreator.java | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/TextSelectionsGeneratorTest.java b/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/TextSelectionsGeneratorTest.java index 3147d3b6..177b64ba 100644 --- a/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/TextSelectionsGeneratorTest.java +++ b/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/TextSelectionsGeneratorTest.java @@ -68,6 +68,11 @@ public class TextSelectionsGeneratorTest { new S(69, 12), new S(96, 12), new S(129, 12), new S(163, 12), new S(187, 8), new S(149, 46)); } + @Test + public void testContainingLabel() throws Exception { + assertThatMethodContainsSelections("containingLabel", new S(53, 28), new S(84, 16), new S(53, 47), new S(65, 12), new S(92, 8)); + } + private void assertThatMethodContainsSelections(String methodName, S... methodRelativeSelections) throws JavaModelException { IMethod enclosingMethod = getTestDataMethod(methodName); assertThat(enclosingMethod.exists()); diff --git a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/analyze/analyzers/StatementListsCreator.java b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/analyze/analyzers/StatementListsCreator.java index e6e652b1..aa86d56c 100644 --- a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/analyze/analyzers/StatementListsCreator.java +++ b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/analyze/analyzers/StatementListsCreator.java @@ -19,6 +19,7 @@ import org.eclipse.jdt.core.dom.DoStatement; import org.eclipse.jdt.core.dom.EnhancedForStatement; import org.eclipse.jdt.core.dom.ForStatement; import org.eclipse.jdt.core.dom.IfStatement; +import org.eclipse.jdt.core.dom.LabeledStatement; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.Statement; import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; @@ -110,4 +111,10 @@ public class StatementListsCreator extends ASTVisitor { addIfNotBlockOrNull(node.getElseStatement()); return true; } + + @Override + public boolean visit(LabeledStatement node) { + addIfNotBlockOrNull(node.getBody()); + return true; + } } \ No newline at end of file -- 2.43.5