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


Java RuleNames类代码示例

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


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

示例1: getGrammarPDAs

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
@Override
public SerializationContextMap<Pda<ISerState, RuleCall>> getGrammarPDAs(Grammar grammar) {
	RuleNames names = RuleNames.getRuleNames(grammar, true);
	RuleFilter filter = new RuleFilter();
	filter.setDiscardTerminalRules(true);
	filter.setDiscardUnreachableRules(false);
	filter.setDiscardRuleTypeRef(false);
	Grammar flattened = new FlattenedGrammarAccess(names, filter).getFlattenedGrammar();
	Builder<Pda<ISerState, RuleCall>> result = SerializationContextMap.<Pda<ISerState, RuleCall>>builder();
	for (ParserRule rule : GrammarUtil.allParserRules(flattened)) {
		RuleWithParameterValues withParams = RuleWithParameterValues.findInEmfObject(rule);
		AbstractRule original = withParams.getOriginal();
		if (original instanceof ParserRule && isValidRule((ParserRule) original)) {
			ISerializationContext context = createContext((ParserRule) original, withParams.getParamValues());
			try {
				Pda<ISerState, RuleCall> pda = createPDA(grammar, rule);
				result.put(context, pda);
			} catch (Exception e) {
				LOG.error("Error creating PDA for context '" + context + "': " + e.getMessage(), e);
			}
		}
	}
	return result.create();
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:25,代码来源:GrammarPDAProvider.java

示例2: FlattenedGrammarAccess

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
public FlattenedGrammarAccess(final RuleNames names, final RuleFilter filter) {
  final Grammar grammar = names.getContextGrammar();
  Grammar flattenedGrammar = this.<Grammar>copy(grammar);
  flattenedGrammar.setName(grammar.getName());
  LinkedHashMap<RuleWithParameterValues, AbstractRule> origToCopy = Maps.<RuleWithParameterValues, AbstractRule>newLinkedHashMap();
  final ArrayList<AbstractRule> copies = this.copyRuleStubs(names, origToCopy, filter.getRules(grammar), filter.isDiscardRuleTypeRef());
  EList<AbstractRule> _rules = flattenedGrammar.getRules();
  Iterables.<AbstractRule>addAll(_rules, copies);
  Multimap<TerminalRule, AbstractRule> calledFrom = this.copyRuleBodies(copies, origToCopy);
  this.setHiddenTokens(flattenedGrammar, grammar, origToCopy);
  this.markAsFragment(calledFrom);
  boolean _isDiscardUnreachableRules = filter.isDiscardUnreachableRules();
  if (_isDiscardUnreachableRules) {
    Set<AbstractRule> usedRules = CollectionLiterals.<AbstractRule>newHashSet();
    boolean _isDiscardTerminalRules = filter.isDiscardTerminalRules();
    boolean _not = (!_isDiscardTerminalRules);
    if (_not) {
      usedRules.addAll(GrammarUtil.allTerminalRules(flattenedGrammar));
    }
    UsedRulesFinder finder = new UsedRulesFinder(usedRules);
    finder.compute(flattenedGrammar);
    flattenedGrammar.getRules().retainAll(usedRules);
  }
  this.flattenedGrammar = flattenedGrammar;
  new OriginalGrammar(grammar).attachToEmfObject(flattenedGrammar);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:27,代码来源:FlattenedGrammarAccess.java

示例3: generate

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
public void generate(final Grammar it, final AntlrOptions options, final IXtextGeneratorFileSystemAccess fsa) {
  this.keywordHelper = KeywordHelper.getHelper(it);
  this.originalGrammar = it;
  final RuleFilter filter = new RuleFilter();
  filter.setDiscardUnreachableRules(options.isSkipUnusedRules());
  final RuleNames ruleNames = RuleNames.getRuleNames(it, true);
  final Grammar flattened = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar();
  boolean _isCombinedGrammar = this.isCombinedGrammar();
  new CombinedGrammarMarker(_isCombinedGrammar).attachToEmfObject(flattened);
  fsa.generateFile(this.getGrammarNaming().getParserGrammar(it).getGrammarFileName(), this.compileParser(flattened, options));
  boolean _isCombinedGrammar_1 = this.isCombinedGrammar();
  boolean _not = (!_isCombinedGrammar_1);
  if (_not) {
    fsa.generateFile(this.getGrammarNaming().getLexerGrammar(it).getGrammarFileName(), this.compileLexer(flattened, options));
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:17,代码来源:AbstractAntlrGrammarGenerator.java

示例4: generate

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	checkGrammar(grammar);
	
	RuleFilter filter = new RuleFilter();
	filter.setDiscardUnreachableRules(getOptions().isSkipUnusedRules());
	RuleNames ruleNames = RuleNames.getRuleNames(grammar, true);
	Grammar flattened = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar();
	super.generate(flattened, ctx);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:AbstractAntlrGeneratorFragment.java

示例5: generate

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	RuleNames.ensureAdapterInstalled(grammar);
	super.generate(grammar, ctx);

	final ResourceSaveIndicator isSaving = new ResourceSaveIndicator();
	// create a defensive clone
	Grammar copy = deepCopy(grammar, isSaving);
	ResourceSet set = copy.eResource().getResourceSet();

	// save grammar model
	String path;
	if (xmlVersion == null) {
		path = GrammarUtil.getClasspathRelativePathToBinGrammar(copy);
	} else {
		log.warn("'xmlVersion' has been specified for this "
				+ GrammarAccessFragment.class.getSimpleName()
				+ ". Therefore, the grammar is persisted as XMI and not as binary. This can be a performance drawback.");
		path = GrammarUtil.getClasspathRelativePathToXmi(copy);
	}
	URI uri = URI.createURI(ctx.getOutput().getOutlet(Generator.SRC_GEN).getPath() + "/" + path);
	Resource resource = set.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	addAllGrammarsToResource(resource, copy, new HashSet<Grammar>());
	isSaving.set(Boolean.TRUE);
	Map<String, Object> saveOptions = Maps.newHashMap();
	if (resource instanceof XMLResource) {
		((XMLResource) resource).setXMLVersion(getXmlVersion());
	} else if (resource instanceof BinaryResourceImpl){
		saveOptions.put(BinaryResourceImpl.OPTION_VERSION, BinaryResourceImpl.BinaryIO.Version.VERSION_1_1);
		saveOptions.put(BinaryResourceImpl.OPTION_STYLE_DATA_CONVERTER, Boolean.TRUE);
	}
	try {
		resource.save(saveOptions);
	} catch (IOException e) {
		log.error(e.getMessage(), e);
	} finally {
		isSaving.set(Boolean.FALSE);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:40,代码来源:GrammarAccessFragment.java

示例6: getRuleName

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
/**
 * Returns the effective rule name for the generated Antlr grammar.
 * Inherited rules may be prefixed by {@code super[0..9]*}. Otherwise the
 * prefix {@code rule or RULE_} is used.
 * @since 2.9
 */
public static String getRuleName(AbstractRule rule) {
	RuleWithParameterValues parameterValues = RuleWithParameterValues.findInEmfObject(rule);
	if (parameterValues != null) {
		return rule.getName();
	}
	RuleNames ruleNames = RuleNames.getRuleNames(rule);
	return ruleNames.getAntlrRuleName(rule);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:15,代码来源:AntlrGrammarGenUtil.java

示例7: ruleName

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
public String ruleName(final AbstractRule rule) {
  final RuleNames ruleNames = RuleNames.tryGetRuleNames(rule);
  String _elvis = null;
  String _antlrRuleName = null;
  if (ruleNames!=null) {
    _antlrRuleName=ruleNames.getAntlrRuleName(rule);
  }
  if (_antlrRuleName != null) {
    _elvis = _antlrRuleName;
  } else {
    String _ruleName = AntlrGrammarGenUtil.getRuleName(rule);
    _elvis = _ruleName;
  }
  return _elvis;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:16,代码来源:GrammarAccessExtensions.java

示例8: getModel

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
public Grammar getModel(final String model, final boolean dropUnreachable) throws Exception {
  EObject _model = super.getModel(model);
  Grammar grammar = ((Grammar) _model);
  RuleNames ruleNames = RuleNames.getRuleNames(grammar, false);
  RuleFilter filter = new RuleFilter();
  filter.setDiscardUnreachableRules(dropUnreachable);
  Grammar result = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar();
  XtextResource resource = this.<XtextResource>get(XtextResource.class);
  resource.getContents().add(result);
  resource.setURI(URI.createURI("synthetic://flattened.xtext"));
  return result;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:GrammarFlatteningTest.java

示例9: readRuleNames

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
@Inject
private void readRuleNames(N4JSGrammarAccess grammarAccess, RuleNames ruleNames) {
	stringRuleName = ruleNames.getQualifiedName(grammarAccess.getSTRINGRule());
	identifierRuleName = ruleNames.getQualifiedName(grammarAccess.getIdentifierNameRule());
	numberRuleName = ruleNames.getQualifiedName(grammarAccess.getNumericLiteralAsStringRule());
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:7,代码来源:PropertyNameAwareElementFactory.java

示例10: setDelegateRuleName

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
@Inject
private void setDelegateRuleName(N4JSGrammarAccess grammarAccess, RuleNames ruleNames) {
	delegateRule = grammarAccess.getIDENTIFIERRule();
	this.delegateRuleName = ruleNames.getQualifiedName(delegateRule);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:6,代码来源:QualifiedTypeReferenceNameValueConverter.java

示例11: getUniqueRuleName

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
/**
 * @since 2.9
 */
public static String getUniqueRuleName(AbstractRule rule) {
	String plainName = RuleNames.getRuleNames(rule).getUniqueRuleName(rule);
	return toJavaIdentifier(plainName, true);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:8,代码来源:GrammarAccessUtil.java

示例12: setGrammar

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
@Inject
private void setGrammar(RuleNames names) {
	wsRule = Iterables.getFirst(names.getRulesBySimpleName("WS"), null);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:5,代码来源:DefaultHiddenTokenHelper.java

示例13: getContextName

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
public String getContextName(Grammar grammar, ParserRule ctx) {
	if (grammar == null) {
		return ctx.getName();	
	}
	return RuleNames.getRuleNames(grammar, false).getUniqueRuleName(ctx);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:7,代码来源:Context2NameFunction.java

示例14: getQualifiedNameAsString

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
/**
 * @since 2.9
 */
public static String getQualifiedNameAsString(RuleCall ruleCall) {
	AbstractRule rule = getOriginalElement(ruleCall).getRule();
	String result = RuleNames.getRuleNames(rule).getQualifiedName(rule);
	return '"' + result + '"';
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:9,代码来源:AntlrGrammarGenUtil.java

示例15: gaRuleIdentifier

import org.eclipse.xtext.xtext.RuleNames; //导入依赖的package包/类
/**
 * Creates an identifier for a Rule which is a valid Java identifier and unique within
 * the Rule's grammar and its super grammars.
 */
public String gaRuleIdentifier(final AbstractRule rule) {
  final String plainName = RuleNames.getRuleNames(rule).getUniqueRuleName(rule);
  return this.toJavaIdentifier(plainName, true);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:9,代码来源:GrammarAccessExtensions.java


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