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


Java GrammarUtil.containingParserRule方法代码示例

本文整理汇总了Java中org.eclipse.xtext.GrammarUtil.containingParserRule方法的典型用法代码示例。如果您正苦于以下问题:Java GrammarUtil.containingParserRule方法的具体用法?Java GrammarUtil.containingParserRule怎么用?Java GrammarUtil.containingParserRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.xtext.GrammarUtil的用法示例。


在下文中一共展示了GrammarUtil.containingParserRule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkUnconsumed

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected String checkUnconsumed(AbstractToken token, IEObjectConsumer instanceDescription) {
	if (token.getGrammarElement() == null)
		return null;
	boolean finalNode = nfaProvider.getNFA(token.getGrammarElement()).isEndState();
	if (!finalNode || instanceDescription.isConsumed())
		return null;
	ParserRule parserRule = GrammarUtil.containingParserRule(token.getGrammarElement());
	StringBuffer b = new StringBuffer();
	b.append("Can not leave rule '");
	b.append(parserRule.getName());
	b.append("' since the current object '");
	b.append(instanceDescription.getEObject().eClass().getName());
	b.append("' has features with unconsumed values: ");
	Map<EStructuralFeature, Integer> unconsumedTokens = instanceDescription.getUnconsumed();
	int i = 0;
	for (Map.Entry<EStructuralFeature, Integer> unconsumedFeature2NumberEntry : unconsumedTokens.entrySet()) {
		b.append("'");
		b.append(unconsumedFeature2NumberEntry.getKey().getName());
		b.append("':");
		b.append(unconsumedFeature2NumberEntry.getValue());
		if (++i != unconsumedTokens.size())
			b.append(", ");
	}
	return b.toString();
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:26,代码来源:TreeConstructionReportImpl.java

示例2: initStream

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
/**
 * @since 2.0
 */
protected void initStream(AbstractToken token, WsMergerStream out) {
	AbstractElement rootMostElement = null;
	if (!token.getTokensForSemanticChildren().isEmpty()) {
		for (AbstractToken t : Lists.reverse(token.getTokensForSemanticChildren()))
			if (t.getGrammarElement() != null) {
				rootMostElement = t.getGrammarElement();
				break;
			}
	} else if (token.getGrammarElement() != null) {
		rootMostElement = token.getGrammarElement();
	}
	if (rootMostElement != null) {
		ParserRule rootRule = GrammarUtil.containingParserRule(rootMostElement);
		out.init(rootRule);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:20,代码来源:AbstractParseTreeConstructor.java

示例3: getSignificantGrammarElement

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public String getSignificantGrammarElement(final Iterable<ISerializationContext> contexts) {
  ParserRule rule = null;
  int index = Integer.MAX_VALUE;
  for (final ISerializationContext ctx : contexts) {
    {
      ParserRule pr = ctx.getParserRule();
      if ((pr == null)) {
        final Action action = ctx.getAssignedAction();
        if ((action != null)) {
          pr = GrammarUtil.containingParserRule(action);
        }
      }
      if ((pr != null)) {
        final Integer i = this.rules.get(pr);
        if (((i).intValue() < index)) {
          index = (i).intValue();
          rule = pr;
        }
      }
    }
  }
  if ((rule != null)) {
    return rule.getName();
  }
  return "unknown";
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:27,代码来源:NamedSerializationContextProvider.java

示例4: adjustRuleName

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected String adjustRuleName(String ruleName, Param param) {
	AbstractElement elementToParse = param.elementToParse;
	Set<Parameter> context = getAssignedParameters(elementToParse, param.paramStack);
	if (!context.isEmpty()) {
		ParserRule containingRule = GrammarUtil.containingParserRule(elementToParse);
		String antlrRuleName = ruleNames.getAntlrRuleName(containingRule);
		int len = antlrRuleName.length();
		if (antlrRuleName.startsWith("rule")) {
			len += 2; // rule__XYZ instead of ruleXYZ
		}
		int config = getParameterConfig(context);
		String result = ruleNames.getAntlrRuleName(containingRule, config) + ruleName.substring(len);
		return result;
	}
	return ruleName;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:17,代码来源:RequiredRuleNameComputer.java

示例5: highlightSpecialIdentifiers

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
protected void highlightSpecialIdentifiers(final IHighlightedPositionAcceptor acceptor, final ICompositeNode root) {
  TerminalRule idRule = grammarAccess.getIDRule();

  for (ILeafNode leaf : root.getLeafNodes()) {
    if (commentProvider.isJavaDocComment(leaf)) {
      // not really a special identifier, but we don't want to iterate over the leaf nodes twice, do we?
      acceptor.addPosition(leaf.getOffset(), leaf.getLength(), CheckHighlightingConfiguration.JAVADOC_ID);
    } else if (!leaf.isHidden()) {
      if (leaf.getGrammarElement() instanceof Keyword) {
        // Check if it is a keyword used as an identifier.
        ParserRule rule = GrammarUtil.containingParserRule(leaf.getGrammarElement());
        if (FEATURE_CALL_ID_RULE_NAME.equals(rule.getName())) {
          acceptor.addPosition(leaf.getOffset(), leaf.getLength(), DefaultHighlightingConfiguration.DEFAULT_ID);
        }
      } else {
        highlightSpecialIdentifiers(leaf, acceptor, idRule);
      }
    }
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:22,代码来源:CheckHighlightingCalculator.java

示例6: installProxies

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
/**
 * Installs proxies for all non containment references and only if the node representing the EObject that contains
 * the cross reference has got leaf nodes (as a leaf node represents the cross reference).
 *
 * @param resource
 *            the N4JSResource
 * @param obj
 *            the EObject containing the cross reference
 * @param producer
 *            the error/warning producer
 * @param parentNode
 *            the node representing obj inside the node model
 */
private void installProxies(N4JSResource resource, EObject obj, IDiagnosticProducer producer,
		ICompositeNode parentNode, boolean dontCheckParent) {
	final EClass eClass = obj.eClass();
	if (eClass.getEAllReferences().size() - eClass.getEAllContainments().size() == 0)
		return;

	for (INode node = parentNode.getFirstChild(); node != null; node = node.getNextSibling()) {
		EObject grammarElement = node.getGrammarElement();
		if (grammarElement instanceof CrossReference && hasLeafNodes(node)) {
			producer.setNode(node);
			CrossReference crossReference = (CrossReference) grammarElement;
			final EReference eRef = GrammarUtil.getReference(crossReference, eClass);
			if (eRef == null) {
				ParserRule parserRule = GrammarUtil.containingParserRule(crossReference);
				final String feature = GrammarUtil.containingAssignment(crossReference).getFeature();
				throw new IllegalStateException("Couldn't find EReference for crossreference '" + eClass.getName()
						+ "::" + feature + "' in parser rule '" + parserRule.getName() + "'.");
			}
			createAndSetProxy(resource, obj, node, eRef, crossReference, producer);
			afterCreateAndSetProxy(obj, node, eRef, crossReference, producer);
		} else if (grammarElement instanceof RuleCall && node instanceof ICompositeNode) {
			RuleCall ruleCall = (RuleCall) grammarElement;
			AbstractRule calledRule = ruleCall.getRule();
			if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
				installProxies(resource, obj, producer, (ICompositeNode) node, true);
			}
		}
	}
	if (!dontCheckParent && shouldCheckParentNode(parentNode)) {
		installProxies(resource, obj, producer, parentNode.getParent(), dontCheckParent);
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:46,代码来源:N4JSLinker.java

示例7: getAssignedParameters

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public static Set<Parameter> getAssignedParameters(AbstractElement element, int parameterConfig) {
	if (parameterConfig != 0) {
		ParserRule parserRule = GrammarUtil.containingParserRule(element);
		Set<Parameter> allParameters = ImmutableSet.copyOf(parserRule.getParameters());
		int seen = 0;
		for(Set<Parameter> candidate: Sets.powerSet(allParameters)) {
			if (seen == parameterConfig) {
				return candidate;
			}
			seen++;
		}
	}
	return Collections.emptySet();
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:15,代码来源:ParameterConfigHelper.java

示例8: getParameterConfig

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public static int getParameterConfig(Set<Parameter> params) {
	if (params.isEmpty()) {
		return 0;
	}
	Parameter firstParam = params.iterator().next();
	ParserRule parserRule = GrammarUtil.containingParserRule(firstParam);
	return getParameterConfig(params, parserRule);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:9,代码来源:ParameterConfigHelper.java

示例9: drawPTC

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected Digraph drawPTC(TreeConstructionReportImpl report) {
	Digraph digraph = new Digraph();
	Set<AbstractToken> drawnTokens = new HashSet<AbstractToken>();
	Set<ParserRule> drawnRules = new HashSet<ParserRule>();
	List<AbstractToken> traces = new ArrayList<AbstractToken>();
	traces.add(report.getSuccess());
	traces.addAll(report.getDeadends());
	boolean solid = true;
	for (AbstractToken token : traces) {
		while (token != null && !drawnTokens.contains(token)) {
			// String ser = ((AbstractToken) t).serialize().replaceAll(
			// "\\\\", "\\\\");
			String tokenDescription = token.getClass().getSimpleName() + "\\n"
					+ token.getEObjectConsumer() + "\\n'" /* + ser */+ "'";
			digraph.add(new Node(token, tokenDescription));
			if (token.getGrammarElement() != null) {
				ParserRule parserRule = GrammarUtil.containingParserRule(token
						.getGrammarElement());
				if (parserRule != null && !drawnRules.contains(parserRule)) {
					drawnRules.add(parserRule);
					drawRule(parserRule, digraph);
				}
			}
			if (token.getNext() != null) {
				Edge edge = new Edge(token.getNext(), token);
				edge.setLabel(String.valueOf((token).getTransitionIndex()));
				if (!solid)
					edge.setStyle("dashed");
				digraph.add(edge);
			}
			drawnTokens.add(token);
			token = token.getNext();
		}
		solid = false;
	}
	return digraph;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:38,代码来源:TraceToDot.java

示例10: getParameterDeclarator

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public ParserRule getParameterDeclarator() {
	Action action = getAssignedAction();
	if (action != null) {
		return GrammarUtil.containingParserRule(action);
	}
	ParserRule rule = getParserRule();
	if (rule != null) {
		return rule;
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:12,代码来源:SerializationContext.java

示例11: installProxies

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private void installProxies(EObject obj, IDiagnosticProducer producer,
		Multimap<EStructuralFeature.Setting, INode> settingsToLink, ICompositeNode parentNode, boolean dontCheckParent) {
	final EClass eClass = obj.eClass();
	if (eClass.getEAllReferences().size() - eClass.getEAllContainments().size() == 0)
		return;

	for (INode node = parentNode.getFirstChild(); node != null; node = node.getNextSibling()) {
		EObject grammarElement = node.getGrammarElement();
		if (grammarElement instanceof CrossReference && hasLeafNodes(node)) {
			producer.setNode(node);
			CrossReference crossReference = (CrossReference) grammarElement;
			final EReference eRef = GrammarUtil.getReference(crossReference, eClass);
			if (eRef == null) {
				ParserRule parserRule = GrammarUtil.containingParserRule(crossReference);
				final String feature = GrammarUtil.containingAssignment(crossReference).getFeature();
				throw new IllegalStateException("Couldn't find EReference for crossreference '"+eClass.getName()+"::"+feature+"' in parser rule '"+parserRule.getName()+"'.");
			}
			if (!eRef.isResolveProxies() /*|| eRef.getEOpposite() != null see https://bugs.eclipse.org/bugs/show_bug.cgi?id=282486*/) {
				final EStructuralFeature.Setting setting = ((InternalEObject) obj).eSetting(eRef);
				settingsToLink.put(new SettingDelegate(setting), node);
			} else {
				createAndSetProxy(obj, node, eRef);
				afterCreateAndSetProxy(obj, node, eRef, crossReference, producer);
			}
		} else if (grammarElement instanceof RuleCall && node instanceof ICompositeNode) {
			RuleCall ruleCall = (RuleCall) grammarElement;
			AbstractRule calledRule = ruleCall.getRule();
			if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
				installProxies(obj, producer, settingsToLink, (ICompositeNode) node, true);
			}
		}
	}
	if (!dontCheckParent && shouldCheckParentNode(parentNode)) {
		installProxies(obj, producer, settingsToLink, parentNode.getParent(), dontCheckParent);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:37,代码来源:LazyLinker.java

示例12: findRootRuleForRegion

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
/**
 * @since 2.0
 */
protected ParserRule findRootRuleForRegion(INode node) {
	if (GrammarUtil.isEObjectRule(node.getGrammarElement()))
		return (ParserRule) node.getGrammarElement();
	if (node.hasDirectSemanticElement())
		return GrammarUtil.containingParserRule(node.getGrammarElement());
	if (node.getParent() != null)
		return findRootRuleForRegion(node.getParent());
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:NodeModelStreamer.java

示例13: gaRuleParameterAccessor

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
/**
 * Returns the invocation of a ParserRule Parameter as Java expression.
 */
public String gaRuleParameterAccessor(final Parameter parameter) {
  final ParserRule rule = GrammarUtil.containingParserRule(parameter);
  final int index = rule.getParameters().indexOf(parameter);
  String _gaRuleAccessor = this.gaRuleAccessor(rule);
  String _plus = (_gaRuleAccessor + ".getParameters().get(");
  String _plus_1 = (_plus + Integer.valueOf(index));
  String _plus_2 = (_plus_1 + "/*");
  String _name = parameter.getName();
  String _plus_3 = (_plus_2 + _name);
  return (_plus_3 + "*/)");
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:15,代码来源:GrammarAccessExtensions.java

示例14: _localVar

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected String _localVar(final AbstractElement it) {
  String _xblockexpression = null;
  {
    final ParserRule rule = GrammarUtil.containingParserRule(it);
    final int index = this.contentsAsList(rule).indexOf(it);
    _xblockexpression = ("otherlv_" + Integer.valueOf(index));
  }
  return _xblockexpression;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:10,代码来源:GrammarAccessExtensions.java

示例15: getContainingDatatypeRuleNode

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public INode getContainingDatatypeRuleNode(INode node) {
	INode result = node;
	EObject grammarElement = result.getGrammarElement();
	if (grammarElement != null) {
		ParserRule parserRule = GrammarUtil.containingParserRule(grammarElement);
		while (parserRule != null && GrammarUtil.isDatatypeRule(parserRule)) {
			result = result.getParent();
			grammarElement = result.getGrammarElement();
			parserRule = GrammarUtil.containingParserRule(grammarElement);
		}
	}
	return result;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:ContentAssistContextFactory.java


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