Offset mapping bug fix. Definitely getting better.

This commit is contained in:
Manindra Moharana
2013-06-23 12:02:00 +05:30
parent 54e08667b4
commit fed19cf712
3 changed files with 18 additions and 17 deletions

View File

@@ -26,17 +26,17 @@ Finer details
* Sorted list of completion candidates - fields, then methods. It's unsorted presently.
*! p5 enhanced stuff in java, how does it fit in with everything else, and edge cases. Possibly add support for them.
* Reflection API - getMethods vs getDeclaredMethods.
* Need to add offset correction to ASTGenerator and its lookup methods. Or leave it for later?
Refactoring
Offset Mapping & Refactoring
===========
First major hurdle is offset mapping
* pde<->java code offset : precise conversion needed
*! 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 statements in a single line
x PDE specific enhancements will also have to be tackled like int(), # literals. The length of the node returned needs to be modified to make up for extra chars added like PApplet.parseFloat, etc. Also the 2nd or futher pde enhancements in the same line means even the beginning offset would need adjustment. Meh.
* The above is almost working. There are some offset issues when multiple pde statements are in the same line, but I guess it's good enough for now to proceed ahead. Will look into later.
* The above is almost working. There are some offset issues when multiple pde statements are in the same line, but I guess it's good enough for now to proceed ahead. Will keep a close watch for potential bugs.
Refactoring would work only when code is compiler error free. I plan to do a find replace type op on the compile ready code.
1. First identify the declaration of the variable in the AST.
@@ -45,7 +45,7 @@ Refactoring would work only when code is compiler error free. I plan to do a fin
4. All the changes in code would be made in a separate copy of the code(?). After all the renaming is done, allow it only if the new code compiles. Basically an undo should be possible in case of conflicts.
Quick Navigation
==============
================
x Ctrl + Click on an element to scroll to its definition in code
x Local Vars
x Local Methods

View File

@@ -1010,8 +1010,9 @@ public class ASTGenerator {
System.out.println("+> " + lineNode);
ASTNode decl = null;
if (lineNode != null) {
System.out.println("FLON2: " + lineNumber + " LN O "
+ lineNode.getStartPosition());
ASTNodeWrapper lineNodeWrap = new ASTNodeWrapper(lineNode);
System.out.println("FLON2: " + lineNumber + " LN spos "
+ lineNode.getStartPosition() + " off " + offset);
ASTNode simpName = pinpointOnLine(lineNode, offset,
lineNode.getStartPosition(), name);
System.out.println("+++> " + simpName);
@@ -1128,10 +1129,8 @@ public class ASTGenerator {
int pdeoffsets[] = awrap.getPDECodeOffsets(errorCheckerService);
int javaoffsets[] = awrap.getJavaCodeOffsets(errorCheckerService);
ErrorCheckerService.scrollToErrorLine(editor, pdeoffsets[0],
pdeoffsets[1],
javaoffsets[2]
- javaoffsets[1],
javaoffsets[3]);
pdeoffsets[1],javaoffsets[1],
javaoffsets[2]);
}
}
};

View File

@@ -115,7 +115,7 @@ public class ASTNodeWrapper {
String pdeCode = ecs.getPDECode(pdeoffsets[1] - 1).trim();
int vals[] = createOffsetMapping(pdeCode,nodeOffset - altStartPos,nodeLength);
return new int[] {
lineNumber, altStartPos, nodeOffset + vals[0], vals[1]};
lineNumber, nodeOffset + vals[0] - altStartPos, vals[1]};
}
@@ -127,10 +127,10 @@ public class ASTNodeWrapper {
* The main issue here is that pde enhancements like color vars, # literals
* and int() type casting deviate from standard java. But I need to exact
* index matching for pde and java versions of snippets.For ex:
* "color col = #ffaadd;" <-PDE version "int col = 0xffffaadd;" <-Converted
* to Java
* "color col = #ffaadd;" <-PDE version
* "int col = 0xffffaadd;" <-Converted to Java
*
* For exact index mapping, I need to know at what indices either is
* For exact index mapping, I need to know at which indices either is
* deviating from the other and by what amount. Turns out, it isn't quite
* easy.(1) First I take the pde version of the code as an argument(pde
* version fetched from the editor directly). I then find all instances
@@ -217,11 +217,12 @@ public class ASTNodeWrapper {
int javaCodeMap[] = new int[source.length() * 2];
int pdeCodeMap[] = new int[source.length() * 2];
int pi = 1, pj = 1;
int keySum = 0;
for (Integer key : offsetmap.keySet()) {
for (; pi < key; pi++) {
for (; pi < key +keySum; pi++) {
javaCodeMap[pi] = javaCodeMap[pi - 1] + 1;
}
for (; pj < key; pj++) {
for (; pj < key+keySum; pj++) {
pdeCodeMap[pj] = pdeCodeMap[pj - 1] + 1;
}
@@ -245,6 +246,7 @@ public class ASTNodeWrapper {
pdeCodeMap[pj] = pdeCodeMap[pj - 1];
}
}
keySum += kval;
}
javaCodeMap[pi] = javaCodeMap[pi - 1] + 1;