mirror of
https://github.com/processing/processing4.git
synced 2026-02-14 02:45:36 +01:00
ironing out edge cases
This commit is contained in:
@@ -33,6 +33,7 @@ First major hurdle is offset mapping
|
||||
* pde<->java code offset : precise conversion needed
|
||||
x for the above, I've decide to first implement a sketch outline like feature, which would highlight an AST element precisely in the pde code. This would ensure I've got the mapping working properly. And may lead to a future feature.
|
||||
* This is precise upto a certain line. Once on a line, pde stuff have to be taken into consideration.
|
||||
x Edge case - multiple staetments in a single line
|
||||
* PDE specific enhancements will also have to be tackled like int(), # literals.
|
||||
|
||||
Refactoring would work only when code is compiler error free. I plan to do a find replace type op on the compile ready code.
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.eclipse.jdt.core.dom.QualifiedName;
|
||||
import org.eclipse.jdt.core.dom.SimpleName;
|
||||
import org.eclipse.jdt.core.dom.SimpleType;
|
||||
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
|
||||
import org.eclipse.jdt.core.dom.StringLiteral;
|
||||
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
|
||||
import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
|
||||
@@ -1760,7 +1761,15 @@ public class ASTGenerator {
|
||||
}
|
||||
|
||||
public static boolean isAddableASTNode(ASTNode node) {
|
||||
return true;
|
||||
switch (node.getNodeType()) {
|
||||
// case ASTNode.STRING_LITERAL:
|
||||
// case ASTNode.NUMBER_LITERAL:
|
||||
// case ASTNode.BOOLEAN_LITERAL:
|
||||
// case ASTNode.NULL_LITERAL:
|
||||
// return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package processing.mode.experimental;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
import org.eclipse.jdt.core.dom.ExpressionStatement;
|
||||
@@ -9,6 +12,7 @@ import org.eclipse.jdt.core.dom.MethodInvocation;
|
||||
import org.eclipse.jdt.core.dom.QualifiedName;
|
||||
import org.eclipse.jdt.core.dom.SimpleName;
|
||||
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
|
||||
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
|
||||
import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
|
||||
public class ASTNodeWrapper {
|
||||
@@ -58,8 +62,40 @@ public class ASTNodeWrapper {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new int[] {
|
||||
lineNumber, thisNode.getStartPosition(), nodeOffset, nodeLength };
|
||||
/*
|
||||
* There's an edge case here - multiple staetments in a single line.
|
||||
* After identifying the statement with the line number, I'll have to
|
||||
* look at previous tree nodes in the same level for same line number.
|
||||
* The correct line start offset would be the line start offset of
|
||||
* the first node with this line number.
|
||||
*
|
||||
* Using linear search for now. P.S: Eclipse AST iterators are messy.
|
||||
* TODO: binary search might improve speed by 0.001%?
|
||||
*/
|
||||
|
||||
int altStartPos = thisNode.getStartPosition();
|
||||
thisNode = thisNode.getParent();
|
||||
|
||||
Iterator<StructuralPropertyDescriptor> it = thisNode
|
||||
.structuralPropertiesForType().iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
StructuralPropertyDescriptor prop = (StructuralPropertyDescriptor) it
|
||||
.next();
|
||||
if (prop.isChildListProperty()) {
|
||||
List<ASTNode> nodelist = (List<ASTNode>) thisNode
|
||||
.getStructuralProperty(prop);
|
||||
for (ASTNode cnode : nodelist) {
|
||||
if (getLineNumber(cnode) == lineNumber) {
|
||||
altStartPos = cnode.getStartPosition();
|
||||
// System.out.println("multi...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// System.out.println("Altspos " + altStartPos);
|
||||
return new int[] { lineNumber,altStartPos , nodeOffset, nodeLength };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user