use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class EditorTips method display.
public void display(Point relativePoint, Point absolutePoint) {
if (window.getTokens() == null)
return;
int position = window.getTextPane().viewToModel(relativePoint);
Point p = null;
try {
ATEToken token = window.getTokenAtPosition(position, false);
if (token != null) {
// Make sure the mouse is over the token because
// Swing will return a valid position even if the mouse
// is on the remaining blank part of the line
Rectangle r1 = window.getTextPane().modelToView(token.getStartIndex());
Rectangle r2 = window.getTextPane().modelToView(token.getEndIndex());
if (r1.union(r2).contains(relativePoint)) {
p = SwingUtilities.convertPoint(window.getTextPane(), new Point(relativePoint.x + 2, r2.y - 5), window.getJavaContainer());
}
}
} catch (BadLocationException e) {
// Ignore
}
tipsManager.displayAnyTipsAvailable(position, p);
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class DBLocal method getCustomImports.
/**
* Returns a string of import statement based on the package declaration inside any @header block
*/
private String getCustomImports() {
List<ElementBlock> blocks = debuggerTab.getBlocks();
if (blocks == null || blocks.isEmpty()) {
return "";
}
Set<String> imports = new HashSet<String>();
for (ElementBlock block : blocks) {
if (!block.name.equals(GrammarSyntaxParser.PARSER_HEADER_BLOCK_NAME) && !block.name.equals(GrammarSyntaxParser.LEXER_HEADER_BLOCK_NAME)) {
continue;
}
List<ATEToken> tokens = block.internalTokens;
for (int j = 0; j < tokens.size(); j++) {
ATEToken token = tokens.get(j);
if (token.type == ATESyntaxLexer.TOKEN_ID && token.getAttribute().equals("package")) {
StringBuilder sb = new StringBuilder();
j++;
while (j < tokens.size()) {
ATEToken t = tokens.get(j);
String at = t.getAttribute();
if (at.equals(";"))
break;
sb.append(at);
j++;
}
imports.add(sb.toString());
}
}
}
if (imports.isEmpty()) {
return "";
}
StringBuilder importLines = new StringBuilder();
for (String importName : imports) {
importLines.append("import ");
importLines.append(importName);
importLines.append(".*;\n");
}
return importLines.toString();
}
Aggregations