當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractRule類代碼示例

本文整理匯總了Java中org.eclipse.xtext.AbstractRule的典型用法代碼示例。如果您正苦於以下問題:Java AbstractRule類的具體用法?Java AbstractRule怎麽用?Java AbstractRule使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AbstractRule類屬於org.eclipse.xtext包,在下文中一共展示了AbstractRule類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initializeFor

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
@Override
public void initializeFor(AbstractRule rule) {
	// TODO: GH-61.
	// Remove this function to see test errors in GHOLD-92-LINKING_DIAGNOSTIC_import_missing_B.n4js.xt
	/*
	 * Comment by Sebastian: This is a super nasty side effect of some Xpect internals: Xpect uses own injectors
	 * thus reflectively creates a new injector for the language. Effectively two injectors for N4JS exist at that
	 * time. Both have their own 'singleton'-bindings, their own in-memory gramar representation etc. This is highly
	 * problematic since all sorts of assumptions do no longer hold in such a setup. That is, especially the grammar
	 * elements are supposed to be singletons and to be comparable by identity. Now we have each grammar element
	 * twice in memory. Further there appears to be a blurry boundary between which object is obtain from which of
	 * both injectors, so in the end, we face a parser instance that was produced by the real injector being used by
	 * objects that were produced by the second injector. To be honest, I wonder wow this can even work. This is a
	 * super critical misbehavior of Xpect from my point of view.
	 */
	if (super.getEntryRule() == null) {
		super.initializeFor(rule);
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:20,代碼來源:CustomN4JSParser.java

示例2: rewriteKeywords

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
private static void rewriteKeywords(AbstractRule rule, N4JSKeywords keywords,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
		if (obj instanceof Keyword) {
			Keyword keyword = (Keyword) obj;
			Integer type = keywords.getTokenType(keyword);
			if (type != null) {
				if (keyword.eContainer() instanceof EnumLiteralDeclaration) {
					builder.put((AbstractElement) keyword.eContainer(), type);
				} else {
					builder.put(keyword, type);
				}
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:17,代碼來源:TokenTypeRewriter.java

示例3: rewriteTypeReferences

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
private static void rewriteTypeReferences(N4JSGrammarAccess ga,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
		for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
			if (obj instanceof Assignment) {
				Assignment assignment = (Assignment) obj;
				AbstractElement terminal = assignment.getTerminal();
				if (terminal instanceof RuleCall) {
					AbstractRule calledRule = ((RuleCall) terminal).getRule();
					EClassifier classifier = calledRule.getType().getClassifier();
					if (classifier instanceof EClass
							&& TypeRefsPackage.Literals.TYPE_REF.isSuperTypeOf((EClass) classifier)) {
						builder.put(assignment, TYPE_REF_TOKEN);
					}
				}
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:20,代碼來源:TokenTypeRewriter.java

示例4: rewriteIdentifiers

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
private static void rewriteIdentifiers(N4JSGrammarAccess ga,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	ImmutableSet<AbstractRule> identifierRules = ImmutableSet.of(
			ga.getBindingIdentifierRule(),
			ga.getIdentifierNameRule(),
			ga.getIDENTIFIERRule());
	for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
		for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
			if (obj instanceof Assignment) {
				Assignment assignment = (Assignment) obj;
				AbstractElement terminal = assignment.getTerminal();
				int type = InternalN4JSParser.RULE_IDENTIFIER;
				if (terminal instanceof CrossReference) {
					terminal = ((CrossReference) terminal).getTerminal();
					type = IDENTIFIER_REF_TOKEN;
				}
				if (terminal instanceof RuleCall) {
					AbstractRule calledRule = ((RuleCall) terminal).getRule();
					if (identifierRules.contains(calledRule)) {
						builder.put(assignment, type);
					}
				}
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:27,代碼來源:TokenTypeRewriter.java

示例5: rewriteNumberLiterals

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
private static void rewriteNumberLiterals(N4JSGrammarAccess ga,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
		for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
			if (obj instanceof Assignment) {
				Assignment assignment = (Assignment) obj;
				AbstractElement terminal = assignment.getTerminal();
				if (terminal instanceof RuleCall) {
					AbstractRule calledRule = ((RuleCall) terminal).getRule();
					EClassifier classifier = calledRule.getType().getClassifier();
					if (classifier == EcorePackage.Literals.EBIG_DECIMAL) {
						builder.put(assignment, NUMBER_LITERAL_TOKEN);
					}
				}
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:19,代碼來源:TokenTypeRewriter.java

示例6: registerRules

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected void registerRules(Grammar grammar) {
	if (ALL_RULES_FIELD != null) {
		try {
			Map<String, AbstractRule> localAllRules = (Map<String, AbstractRule>) ALL_RULES_FIELD.get(this);
			if (allRules == null) {
				super.registerRules(grammar);
				allRules = localAllRules;
			} else {
				localAllRules.putAll(allRules);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	} else {
		super.registerRules(grammar);
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:20,代碼來源:InternalSemicolonInjectingParser.java

示例7: testUnassignedRule_04

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
@Test
public void testUnassignedRule_04() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : Second (name=ID)? id=INT;");
  _builder.newLine();
  _builder.append("Second: id=INT (name=ID)?;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 4, this.warnings.size());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:19,代碼來源:OverriddenValueInspectorTest.java

示例8: getOriginalElement

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
/**
 * @since 2.9
 */
@SuppressWarnings("unchecked")
public static <T extends EObject> T getOriginalElement(T obj) {
	if (obj instanceof AbstractRule) {
		AbstractRule result = RuleWithParameterValues.tryGetOriginalRule((AbstractRule) obj);
		if (result != null)
			return (T) result;
		return obj;
	}
	if (obj instanceof Grammar) {
		OriginalGrammar originalGrammar = OriginalGrammar.findInEmfObject(obj);
		return (T) originalGrammar.getOriginal();
	}
	if (obj instanceof AbstractElement) {
		OriginalElement original = OriginalElement.findInEmfObject(obj);
		return (T) original.getOriginal();
	}
	throw new IllegalArgumentException(String.valueOf(obj));
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:22,代碼來源:AntlrGrammarGenUtil.java

示例9: testUnorderedGroup_03

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
@Test
public void testUnorderedGroup_03() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("Model : (a = ID & b = STRING)+;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "Model");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:17,代碼來源:OverriddenValueInspectorTest.java

示例10: gaTypeAccessor

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
/**
 * Returns the invocation of an element or rule accessor, including the .getType() call.
 * Example1: getFooRule().getType()
 * Example2: getBarRule().getFooAction().getType()
 */
public String gaTypeAccessor(final TypeRef ele) {
  String _switchResult = null;
  EObject _eContainer = ele.eContainer();
  final EObject cnt = _eContainer;
  boolean _matched = false;
  if (cnt instanceof AbstractElement) {
    _matched=true;
    String _gaRuleElementAccessor = this.gaRuleElementAccessor(((AbstractElement)cnt));
    _switchResult = (_gaRuleElementAccessor + ".getType()");
  }
  if (!_matched) {
    if (cnt instanceof AbstractRule) {
      _matched=true;
      String _gaRuleAccessor = this.gaRuleAccessor(((AbstractRule)cnt));
      _switchResult = (_gaRuleAccessor + ".getType()");
    }
  }
  if (!_matched) {
    String _name = ele.eContainer().eClass().getName();
    String _plus = ("<error: unknown type " + _name);
    _switchResult = (_plus + ">");
  }
  return _switchResult;
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:30,代碼來源:GrammarAccess.java

示例11: testMultiInheritance_01

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
@Test
public void testMultiInheritance_01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.enumrules.EnumRulesTestLanguage");
  _builder.newLine();
  _builder.append("import \'http://www.eclipse.org/xtext/common/JavaVMTypes\' as types");
  _builder.newLine();
  _builder.append("generate myDsl \"http://example.xtext.org/MyDsl\" as mydsl");
  _builder.newLine();
  _builder.append("Array returns mydsl::Array: componentType=ComponentType componentType=DeclaredType;");
  _builder.newLine();
  _builder.append("DeclaredType returns types::JvmDeclaredType: members+=DeclaredType;");
  _builder.newLine();
  _builder.append("ComponentType returns types::JvmComponentType: \'ignore\';");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammarAsString);
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  final Grammar grammar = ((Grammar) _head);
  EClassifier _classifier = IterableExtensions.<AbstractRule>head(grammar.getRules()).getType().getClassifier();
  EClass array = ((EClass) _classifier);
  Assert.assertEquals("JvmComponentType", this.<EStructuralFeature>feature(array, "componentType").getEType().getName());
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:24,代碼來源:Xtext2EcoreTransformerTest.java

示例12: testMultiInheritance_02

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
@Test
public void testMultiInheritance_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.enumrules.EnumRulesTestLanguage");
  _builder.newLine();
  _builder.append("import \'http://www.eclipse.org/xtext/common/JavaVMTypes\' as types");
  _builder.newLine();
  _builder.append("generate myDsl \"http://example.xtext.org/MyDsl\" as mydsl");
  _builder.newLine();
  _builder.append("Array returns mydsl::Array: componentType=DeclaredType componentType=ComponentType;");
  _builder.newLine();
  _builder.append("DeclaredType returns types::JvmDeclaredType: members+=DeclaredType;");
  _builder.newLine();
  _builder.append("ComponentType returns types::JvmComponentType: \'ignore\';");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammarAsString);
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  final Grammar grammar = ((Grammar) _head);
  EClassifier _classifier = IterableExtensions.<AbstractRule>head(grammar.getRules()).getType().getClassifier();
  EClass array = ((EClass) _classifier);
  Assert.assertEquals("JvmComponentType", this.<EStructuralFeature>feature(array, "componentType").getEType().getName());
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:24,代碼來源:Xtext2EcoreTransformerTest.java

示例13: testFragment_05

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
@Test
public void testFragment_05() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : Named*;");
  _builder.newLine();
  _builder.append("fragment Named: name=ID;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 1, this.warnings.size());
  AbstractRule _findRuleForName_1 = GrammarUtil.findRuleForName(grammar, "Named");
  final ParserRule fragment = ((ParserRule) _findRuleForName_1);
  this.validateRule(fragment);
  Assert.assertEquals(this.warnings.toString(), 0, this.warnings.size());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:23,代碼來源:OverriddenValueInspectorTest.java

示例14: testUnassignedRule_02

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
@Test
public void testUnassignedRule_02() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate metamodel \'foo.sample\'");
  _builder.newLine();
  _builder.append("First : Second name=ID;");
  _builder.newLine();
  _builder.append("Second: name=ID;");
  _builder.newLine();
  String grammarAsString = _builder.toString();
  final Grammar grammar = this.getGrammar(grammarAsString);
  AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
  final ParserRule rule = ((ParserRule) _findRuleForName);
  this.validateRule(rule);
  Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:19,代碼來源:OverriddenValueInspectorTest.java

示例15: getDocumentationNodes

import org.eclipse.xtext.AbstractRule; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
public List<INode> getDocumentationNodes(final EObject object) {
  ICompositeNode node = NodeModelUtils.getNode(object);
  if (node == null) {
    return ImmutableList.of();
  }

  // get all single line comments before a non hidden leaf node
  List<INode> result = Lists.newArrayList();
  for (ILeafNode leaf : node.getLeafNodes()) {
    if (!leaf.isHidden()) {
      break;
    }
    EObject grammarElement = leaf.getGrammarElement();
    if (grammarElement instanceof AbstractRule && ruleName.equals(((AbstractRule) grammarElement).getName())) {
      String comment = leaf.getText();
      if (getCommentPattern().matcher(comment).matches() && !comment.matches(ignore)) {
        result.add(leaf);
      }
    }
  }

  return result;
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:26,代碼來源:SingleLineCommentDocumentationProvider.java


注:本文中的org.eclipse.xtext.AbstractRule類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。