--- a/tools/java/src/stx/libjava/tools/text/Highlighter.java Thu Oct 03 15:30:51 2013 +0100
+++ b/tools/java/src/stx/libjava/tools/text/Highlighter.java Thu Oct 03 17:36:36 2013 +0100
@@ -1,35 +1,36 @@
package stx.libjava.tools.text;
-import net.sf.jasperreports.components.sort.FieldFilter;
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.Argument;
import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
-import org.eclipse.jdt.internal.compiler.ast.ArrayReference;
import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference;
+import org.eclipse.jdt.internal.compiler.ast.Assignment;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
import org.eclipse.jdt.internal.compiler.ast.FieldReference;
+import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
+import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
-import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
-import stx.libjava.tools.environment.Resolver;
import stx.libjava.tools.parser.Parser;
public class Highlighter extends Parser {
@@ -39,15 +40,10 @@
public Highlighter() {
this(new Marker() {
- @Override
- public void mark(int kind, int from, int to) {
- }
+
},
new Indexer() {
-
- @Override
- public void index(ASTNode node, int from, int to) {
- }
+
});
}
@@ -150,34 +146,51 @@
public void endVisit(FieldDeclaration fieldDeclaration, MethodScope scope) {
marker.mark(Marker.MARK_FIELD, fieldDeclaration.sourceStart, fieldDeclaration.sourceEnd);
- indexer.index(fieldDeclaration, fieldDeclaration.sourceStart, fieldDeclaration.sourceEnd);
+ indexer.addFieldDeclaration(fieldDeclaration, fieldDeclaration.sourceStart, fieldDeclaration.sourceEnd);
+ }
+
+ public void endVisit(LocalDeclaration localDeclaration, BlockScope scope) {
+ marker.mark(Marker.MARK_LOCAL, localDeclaration.sourceStart, localDeclaration.sourceEnd);
+ indexer.addLocalDeclaration(localDeclaration, localDeclaration.sourceStart, localDeclaration.sourceEnd);
}
+ public void endVisit(Argument localDeclaration, BlockScope scope) {
+ marker.mark(Marker.MARK_LOCAL, localDeclaration.sourceStart, localDeclaration.sourceEnd);
+ indexer.addLocalDeclaration(localDeclaration, localDeclaration.sourceStart, localDeclaration.sourceEnd);
+ }
+
+
public void endVisit(FieldReference fieldReference, BlockScope scope) {
int start = (int)(fieldReference.nameSourcePosition >>> 32);
- int stop = (int)(fieldReference.nameSourcePosition & 0x0000FFFF);
+ int stop = (int)(fieldReference.nameSourcePosition & 0x0000FFFFFFFF);
marker.mark(Marker.MARK_FIELD, start, stop);
- indexer.index(fieldReference, start, stop);
+ indexer.addVariableReference(fieldReference, start, stop);
}
public void endVisit(FieldReference fieldReference, ClassScope scope) {
int start = (int)(fieldReference.nameSourcePosition >>> 32);
- int stop = (int)(fieldReference.nameSourcePosition & 0x0000FFFF);
+ int stop = (int)(fieldReference.nameSourcePosition & 0x0000FFFFFFFF);
marker.mark(Marker.MARK_FIELD, start, stop);
- indexer.index(fieldReference, start, stop);
+ indexer.addVariableReference(fieldReference, start, stop);
}
public void endVisit(MessageSend messageSend, BlockScope scope) {
int start = (int)(messageSend.nameSourcePosition >>> 32);
- int stop = (int)(messageSend.nameSourcePosition & 0x0000FFFF);
+ int stop = (int)(messageSend.nameSourcePosition & 0x0000FFFFFFFF);
marker.mark(Marker.MARK_SELECTOR, start, stop);
- indexer.index(messageSend, start, stop);
+ indexer.addMessageSend(messageSend, start, stop);
+ }
+
+ public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
+ int start = methodDeclaration.sourceStart;
+ int stop = start + methodDeclaration.selector.length - 1;
+ marker.mark(Marker.MARK_SELECTOR, start, stop);
+ indexer.methodEnter(methodDeclaration);
+ return true;
}
public void endVisit(MethodDeclaration methodDeclaration, ClassScope scope) {
- int start = methodDeclaration.sourceStart;
- int stop = start + methodDeclaration.selector.length - 1;
- marker.mark(Marker.MARK_SELECTOR, start, stop);
+ indexer.methodLeave(methodDeclaration);
}
public void endVisit(
@@ -193,7 +206,7 @@
if (type.token == TypeBinding.INT.simpleName) return;
if (type.token == TypeBinding.LONG.simpleName) return;
marker.mark(Marker.MARK_CLASS, type.sourceStart, type.sourceEnd);
- indexer.index(type, type.sourceStart, type.sourceEnd);
+ indexer.addTypeReference(type, type.sourceStart, type.sourceEnd);
}
public void endVisit(
@@ -209,7 +222,7 @@
if (type.token == TypeBinding.INT.simpleName) return;
if (type.token == TypeBinding.LONG.simpleName) return;
marker.mark(Marker.MARK_CLASS, type.sourceStart, type.sourceEnd);
- indexer.index(type, type.sourceStart, type.sourceEnd);
+ indexer.addTypeReference(type, type.sourceStart, type.sourceEnd);
}
@@ -224,7 +237,7 @@
if (type.token == TypeBinding.INT.simpleName) return;
if (type.token == TypeBinding.LONG.simpleName) return;
marker.mark(Marker.MARK_CLASS, type.sourceStart, type.sourceEnd);
- indexer.index(type, type.sourceStart, type.sourceEnd);
+ indexer.addTypeReference(type, type.sourceStart, type.sourceEnd);
}
public void endVisit(ArrayTypeReference type, ClassScope scope) {
if (type.token == TypeBinding.VOID.simpleName) return;
@@ -237,40 +250,92 @@
if (type.token == TypeBinding.INT.simpleName) return;
if (type.token == TypeBinding.LONG.simpleName) return;
marker.mark(Marker.MARK_CLASS, type.sourceStart, type.sourceEnd);
- indexer.index(type, type.sourceStart, type.sourceEnd);
+ indexer.addTypeReference(type, type.sourceStart, type.sourceEnd);
+ }
+
+ protected void breakpoint() {}
+
+ public void endVisit(
+ SingleNameReference ref,
+ BlockScope scope) {
+ if (ref.binding == null) {
+ breakpoint();
+ ref.resolve(scope);
+ }
+
+ boolean isField = (ref.bits & ASTNode.RestrictiveFlagMASK) == Binding.FIELD;
+ if (isField) {
+ marker.mark(Marker.MARK_FIELD, ref.sourceStart, ref.sourceEnd);
+ }
+ indexer.addVariableReference(ref, ref.sourceStart, ref.sourceEnd);
}
+
+ public void endVisit(
+ QualifiedNameReference ref,
+ BlockScope scope) {
+ if (ref.binding == null) ref.resolve(scope);
+/*
+ Binding[] bindings = ref.getOtherFieldBindings(scope);
+ for (int i = 0; i < bindings.length; i++) {
+ Binding
+ }
+
+ boolean isField = (ref.bits & ASTNode.RestrictiveFlagMASK) == Binding.FIELD;
+ if (isField) {
+ marker.mark(Marker.MARK_FIELD, ref.sourceStart, ref.sourceEnd);
+ }
+ indexer.addVariableReference(ref, ref.sourceStart, ref.sourceEnd);
+*/
+ }
+
+ public void endVisit(Assignment assignment, BlockScope scope) {
+ if ((assignment.lhs.bits & ASTNode.RestrictiveFlagMASK) == Binding.FIELD) {
+ marker.mark(Marker.MARK_FIELD_ASSIGNED, assignment.lhs.sourceStart, assignment.lhs.sourceEnd);
+ }
+ }
+
+
public void endVisit(
ArrayQualifiedTypeReference type,
BlockScope scope) {
marker.mark(Marker.MARK_CLASS, type.sourceStart, type.sourceEnd);
- indexer.index(type, type.sourceStart, type.sourceEnd);
+ indexer.addTypeReference(type, type.sourceStart, type.sourceEnd);
}
public void endVisit(
ArrayQualifiedTypeReference type,
ClassScope scope) {
marker.mark(Marker.MARK_CLASS, type.sourceStart, type.sourceEnd);
- indexer.index(type, type.sourceStart, type.sourceEnd);
+ indexer.addTypeReference(type, type.sourceStart, type.sourceEnd);
}
public void endVisit(
QualifiedTypeReference type,
- BlockScope scope) {
+ BlockScope scope) {
marker.mark(Marker.MARK_CLASS, type.sourceStart, type.sourceEnd);
- indexer.index(type, type.sourceStart, type.sourceEnd);
+ indexer.addTypeReference(type, type.sourceStart, type.sourceEnd);
}
public void endVisit(
QualifiedTypeReference type,
ClassScope scope) {
marker.mark(Marker.MARK_CLASS, type.sourceStart, type.sourceEnd);
- indexer.index(type, type.sourceStart, type.sourceEnd);
+ indexer.addTypeReference(type, type.sourceStart, type.sourceEnd);
}
+ public boolean visit(
+ ConstructorDeclaration constructorDeclaration,
+ ClassScope scope) {
+ indexer.methodEnter(constructorDeclaration);
+ return true;
+ }
+
+
public void endVisit(
ConstructorDeclaration constructorDeclaration,
ClassScope scope) {
+ indexer.methodLeave(constructorDeclaration);
int start = constructorDeclaration.sourceStart;
int stop = start + constructorDeclaration.selector.length - 1;
marker.mark(Marker.MARK_SELECTOR, start, stop);
@@ -327,7 +392,8 @@
case TokenNamecase:
case TokenNamereturn:
marker.mark(Marker.MARK_KEYWORD_FLOW, getCurrentTokenStartPosition(), getCurrentTokenEndPosition());
- break;
+ break;
+ case TokenNameabstract:
case TokenNameassert:
case TokenNameboolean:
case TokenNamebyte:
--- a/tools/java/src/stx/libjava/tools/text/Indexer.java Thu Oct 03 15:30:51 2013 +0100
+++ b/tools/java/src/stx/libjava/tools/text/Indexer.java Thu Oct 03 17:36:36 2013 +0100
@@ -1,6 +1,13 @@
package stx.libjava.tools.text;
-import org.eclipse.jdt.internal.compiler.ast.ASTNode;
+import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.MessageSend;
+import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.Reference;
+import org.eclipse.jdt.internal.compiler.ast.TypeReference;
+
public abstract class Indexer {
@@ -8,7 +15,47 @@
* Add given @param node to the index.
*
* @param node node to add to the index.
+ * @param from start position of the node (its relevant part for highlighting/navigation)
+ * @param to stop position of the node (its relevant part for highlighting/navigation)
+ *
*/
- public abstract void index(ASTNode node, int from, int to);
+ public void addFieldDeclaration(FieldDeclaration node, int from, int to) {}
+
+ /**
+ * Same as {@link #addFieldDeclaration(FieldDeclaration, int, int)} but for local variables
+ * (temporaries and arguments)
+ */
+ public void addLocalDeclaration(LocalDeclaration node, int from, int to) {}
+
+
+ /**
+ * Same as {@link #addFieldDeclaration(FieldDeclaration, int, int)} but for types
+ */
+ public void addTypeReference(TypeReference node, int from, int to) {}
+
+ /**
+ * Same as {@link #addFieldDeclaration(FieldDeclaration, int, int)} but for name references
+ * (variables, fields)
+ */
+ public void addVariableReference(Reference node, int from, int to) {}
+
+ /**
+ * Same as {@link #addFieldDeclaration(FieldDeclaration, int, int)} but for method
+ * invocations
+ */
+ public void addMessageSend(MessageSend node, int from, int to) {}
+
+ /**
+ * Called whenever a method is entered, i.e., before its arguments and
+ * statements are visited.
+ */
+ public void methodEnter(AbstractMethodDeclaration method) {}
+
+ /**
+ * Called whenever a method is left, i.e., after all its arguments and
+ * statements are visited.
+ */
+ public void methodLeave(AbstractMethodDeclaration method) {}
+
}