本文整理汇总了Java中org.fife.ui.rsyntaxtextarea.RSyntaxUtilities.getTokenAtOffset方法的典型用法代码示例。如果您正苦于以下问题:Java RSyntaxUtilities.getTokenAtOffset方法的具体用法?Java RSyntaxUtilities.getTokenAtOffset怎么用?Java RSyntaxUtilities.getTokenAtOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.fife.ui.rsyntaxtextarea.RSyntaxUtilities
的用法示例。
在下文中一共展示了RSyntaxUtilities.getTokenAtOffset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
RSyntaxTextArea textArea = (RSyntaxTextArea)getTextComponent(e);
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
Caret c = textArea.getCaret();
int dot = c.getDot(); // Get before "<" insertion
boolean selection = dot!=c.getMark(); // Me too
textArea.replaceSelection(">");
// Don't automatically complete a tag if there was a selection
if (!selection && getAutoAddClosingTags()) {
Token t = doc.getTokenListForLine(textArea.getCaretLineNumber());
t = RSyntaxUtilities.getTokenAtOffset(t, dot);
if (t!=null && t.isSingleChar(Token.MARKUP_TAG_DELIMITER, '>')) {
String tagName = discoverTagName(doc, dot);
if (tagName!=null) {
textArea.replaceSelection("</" + tagName + ">");
textArea.setCaretPosition(dot+1);
}
}
}
}
示例2: checkStringLiteralMember
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入方法依赖的package包/类
/**
* Checks whether the user is typing a completion for a String member after
* a String literal.
*
* @param comp The text component.
* @param alreadyEntered The text already entered.
* @param cu The compilation unit being parsed.
* @param set The set to add possible completions to.
* @return Whether the user is indeed typing a completion for a String
* literal member.
*/
private boolean checkStringLiteralMember(JTextComponent comp,
String alreadyEntered,
CompilationUnit cu, Set set) {
boolean stringLiteralMember = false;
int offs = comp.getCaretPosition() - alreadyEntered.length() - 1;
if (offs>1) {
RSyntaxTextArea textArea = (RSyntaxTextArea)comp;
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
try {
//System.out.println(doc.charAt(offs) + ", " + doc.charAt(offs+1));
if (doc.charAt(offs)=='"' && doc.charAt(offs+1)=='.') {
int curLine = textArea.getLineOfOffset(offs);
Token list = textArea.getTokenListForLine(curLine);
Token prevToken = RSyntaxUtilities.getTokenAtOffset(list, offs);
if (prevToken!=null &&
prevToken.getType()==Token.LITERAL_STRING_DOUBLE_QUOTE) {
ClassFile cf = getClassFileFor(cu, "java.lang.String");
addCompletionsForExtendedClass(set, cu, cf,
cu.getPackageName(), null);
stringLiteralMember = true;
}
else {
System.out.println(prevToken);
}
}
} catch (BadLocationException ble) { // Never happens
ble.printStackTrace();
}
}
return stringLiteralMember;
}
示例3: checkStringLiteralMember
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入方法依赖的package包/类
/**
* Checks whether the user is typing a completion for a String member after
* a String literal.
*
* @param comp The text component.
* @param alreadyEntered The text already entered.
* @param cu The compilation unit being parsed.
* @param set The set to add possible completions to.
* @return Whether the user is indeed typing a completion for a String
* literal member.
*/
private boolean checkStringLiteralMember(JTextComponent comp,
String alreadyEntered,
CompilationUnit cu, Set<Completion> set) {
boolean stringLiteralMember = false;
int offs = comp.getCaretPosition() - alreadyEntered.length() - 1;
if (offs>1) {
RSyntaxTextArea textArea = (RSyntaxTextArea)comp;
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
try {
//System.out.println(doc.charAt(offs) + ", " + doc.charAt(offs+1));
if (doc.charAt(offs)=='"' && doc.charAt(offs+1)=='.') {
int curLine = textArea.getLineOfOffset(offs);
Token list = textArea.getTokenListForLine(curLine);
Token prevToken = RSyntaxUtilities.getTokenAtOffset(list, offs);
if (prevToken!=null &&
prevToken.getType()==Token.LITERAL_STRING_DOUBLE_QUOTE) {
ClassFile cf = getClassFileFor(cu, "java.lang.String");
addCompletionsForExtendedClass(set, cu, cf,
cu.getPackageName(), null);
stringLiteralMember = true;
}
else {
System.out.println(prevToken);
}
}
} catch (BadLocationException ble) { // Never happens
ble.printStackTrace();
}
}
return stringLiteralMember;
}
示例4: actionPerformed
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
RSyntaxTextArea textArea = (RSyntaxTextArea)getTextComponent(e);
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
Caret c = textArea.getCaret();
int dot = c.getDot(); // Get before "<" insertion
boolean selection = dot!=c.getMark(); // Me too
textArea.replaceSelection(">");
// Don't automatically complete a tag if there was a selection
if (!selection && getAutoAddClosingTags()) {
Token t = doc.getTokenListForLine(textArea.getCaretLineNumber());
t = RSyntaxUtilities.getTokenAtOffset(t, dot);
if (t!=null && t.isSingleChar(Token.MARKUP_TAG_DELIMITER, '>')) {
String tagName = discoverTagName(doc, dot);
if (tagName!=null) {
textArea.replaceSelection("</" + tagName + ">");
textArea.setCaretPosition(dot+1);
}
}
}
}