ASTGen: ctrl click on declaration shows usage

This commit is contained in:
Jakub Valtar
2016-04-22 14:16:09 +02:00
parent 3ca2d9aa9e
commit 0647c7d248
2 changed files with 11 additions and 8 deletions

View File

@@ -2509,13 +2509,11 @@ public class ASTGenerator {
// Thread: EDT
public void scrollToDeclaration(int tabIndex, int offset) {
public void handleCtrlClick(int tabIndex, int offset) {
Messages.log("* scrollToDeclaration");
// TODO: don't run the heavy lifting on EDT
// TODO: handle comments
PreprocessedSketch ps = errorCheckerService.latestResult;
int javaOffset = ps.tabOffsetToJavaOffset(tabIndex, offset);
@@ -2536,7 +2534,8 @@ public class ASTGenerator {
String key = binding.getKey();
ASTNode decl = ps.compilationUnit.findDeclaringNode(key);
if (decl == null) {
Messages.log("decl not found");
Messages.log("decl not found, showing usage instead");
handleShowUsage(binding);
return;
}
@@ -2551,8 +2550,12 @@ public class ASTGenerator {
return;
}
Messages.log("found declaration, offset " + decl.getStartPosition() + ", name: " + declName);
errorCheckerService.highlightJavaRange(declName.getStartPosition(), declName.getLength());
if (declName.equals(simpleName)) {
handleShowUsage(binding);
} else {
Messages.log("found declaration, offset " + decl.getStartPosition() + ", name: " + declName);
errorCheckerService.highlightJavaRange(declName.getStartPosition(), declName.getLength());
}
}

View File

@@ -78,7 +78,7 @@ public class JavaTextAreaPainter extends TextAreaPainter
super(textArea, defaults);
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
public void mouseReleased(MouseEvent evt) {
if (!getJavaEditor().hasJavaTabs()) { // Ctrl + Click disabled for java tabs
if (evt.getButton() == MouseEvent.BUTTON1) {
if ((evt.isControlDown() && !Platform.isMacOS()) || evt.isMetaDown()) {
@@ -130,7 +130,7 @@ public class JavaTextAreaPainter extends TextAreaPainter
ASTGenerator astGenerator = getJavaEditor().getErrorChecker().getASTGenerator();
synchronized (astGenerator) {
astGenerator.scrollToDeclaration(tabIndex, off);
astGenerator.handleCtrlClick(tabIndex, off);
}
}