tools/java/src/stx/libjava/tools/source/JavaSourceHighlighter.java
branchdevelopment
changeset 2727 0d4d725cc712
parent 2723 02802ba0024f
--- a/tools/java/src/stx/libjava/tools/source/JavaSourceHighlighter.java	Wed Sep 11 11:35:14 2013 +0100
+++ b/tools/java/src/stx/libjava/tools/source/JavaSourceHighlighter.java	Wed Sep 11 11:36:27 2013 +0100
@@ -1,17 +1,25 @@
 package stx.libjava.tools.source;
 
 import org.eclipse.jdt.core.compiler.InvalidInputException;
+import org.eclipse.jdt.internal.compiler.ASTVisitor;
 import org.eclipse.jdt.internal.compiler.CompilationResult;
 import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
+import org.eclipse.jdt.internal.compiler.ast.ASTNode;
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.MessageSend;
+import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
+import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
 import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
 import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
 
 public class JavaSourceHighlighter extends JavaSourceParser {
     
     protected JavaSourceMarker marker;
+    protected JavaSourceIndexer indexer;
     
     public JavaSourceHighlighter() {
         this(new JavaSourceMarker() {            
@@ -42,12 +50,21 @@
     public JavaSourceMarker getMarker() {
         return marker;
     }
-
+    
     public void setMarker(JavaSourceMarker marker) {
         this.marker = marker;        
         ((Scanner)this.scanner).marker = marker;
     }
 
+    public JavaSourceIndexer getIndexer() {
+        return indexer;
+    }
+
+    public void setIndexer(JavaSourceIndexer indexer) {
+        this.indexer = indexer;
+    }
+
+
     public void initializeScanner(){
         this.scanner = new JavaSourceHighlighter.Scanner(
             false /*comment*/,
@@ -59,6 +76,71 @@
             this.options.taskPriorities/*taskPriorities*/,
             this.options.isTaskCaseSensitive/*taskCaseSensitive*/);
     }
+    
+    
+    public ASTNode[] parseClassBodyDeclarations(char[] source, int offset, int length, CompilationUnitDeclaration unit) {
+        ASTNode[] nodes = super.parseClassBodyDeclarations(source, offset, length, unit);
+        Visitor v = new Visitor();
+        v.setMarker(marker);
+        v.setIndexer(indexer);
+        for (int i = 0; i < nodes.length; i++) {
+            ASTNode n = nodes[i];
+            if (n instanceof MethodDeclaration) {
+                ((MethodDeclaration)n).traverse(v, (ClassScope)null);
+            } else {
+                nodes[i].traverse(v, null);
+            }
+        }
+        return nodes;
+    }
+
+    
+    public static class Visitor extends ASTVisitor {
+        protected JavaSourceMarker marker;        
+        protected JavaSourceIndexer indexer;
+
+        public JavaSourceMarker getMarker() {
+            return marker;
+        }
+
+        public void setMarker(JavaSourceMarker marker) {
+            this.marker = marker;
+        }
+
+        public JavaSourceIndexer getIndexer() {
+            return indexer;
+        }
+
+        public void setIndexer(JavaSourceIndexer indexer) {
+            this.indexer = indexer;
+        }
+        
+        public boolean visit(MessageSend messageSend, BlockScope scope) {
+            int start = (int)(messageSend.nameSourcePosition >>> 32);
+            int stop  = (int)(messageSend.nameSourcePosition & 0x0000FFFF);
+            marker.mark(JavaSourceMarker.MARK_SELECTOR, start, stop);                                                            
+            return true; // continue visiting
+        }
+        
+        public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
+            int start = methodDeclaration.sourceStart;
+            int stop  = start + methodDeclaration.selector.length - 1;
+            marker.mark(JavaSourceMarker.MARK_SELECTOR, start, stop);
+            return true; // do nothing by default, keep traversing
+        }
+        
+        public boolean visit(
+                ConstructorDeclaration constructorDeclaration,
+                ClassScope scope) {
+            int start = constructorDeclaration.sourceStart;
+            int stop  = start + constructorDeclaration.selector.length - 1;
+            marker.mark(JavaSourceMarker.MARK_SELECTOR, start, stop);
+
+            return true; // do nothing by default, keep traversing
+        }
+
+        
+    }
         
     public static class Scanner extends org.eclipse.jdt.internal.compiler.parser.Scanner {
         
@@ -127,6 +209,7 @@
             case TokenNameinstanceof:
             case TokenNameinterface:
             case TokenNamelong:
+            case TokenNameint:
             case TokenNamenative:
             case TokenNamenew:
             case TokenNamenull: