From 0632309fc0bba2e035c96a0812f01b999f595a0e Mon Sep 17 00:00:00 2001 From: Manindra Moharana Date: Sun, 23 Feb 2014 03:12:10 +0530 Subject: [PATCH] lookin into jdoc scroll bug, irritating one this --- .../mode/experimental/ASTGenerator.java | 5 +- .../mode/experimental/ASTNodeWrapper.java | 83 ++++++++++++++++++- .../experimental/ErrorCheckerService.java | 4 + 3 files changed, 88 insertions(+), 4 deletions(-) diff --git a/pdex/src/processing/mode/experimental/ASTGenerator.java b/pdex/src/processing/mode/experimental/ASTGenerator.java index 4d7602eaa..1d2a05297 100644 --- a/pdex/src/processing/mode/experimental/ASTGenerator.java +++ b/pdex/src/processing/mode/experimental/ASTGenerator.java @@ -235,7 +235,10 @@ public class ASTGenerator { } - public static final boolean SHOWAST = !true; + /** + * Toggle AST View window + */ + public static final boolean SHOWAST = true; protected DefaultMutableTreeNode buildAST(String source, CompilationUnit cu) { if (cu == null) { diff --git a/pdex/src/processing/mode/experimental/ASTNodeWrapper.java b/pdex/src/processing/mode/experimental/ASTNodeWrapper.java index b980f1518..340f956c3 100644 --- a/pdex/src/processing/mode/experimental/ASTNodeWrapper.java +++ b/pdex/src/processing/mode/experimental/ASTNodeWrapper.java @@ -29,6 +29,7 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.ExpressionStatement; import org.eclipse.jdt.core.dom.FieldDeclaration; +import org.eclipse.jdt.core.dom.Javadoc; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.QualifiedName; @@ -99,6 +100,7 @@ public class ASTNodeWrapper { public int[] getJavaCodeOffsets(ErrorCheckerService ecs) { int nodeOffset = Node.getStartPosition(), nodeLength = Node .getLength(); + log("0.nodeOffset " + nodeOffset); ASTNode thisNode = Node; while (thisNode.getParent() != null) { if (getLineNumber(thisNode.getParent()) == lineNumber) { @@ -119,8 +121,34 @@ public class ASTNodeWrapper { */ int altStartPos = thisNode.getStartPosition(); + log("1.Altspos " + altStartPos); thisNode = thisNode.getParent(); + int jdocOffset; Javadoc jd = null; + if(thisNode instanceof TypeDeclaration){ + jd = ((TypeDeclaration)thisNode).getJavadoc(); + log("Has t jdoc " + ((TypeDeclaration)thisNode).getJavadoc()); + } else if(thisNode instanceof MethodDeclaration){ + jd = ((MethodDeclaration)thisNode).getJavadoc(); + log("Has m jdoc " + jd); + } else if(thisNode instanceof FieldDeclaration){ + jd = ((FieldDeclaration)thisNode).getJavadoc(); + log("Has f jdoc " + ((FieldDeclaration)thisNode).getJavadoc()); + } + + if(jd != null){ + jdocOffset = jd.getLength(); + log("jdoc offset: " + jdocOffset); + while (thisNode.getParent() != null) { + if (getLineNumber2(thisNode.getParent()) == getLineNumber2(getNode())) { + thisNode = thisNode.getParent(); + } else { + break; + } + } + //thisNode = thisNode.getParent(); + } + log("Visiting children of node " + getNodeAsString(thisNode)); Iterator it = thisNode .structuralPropertiesForType().iterator(); boolean flag = true; @@ -130,15 +158,17 @@ public class ASTNodeWrapper { if (prop.isChildListProperty()) { List nodelist = (List) thisNode .getStructuralProperty(prop); + log("prop " + prop); for (ASTNode cnode : nodelist) { - if (getLineNumber(cnode) == lineNumber) { + log("Visiting node " + getNodeAsString(cnode)); + if (getLineNumber2(cnode) == lineNumber) { if (flag) { altStartPos = cnode.getStartPosition(); // log("multi..."); flag = false; } else { - if(cnode == Node){ + if (cnode == Node) { // loop only till the current node. break; } @@ -159,10 +189,36 @@ public class ASTNodeWrapper { if (vals != null) return new int[] { lineNumber, nodeOffset + vals[0] - altStartPos, vals[1] }; - else + else {// no offset mapping needed + log("joff[1] = " + (nodeOffset - altStartPos)); return new int[] { lineNumber, nodeOffset - altStartPos, nodeLength }; + } } + private boolean hasJavaDoc(ASTNode node){ + if(node != null){ + Iterator it = node + .structuralPropertiesForType().iterator(); + log("Checkin for javadoc in child node of " + getNodeAsString(node)); + while (it.hasNext()) { + StructuralPropertyDescriptor prop = (StructuralPropertyDescriptor) it + .next(); + if (prop.isChildListProperty()) { + List nodelist = (List) node + .getStructuralProperty(prop); + log("prop " + prop); + for (ASTNode cnode : nodelist) { + log("Visiting node " + getNodeAsString(cnode)); + if(cnode instanceof Javadoc){ + log("Visiting jdoc " + cnode); + return true; + } + } + } + } + } + return false; + } /** * Finds the difference in pde and java code offsets @@ -492,6 +548,27 @@ public class ASTNodeWrapper { return ((CompilationUnit) node.getRoot()).getLineNumber(node .getStartPosition()); } + + private static int getLineNumber2(ASTNode thisNode) { + int jdocOffset = 0; Javadoc jd = null; + if(thisNode instanceof TypeDeclaration){ + jd = ((TypeDeclaration)thisNode).getJavadoc(); + log("Has t jdoc " + ((TypeDeclaration)thisNode).getJavadoc()); + } else if(thisNode instanceof MethodDeclaration){ + jd = ((MethodDeclaration)thisNode).getJavadoc(); + log("Has m jdoc " + jd); + } else if(thisNode instanceof FieldDeclaration){ + jd = ((FieldDeclaration)thisNode).getJavadoc(); + log("Has f jdoc " + ((FieldDeclaration)thisNode).getJavadoc()); + } + if(jd != null){ + jdocOffset = 1+jd.getLength(); + } + log("ln 2 = " + ((CompilationUnit) thisNode.getRoot()).getLineNumber(thisNode + .getStartPosition() + jdocOffset)); + return ((CompilationUnit) thisNode.getRoot()).getLineNumber(thisNode + .getStartPosition() + jdocOffset); + } static private String getNodeAsString(ASTNode node) { if (node == null) diff --git a/pdex/src/processing/mode/experimental/ErrorCheckerService.java b/pdex/src/processing/mode/experimental/ErrorCheckerService.java index 307cd3b53..cc3d3655a 100644 --- a/pdex/src/processing/mode/experimental/ErrorCheckerService.java +++ b/pdex/src/processing/mode/experimental/ErrorCheckerService.java @@ -1278,9 +1278,13 @@ public class ErrorCheckerService implements Runnable{ * @return true - if highlighting happened correctly. */ public boolean highlightNode(ASTNodeWrapper awrap){ + log("Highlighting: " + awrap); try { int pdeoffsets[] = awrap.getPDECodeOffsets(this); int javaoffsets[] = awrap.getJavaCodeOffsets(this); + log("offsets: " +pdeoffsets[0] + "," + + pdeoffsets[1]+ "," +javaoffsets[1]+ "," + + javaoffsets[2]); scrollToErrorLine(editor, pdeoffsets[0], pdeoffsets[1],javaoffsets[1], javaoffsets[2]);