当前位置: 首页>>代码示例>>Java>>正文


Java RSyntaxUtilities.getTokenAtOffset方法代码示例

本文整理汇总了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);
					}
				}

			}

		}
 
开发者ID:pyros2097,项目名称:GdxStudio,代码行数:27,代码来源:AbstractMarkupLanguageSupport.java

示例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;

}
 
开发者ID:pyros2097,项目名称:GdxStudio,代码行数:47,代码来源:SourceCompletionProvider.java

示例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;

}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:47,代码来源:SourceCompletionProvider.java

示例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);
			}
		}

	}

}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:28,代码来源:AbstractMarkupLanguageSupport.java


注:本文中的org.fife.ui.rsyntaxtextarea.RSyntaxUtilities.getTokenAtOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。