mirror of
https://github.com/processing/processing4.git
synced 2026-01-30 03:41:15 +01:00
ECS + ASTGen: fix minor mapping inaccuracies
This commit is contained in:
@@ -1024,12 +1024,10 @@ public class ASTGenerator {
|
||||
* @param scrollOnly
|
||||
* @return
|
||||
*/
|
||||
public ASTNode getASTNodeAt(int offset) {
|
||||
public ASTNode getASTNodeAt(int javaOffset) {
|
||||
Messages.log("* getASTNodeAt");
|
||||
|
||||
PreprocessedSketch ps = errorCheckerService.latestResult;
|
||||
int tabIndex = ps.sketch.getCodeIndex(editor.getCurrentTab());
|
||||
int javaOffset = ps.tabOffsetToJavaOffset(tabIndex, offset);
|
||||
ASTNode node = NodeFinder.perform(ps.compilationUnit, javaOffset, 0);
|
||||
|
||||
if (node == null) {
|
||||
@@ -1235,10 +1233,11 @@ public class ASTGenerator {
|
||||
return lastClickedWord;
|
||||
}
|
||||
|
||||
public void setLastClickedWord(int offset, String lastClickedWord) {
|
||||
public void setLastClickedWord(int tabIndex, int offset, String lastClickedWord) {
|
||||
Messages.log("* setLastClickedWord");
|
||||
this.lastClickedWord = lastClickedWord;
|
||||
lastClickedWordNode = getASTNodeAt(offset);
|
||||
int javaOffset = errorCheckerService.latestResult.tabOffsetToJavaOffset(tabIndex, offset);
|
||||
lastClickedWordNode = getASTNodeAt(javaOffset); // TODO: don't call this on EDT
|
||||
log("Last clicked node: " + lastClickedWordNode);
|
||||
}
|
||||
|
||||
@@ -1256,9 +1255,13 @@ public class ASTGenerator {
|
||||
+ (ta.getSelectionStart() - ta.getLineStartOffset(line))
|
||||
+ ", "
|
||||
+ (ta.getSelectionStop() - ta.getLineStartOffset(line)));
|
||||
int tabIndex = editor.getSketch().getCurrentCodeIndex();
|
||||
int offset = ta.getSelectionStart();
|
||||
int javaOffset =
|
||||
errorCheckerService.latestResult.tabOffsetToJavaOffset(tabIndex, offset);
|
||||
ASTNode wnode;
|
||||
if (lastClickedWord == null || lastClickedWordNode == null) {
|
||||
wnode = getASTNodeAt(ta.getSelectionStart());
|
||||
wnode = getASTNodeAt(javaOffset);
|
||||
}
|
||||
else{
|
||||
wnode = lastClickedWordNode;
|
||||
@@ -2150,7 +2153,7 @@ public class ASTGenerator {
|
||||
value = ((MethodInvocation) node).getName().toString() + " | "
|
||||
+ className;
|
||||
else if (node instanceof FieldDeclaration)
|
||||
value = node.toString() + " FldDecl| ";
|
||||
value = node.toString() + " FldDecl | ";
|
||||
else if (node instanceof SingleVariableDeclaration)
|
||||
value = ((SingleVariableDeclaration) node).getName() + " - "
|
||||
+ ((SingleVariableDeclaration) node).getType() + " | SVD ";
|
||||
@@ -2165,7 +2168,7 @@ public class ASTGenerator {
|
||||
else if (className.startsWith("Variable"))
|
||||
value = node.toString() + " | " + className;
|
||||
else if (className.endsWith("Type"))
|
||||
value = node.toString() + " |" + className;
|
||||
value = node.toString() + " | " + className;
|
||||
value += " [" + node.getStartPosition() + ","
|
||||
+ (node.getStartPosition() + node.getLength()) + "]";
|
||||
value += " Line: "
|
||||
@@ -2698,16 +2701,22 @@ public class ASTGenerator {
|
||||
/// Editor stuff -------------------------------------------------------------
|
||||
|
||||
|
||||
public void scrollToDeclaration(int offset, String name) {
|
||||
// Thread: EDT
|
||||
public void scrollToDeclaration(int tabIndex, int offset, String name) {
|
||||
Messages.log("* scrollToDeclaration");
|
||||
|
||||
ASTNode node = getASTNodeAt(offset);
|
||||
// TODO: don't run the heavy lifting on EDT
|
||||
|
||||
PreprocessedSketch ps = errorCheckerService.latestResult;
|
||||
|
||||
int javaOffset = ps.tabOffsetToJavaOffset(tabIndex, offset);
|
||||
|
||||
ASTNode node = getASTNodeAt(javaOffset);
|
||||
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PreprocessedSketch ps = errorCheckerService.latestResult;
|
||||
|
||||
IBinding binding = resolveBinding(node);
|
||||
if (binding == null) {
|
||||
|
||||
@@ -1010,10 +1010,18 @@ public class ErrorCheckerService {
|
||||
|
||||
int startPdeOffset = ps.javaOffsetToPdeOffset(startJavaOffset);
|
||||
|
||||
int stopPdeOffset = javaLength == 0 ?
|
||||
startPdeOffset :
|
||||
// Make the stop inclusive for the purpose of mapping
|
||||
ps.javaOffsetToPdeOffset(stopJavaOffset - 1) + 1;
|
||||
int stopPdeOffset;
|
||||
|
||||
if (javaLength == 0) {
|
||||
stopPdeOffset = startPdeOffset;
|
||||
} else {
|
||||
// Subtract one for inclusive end
|
||||
stopPdeOffset = ps.javaOffsetToPdeOffset(stopJavaOffset - 1);
|
||||
if (javaLength == 1 || stopPdeOffset > startPdeOffset) {
|
||||
// Add one back for exclusive end
|
||||
stopPdeOffset += 1;
|
||||
}
|
||||
}
|
||||
|
||||
int tabIndex = ps.pdeOffsetToTabIndex(startPdeOffset);
|
||||
|
||||
|
||||
@@ -318,8 +318,11 @@ public class JavaTextArea extends JEditTextArea {
|
||||
}
|
||||
Messages.log("Mouse click, word: " + word.trim());
|
||||
ASTGenerator astGenerator = editor.getErrorChecker().getASTGenerator();
|
||||
|
||||
int tabIndex = editor.getSketch().getCurrentCodeIndex();
|
||||
|
||||
synchronized (astGenerator) {
|
||||
astGenerator.setLastClickedWord(off, word);
|
||||
astGenerator.setLastClickedWord(tabIndex, off, word);
|
||||
}
|
||||
return word.trim();
|
||||
}
|
||||
|
||||
@@ -176,9 +176,12 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
return;
|
||||
|
||||
Messages.log(line + "|" + line + "| offset " + xLS + word + " <= \n");
|
||||
|
||||
int tabIndex = getEditor().getSketch().getCurrentCodeIndex();
|
||||
|
||||
ASTGenerator astGenerator = getJavaEditor().getErrorChecker().getASTGenerator();
|
||||
synchronized (astGenerator) {
|
||||
astGenerator.scrollToDeclaration(off, word);
|
||||
astGenerator.scrollToDeclaration(tabIndex, off, word);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,9 +44,9 @@ public class PreprocessedSketch {
|
||||
public static int lineToOffset(String text, int line) {
|
||||
int lineOffset = 0;
|
||||
for (int i = 0; i < line && lineOffset >= 0; i++) {
|
||||
lineOffset = text.indexOf('\n', lineOffset+1);
|
||||
lineOffset = text.indexOf('\n', lineOffset) + 1;
|
||||
}
|
||||
return lineOffset + 1;
|
||||
return lineOffset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -130,8 +130,9 @@ public class SourceMapping {
|
||||
int i = Collections.binarySearch(outMap, searchKey, OUTPUT_OFFSET_COMP);
|
||||
if (i < 0) {
|
||||
i = -(i + 1);
|
||||
i -= 1;
|
||||
}
|
||||
i = PApplet.constrain(i-1, 0, outMap.size()-1);
|
||||
i = PApplet.constrain(i, 0, outMap.size()-1);
|
||||
Edit edit = outMap.get(i);
|
||||
int diff = outputOffset - edit.toOffset;
|
||||
return edit.fromOffset + Math.min(diff, Math.max(0, edit.fromLength - 1));
|
||||
@@ -144,8 +145,9 @@ public class SourceMapping {
|
||||
int i = Collections.binarySearch(inMap, searchKey, INPUT_OFFSET_COMP);
|
||||
if (i < 0) {
|
||||
i = -(i + 1);
|
||||
i -= 1;
|
||||
}
|
||||
i = PApplet.constrain(i-1, 0, inMap.size()-1);
|
||||
i = PApplet.constrain(i, 0, inMap.size()-1);
|
||||
Edit edit = inMap.get(i);
|
||||
int diff = inputOffset - edit.fromOffset;
|
||||
return edit.toOffset + Math.min(diff, Math.max(0, edit.toLength - 1));
|
||||
|
||||
@@ -62,9 +62,8 @@ public class SourceUtils {
|
||||
int offset = matcher.start(1);
|
||||
int length = match.length();
|
||||
String replace = "PApplet.parse"
|
||||
+ Character.toUpperCase(match.charAt(0))
|
||||
+ match.substring(1);
|
||||
result.add(Edit.replace(offset, length, replace));
|
||||
+ Character.toUpperCase(match.charAt(0));
|
||||
result.add(Edit.replace(offset, length - (match.length() - 1), replace));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user