下面列出了怎么用org.eclipse.jface.text.rules.IPredicateRule的API类实例代码及写法,或者点击链接到github查看源代码。
public XMLPartitionScanner() {
IToken xmlComment = new Token(XML_COMMENT);
IToken xmlPI = new Token(XML_PI);
IToken startTag = new Token(XML_START_TAG);
IToken endTag = new Token(XML_END_TAG);
IToken docType = new Token(XML_DOCTYPE);
IToken text = new Token(XML_TEXT);
IPredicateRule[] rules = new IPredicateRule[7];
rules[0] = new NonMatchingRule();
rules[1] = new MultiLineRule("<!--", "-->", xmlComment);
rules[2] = new MultiLineRule("<?", "?>", xmlPI);
rules[3] = new MultiLineRule("</", ">", endTag);
rules[4] = new StartTagRule(startTag);
rules[5] = new MultiLineRule("<!DOCTYPE", ">", docType);
rules[6] = new XMLTextPredicateRule(text);
setPredicateRules(rules);
}
/**
* Creates the partitioner and sets up the appropriate rules.
*/
public BibPartitionScanner() {
super();
IToken bibEntry = new Token(BIB_ENTRY);
List rules = new ArrayList();
// Add rule for single line comments.
// rules.add(new EndOfLineRule("//", Token.UNDEFINED));
// Add rule for strings and character constants.
// rules.add(new SingleLineRule("\"", "\"", Token.UNDEFINED, '\\'));
// rules.add(new SingleLineRule("'", "'", Token.UNDEFINED, '\\'));
// Add rules for BibTeX entries
//rules.add(new MultiLineRule("{", "}", bibEntry, (char) 0, false));
rules.add(new BibBraceRule(true, bibEntry));;
IPredicateRule[] result= new IPredicateRule[rules.size()];
rules.toArray(result);
setPredicateRules(result);
}
public ModulaRuleBasedPartitionScanner() {
super();
// Create the list of rules that produce tokens
inactiveCodeRule = new InactiveCodeRule();
IPredicateRule[] rules = new IPredicateRule[] {
inactiveCodeRule,
new EndOfLineRule("--", END_OF_LINE_COMMENT_TOKEN), //$NON-NLS-1$
new ModulaCommentRule(BLOCK_COMMENT_TOKEN),
new SingleLineRule("\"", "\"", DOUBLE_QUOTE_STRING_TOKEN), //$NON-NLS-1$ //$NON-NLS-2$
new SingleLineRule("'", "'", SINGLE_QUOTE_STRING_TOKEN), //$NON-NLS-1$ //$NON-NLS-2$
new MultiLineRule("<*", "*>", PRAGMA_TOKEN, (char)0, true) //$NON-NLS-1$ //$NON-NLS-2$
};
setPredicateRules(rules);
setDefaultReturnToken(DEFAULT_TOKEN);
}
/**
*
*/
public CompositePartitionScanner(ISubPartitionScanner defaultPartitionScanner, ISubPartitionScanner primaryPartitionScanner,
IPartitionerSwitchStrategy partitionerSwitchStrategy) {
this.defaultPartitionScanner = defaultPartitionScanner;
this.primaryPartitionScanner = primaryPartitionScanner;
defaultPartitionScanner.initCharacterScanner(this, partitionerSwitchStrategy.getDefaultSwitchStrategy());
primaryPartitionScanner.initCharacterScanner(this, partitionerSwitchStrategy.getPrimarySwitchStrategy());
String[][] pairs = partitionerSwitchStrategy.getSwitchTagPairs();
switchRules = new IPredicateRule[pairs.length][];
for (int i = 0; i < pairs.length; ++i) {
switchRules[i] = new IPredicateRule[] { new SingleTagRule(pairs[i][0], new Token(START_SWITCH_TAG)), new SingleTagRule(pairs[i][1], new Token(END_SWITCH_TAG)) };
}
currentPartitionScanner = defaultPartitionScanner;
setDefaultReturnToken(new Token(IDocument.DEFAULT_CONTENT_TYPE));
}
/**
*
*/
public SQLPartitionScanner( )
{
super( );
IToken sqlComment = new Token( COMMENT );
IToken sqlQuoteString = new Token( QUOTE_STRING );
ArrayList rules = new ArrayList( );
rules.add( new MultiLineRule( "\"", "\"", sqlQuoteString, '\\' ) ); //$NON-NLS-1$ //$NON-NLS-2$
rules.add( new MultiLineRule( "\'", "\'", sqlQuoteString, '\\' ) ); //$NON-NLS-1$ //$NON-NLS-2$
rules.add( new EndOfLineRule( "//", sqlComment ) ); //$NON-NLS-1$
rules.add( new EndOfLineRule( "--", sqlComment ) ); //$NON-NLS-1$
rules.add( new MultiLineRule( "/*", "*/", sqlComment ) ); //$NON-NLS-1$ //$NON-NLS-2$
setPredicateRules( (IPredicateRule[]) rules.toArray( new IPredicateRule[rules.size( )] ) );
}
/**
* Creates the partitioner and sets up the appropriate rules.
*/
public SamplePartitionScanner() {
IToken tkString = new Token(LANG_STRING);
IToken tkRawString = new Token(LANG_RAW_STRING);
IToken tkCharacter = new Token(LANG_CHARACTER);
IToken tkSingleComment = new Token(LANG_SINGLE_COMMENT);
IToken tkMultiComment = new Token(LANG_MULTI_COMMENT);
List<IPredicateRule> rules = new ArrayList<IPredicateRule>();
rules.add(new MultiLineRule("`", "`", tkRawString, NO_ESCAPE, true));
rules.add(new MultiLineRule("\"", "\"", tkString, '\\', true));
rules.add(new SingleLineRule("'", "'", tkCharacter, '\\', true));
rules.add(new EndOfLineRule("//", tkSingleComment, NO_ESCAPE));
rules.add(new MultiLineRule("/*", "*/", tkMultiComment, NO_ESCAPE, true));
setPredicateRules(rules.toArray(new IPredicateRule[rules.size()]));
}
/***
* Add some partition rules common to C-style languages.
* All rules are optional, if an id is null, the rule will not be added.
*/
protected static void addStandardRules(ArrayList2<IPredicateRule> rules,
String lineCommentId, String blockCommentId,
String docLineCommentId, String docBlockCommentId,
String stringId) {
if(docLineCommentId != null) {
rules.add(new PatternRule("///", null, new Token(docLineCommentId), NO_ESCAPE_CHAR, true, true));
}
if(docBlockCommentId != null) {
rules.add(new PatternRule("/**", "*/", new Token(docBlockCommentId), NO_ESCAPE_CHAR, false, true));
}
if(lineCommentId != null) {
rules.add(new PatternRule("//", null, new Token(lineCommentId), NO_ESCAPE_CHAR, true, true));
}
if(blockCommentId != null) {
rules.add(new PatternRule("/*", "*/", new Token(blockCommentId), NO_ESCAPE_CHAR, false, true));
}
if(stringId != null) {
rules.add(new PatternRule("\"", "\"", new Token(stringId), '\\', false, true));
}
}
public HPartitionScanner() {
// IToken key= new Token(IDocument.DEFAULT_CONTENT_TYPE);
IToken comment = new Token(COMMENT);
IToken propertyValue = new Token(PROPERTY_VALUE);
setPredicateRules(new IPredicateRule[] {
new SingleLineRule(AssistConstants.PARAM_DELIM_EQ, null, propertyValue, '\\', true, true),
new SingleLineRule("#", null, comment, (char) 0, true, true), });
}
public TagBasedTLCOutputTokenScanner()
{
Vector<IPredicateRule> rules = new Vector<IPredicateRule>();
rules.add(new TLCSingleLineRule(RULE_START, TAIL_DELIM + "\n", new Token(TAG_OPEN)));
rules.add(new TLCSingleLineRule(RULE_END, TAIL_DELIM + "\n", new Token(TAG_CLOSED)));
rules.add(new TLCMultiLineRule(new Token(DEFAULT_CONTENT_TYPE)));
// add the rules
setPredicateRules((IPredicateRule[]) rules.toArray(new IPredicateRule[rules.size()]));
}
public GWTPartitionScanner() {
IToken jsniMethod = new Token(GWTPartitions.JSNI_METHOD);
MultiLineRule jsniRule = new MultiLineRule("/*-{", "}-*/", jsniMethod);
IPredicateRule[] result = new IPredicateRule[] {jsniRule};
setPredicateRules(result);
}
private static void resetRules(IPredicateRule[] rules) {
for (IPredicateRule rule : rules) {
if (rule instanceof IResumableRule) {
((IResumableRule) rule).resetRule();
}
}
}
/**
* Creates the partitioner and sets up the appropriate rules.
*/
public PropertiesFilePartitionScanner() {
super();
IToken comment= new Token(COMMENT);
IToken propertyValue= new Token(PROPERTY_VALUE);
IToken key= new Token(IDocument.DEFAULT_CONTENT_TYPE);
List<IPredicateRule> rules= new ArrayList<IPredicateRule>();
// Add rule for leading white space.
rules.add(new LeadingWhitespacePredicateRule(key, "\t")); //$NON-NLS-1$
rules.add(new LeadingWhitespacePredicateRule(key, " ")); //$NON-NLS-1$
// Add rules for comments.
rules.add(new EndOfLineRule("#", comment, (char) 0, true)); //$NON-NLS-1$
rules.add(new EndOfLineRule("!", comment, (char) 0, true)); //$NON-NLS-1$
// Add rules for property values.
rules.add(new SingleLineRule("=", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
rules.add(new SingleLineRule(":", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
rules.add(new SingleLineRule(" ", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
rules.add(new SingleLineRule("\t", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
// Add special case word rule.
EmptyCommentRule wordRule= new EmptyCommentRule(comment);
rules.add(wordRule);
IPredicateRule[] result= new IPredicateRule[rules.size()];
rules.toArray(result);
setPredicateRules(result);
}
/**
* Creates the partitioner and sets up the appropriate rules.
*/
public JavaPartitionScanner() {
super();
IToken string= new Token(JAVA_STRING);
IToken character= new Token(JAVA_CHARACTER);
IToken javaDoc= new Token(JAVA_DOC);
IToken multiLineComment= new Token(JAVA_MULTI_LINE_COMMENT);
IToken singleLineComment= new Token(JAVA_SINGLE_LINE_COMMENT);
List<IPredicateRule> rules= new ArrayList<IPredicateRule>();
// Add rule for single line comments.
rules.add(new EndOfLineRule("//", singleLineComment)); //$NON-NLS-1$
// Add rule for strings.
rules.add(new SingleLineRule("\"", "\"", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
// Add rule for character constants.
rules.add(new SingleLineRule("'", "'", character, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
// Add special case word rule.
EmptyCommentRule wordRule= new EmptyCommentRule(multiLineComment);
rules.add(wordRule);
// Add rules for multi-line comments and javadoc.
rules.add(new MultiLineRule("/**", "*/", javaDoc)); //$NON-NLS-1$ //$NON-NLS-2$
rules.add(new MultiLineRule("/*", "*/", multiLineComment)); //$NON-NLS-1$ //$NON-NLS-2$
IPredicateRule[] result= new IPredicateRule[rules.size()];
rules.toArray(result);
setPredicateRules(result);
}
/**
* Creates the partitioner and sets up the appropriate rules.
*/
public EditorConfigPartitionScanner() {
super();
IToken comment = new Token(COMMENT);
IToken sectionName = new Token(SECTION);
IToken propertyValue = new Token(PROPERTY_VALUE);
IToken key = new Token(IDocument.DEFAULT_CONTENT_TYPE);
List<IPredicateRule> rules = new ArrayList<IPredicateRule>();
// Add rule for leading white space.
rules.add(new LeadingWhitespacePredicateRule(key, "\t")); //$NON-NLS-1$
rules.add(new LeadingWhitespacePredicateRule(key, " ")); //$NON-NLS-1$
// Add rules for comments.
rules.add(new EndOfLineRule("#", comment, (char) 0, true)); //$NON-NLS-1$
// rules.add(new EndOfLineRule("!", comment, (char) 0, true));
// //$NON-NLS-1$
// Add rules for sections.
rules.add(new SingleLineRule("[", "]", sectionName, '\\', true, true)); //$NON-NLS-1$
// Add rules for property values.
rules.add(new SingleLineRule("=", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
rules.add(new SingleLineRule(":", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
rules.add(new SingleLineRule(" ", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
rules.add(new SingleLineRule("\t", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
// Add special case word rule.
EmptyCommentRule wordRule = new EmptyCommentRule(comment);
rules.add(wordRule);
IPredicateRule[] result = new IPredicateRule[rules.size()];
rules.toArray(result);
setPredicateRules(result);
}
public CalcitePartitionScanner() {
IToken comment = new Token(SQL_COMMENT);
IToken string = new Token(SQL_STRING);
IToken quotedIdentifier = new Token(SQL_QUOTED_IDENTIFIER);
setPredicateRules(new IPredicateRule[] {
new EndOfLineRule("//", comment),
new EndOfLineRule("--", comment),
new MultiLineRule("/*", "*/", comment),
new SingleLineRule("\"", "\"", quotedIdentifier),
new MultiLineRule("'", "'", string),
});
}
public PartitionScanner() {
super();
final IToken comment = new Token(ContentTypes.COMMENT_CONTENT_TYPE);
final IPredicateRule[] rules = new IPredicateRule[2];
rules[0] = new MultiLineRule("/*", "*/", comment);
rules[1] = new MultiLineRule("(*", "*)", comment);
this.setPredicateRules(rules);
}
@Override
protected void initPredicateRules(ArrayList2<IPredicateRule> rules) {
addStandardRules(rules,
LangPartitionTypes.LINE_COMMENT.getId(),
LangPartitionTypes.BLOCK_COMMENT.getId(),
null,
null,
null
);
rules.add(new SingleLineRule("'", "'", new Token(LangPartitionTypes.CHARACTER.getId()), '\\'));
rules.add(new MultiLineRule("`", "`", new Token(LangPartitionTypes.MULTILINE_STRING.getId())));
rules.add(new SingleLineRule("\"", "\"", new Token(LangPartitionTypes.STRING.getId()), '\\'));
}
private static IPartitionTokenScanner createDefaultScanner() {
final IToken string = new Token(PatternExpressionViewer.GROOVY_EXPRESSION_CONTENT_TYPE);
final RuleBasedPartitionScanner scanner = new RuleBasedPartitionScanner();
scanner.setPredicateRules(new IPredicateRule[] {
new MultiLineRule(GROOVY_START_TAG, GROOVY_END_TAG, string)
});
return scanner;
}
public IPredicateRule[] getPartitioningRules()
{
return partitioningRules;
}
public IPredicateRule[] getPartitioningRules()
{
return partitioningRules;
}
public IPredicateRule[] getPartitioningRules()
{
return partitioningRules;
}
public IPredicateRule[] getPartitioningRules() {
return partitioningRules;
}
public IPredicateRule[] getPartitioningRules()
{
return partitioningRules;
}
public IPredicateRule[] getPartitioningRules()
{
return partitioningRules;
}
public IPredicateRule[] getRules() {
return EMPTY;
}
@Override
public void setPredicateRules(IPredicateRule[] rules) {
throw new UnsupportedOperationException("unsupported method"); //$NON-NLS-1$
}
private IToken doResumeContentType() {
if (fContentType == null) {
return null;
}
// inside a partition
fColumn = UNDEFINED;
boolean resume = (fPartitionOffset > -1 && fPartitionOffset < fOffset);
fTokenOffset = resume ? fPartitionOffset : fOffset;
if (hasResume) {
resume = true;
hasResume = false;
}
IToken token;
boolean doResetRules;
do {
doResetRules = false;
for (IPredicateRule rule : currentPartitionScanner.getRules()) {
token = rule.getSuccessToken();
if (fContentType.equals(token.getData())) {
token = rule.evaluate(currentPartitionScanner.getCharacterScanner(), resume);
if (!token.isUndefined() && fOffset != fTokenOffset) {
fContentType = null;
currentPartitionScanner.setLastToken(token);
currentPartitionScanner.doResetRules();
return returnToken(token);
}
if (doResetRules = currentPartitionScanner.doResetRules()) {
break;
}
if (hasSwitchingSequence()) {
fContentType = null;
return getDefaultToken();
}
}
}
} while (doResetRules);
// haven't found any rule for this type of partition
fContentType = null;
if (resume && fPartitionOffset >= 0) {
fOffset = fPartitionOffset;
fPartitionOffset = -1;
}
return null;
}
/**
*
*/
public SubPartitionScanner(IPredicateRule[] rules, String[] contentTypes, IToken defaultToken) {
this.rules = rules;
this.contentTypes.addAll(Arrays.asList(contentTypes));
this.defaultToken = (defaultToken != null) ? defaultToken : DEFAULT_TOKEN;
}
public IPredicateRule[] getRules() {
return rules;
}
public IPredicateRule[] getRules() {
return subPartitionScanners[current].getRules();
}