]> git.uio.no Git - ifi-stolz-refaktor.git/blobdiff - case-study/refaktor-after/src/no/uio/ifi/refaktor/analyze/analyzers/TextSelectionsGeneratorHelper.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / refaktor-after / src / no / uio / ifi / refaktor / analyze / analyzers / TextSelectionsGeneratorHelper.java
diff --git a/case-study/refaktor-after/src/no/uio/ifi/refaktor/analyze/analyzers/TextSelectionsGeneratorHelper.java b/case-study/refaktor-after/src/no/uio/ifi/refaktor/analyze/analyzers/TextSelectionsGeneratorHelper.java
new file mode 100644 (file)
index 0000000..7d7c134
--- /dev/null
@@ -0,0 +1,49 @@
+package no.uio.ifi.refaktor.analyze.analyzers;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import no.uio.ifi.refaktor.textselection.CompilationUnitTextSelection;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.Statement;
+
+public class TextSelectionsGeneratorHelper {
+
+       public final Set<CompilationUnitTextSelection> textSelections;
+       private final ICompilationUnit compilationUnit;
+       
+       private TextSelectionsGeneratorHelper(ICompilationUnit compilationUnit) {
+               this.compilationUnit = compilationUnit;
+               textSelections = new HashSet<CompilationUnitTextSelection>();
+       }
+
+       static Set<CompilationUnitTextSelection> generateSelectionsFromList(List<Statement> statements, ICompilationUnit compilationUnit) {
+               return new TextSelectionsGeneratorHelper(compilationUnit).generateSelectionsFromList(statements);
+       }
+
+       private Set<CompilationUnitTextSelection> generateSelectionsFromList(List<Statement> statements) {
+               for (Statement statement: statements)
+                       generateSelectionsFor(statement);
+               return textSelections;
+       }
+
+       private void generateSelectionsFor(Statement statement) {
+               Set<CompilationUnitTextSelection> newSelections = new HashSet<CompilationUnitTextSelection>();
+               CompilationUnitTextSelection textSelectionFromStatement = createTextSelectionFromStatement(statement);
+               textSelectionFromStatement.generated_1113821714625968249(newSelections, this);
+       }
+
+       private CompilationUnitTextSelection createTextSelectionFromStatement(Statement statement) {
+               return new CompilationUnitTextSelection(compilationUnit, statement.getStartPosition(), statement.getLength());
+       }
+
+       public static CompilationUnitTextSelection addTwoTextSelections(
+                       CompilationUnitTextSelection textSelectionOne, CompilationUnitTextSelection textSelectionTwo) {
+               int offset = Math.min(textSelectionOne.getOffset(), textSelectionTwo.getOffset());
+               int length = Math.max(textSelectionOne.getEnd(), textSelectionTwo.getEnd()) - offset;
+               return new CompilationUnitTextSelection(textSelectionOne.getCompilationUnit(), offset, length);
+       }
+
+}