]> git.uio.no Git - ifi-stolz-refaktor.git/blobdiff - case-study/jdt-after/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/NameCollector.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / core refactoring / org / eclipse / jdt / internal / corext / refactoring / code / NameCollector.java
diff --git a/case-study/jdt-after/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/NameCollector.java b/case-study/jdt-after/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/NameCollector.java
new file mode 100644 (file)
index 0000000..53a619d
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.corext.refactoring.code;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.TypeDeclarationStatement;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+
+import org.eclipse.jdt.internal.corext.dom.GenericVisitor;
+import org.eclipse.jdt.internal.corext.dom.Selection;
+
+public class NameCollector extends GenericVisitor {
+       private List<String> names= new ArrayList<String>();
+       public Selection fSelection;
+       public NameCollector(ASTNode node) {
+               fSelection= Selection.createFromStartLength(node.getStartPosition(), node.getLength());
+       }
+       @Override
+       protected boolean visitNode(ASTNode node) {
+               return fSelection.generated_4721085911331191808(node);
+       }
+       @Override
+       public boolean visit(SimpleName node) {
+               names.add(node.getIdentifier());
+               return super.visit(node);
+       }
+       @Override
+       public boolean visit(VariableDeclarationStatement node) {
+               return true;
+       }
+       @Override
+       public boolean visit(VariableDeclarationFragment node) {
+               boolean result= super.visit(node);
+               if (!result)
+                       names.add(node.getName().getIdentifier());
+               return result;
+       }
+       @Override
+       public boolean visit(SingleVariableDeclaration node) {
+               boolean result= super.visit(node);
+               if (!result)
+                       names.add(node.getName().getIdentifier());
+               return result;
+       }
+       @Override
+       public boolean visit(TypeDeclarationStatement node) {
+               names.add(node.getDeclaration().getName().getIdentifier());
+               return false;
+       }
+
+    List<String> getNames() {
+        return names;
+    }
+}