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


Java EcoreUtil2.getAllContentsOfType方法代码示例

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


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

示例1: checkGeneratedEnumIsValid

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
@Check
public void checkGeneratedEnumIsValid(EnumLiteralDeclaration decl) {
	EnumRule rule = GrammarUtil.containingEnumRule(decl);
	if (!(rule.getType().getMetamodel() instanceof GeneratedMetamodel))
		return;
	if (!(rule.getType().getClassifier() instanceof EEnum))
		return;
	EEnum eEnum = (EEnum) rule.getType().getClassifier();
	List<EnumLiteralDeclaration> declarations = EcoreUtil2.getAllContentsOfType(rule, EnumLiteralDeclaration.class);
	if (declarations.size() == eEnum.getELiterals().size())
		return;
	for (EnumLiteralDeclaration otherDecl : declarations) {
		if (decl == otherDecl) {
			return;
		}
		if (otherDecl.getEnumLiteral() == decl.getEnumLiteral()) {
			if (!decl.getEnumLiteral().getLiteral().equals(decl.getLiteral().getValue()))
				addIssue("Enum literal '" + decl.getEnumLiteral().getName()
						+ "' has already been defined with literal '" + decl.getEnumLiteral().getLiteral() + "'.",
						decl,
						XtextPackage.Literals.ENUM_LITERAL_DECLARATION__ENUM_LITERAL,
						DUPLICATE_ENUM_LITERAL);
			return;
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:27,代码来源:XtextValidator.java

示例2: getCrossReferencesWithSameEReference

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
private static List<CrossReference> getCrossReferencesWithSameEReference(CrossReference cr) {
	Grammar g = GrammarUtil.getGrammar(cr);
	EReference ref = GrammarUtil.getReference(cr);
	List<CrossReference> result = Lists.newArrayList();
	for (CrossReference c : EcoreUtil2.getAllContentsOfType(g, CrossReference.class))
		if (GrammarUtil.getReference(c) == ref)
			result.add(c);
	return result;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:10,代码来源:ParseTreeConstructorUtil.java

示例3: reportError

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
private void reportError(EClassifierInfo info, TransformationErrorCode errorCode, String message) {
	if (grammar == null) {
		reportError(errorCode, message, null);
		return;
	}
	List<TypeRef> typeRefs = EcoreUtil2.getAllContentsOfType(grammar, TypeRef.class);
	for(TypeRef typeRef: typeRefs) {
		EClassifierInfo otherInfo = infos.getInfo(typeRef);
		if (otherInfo == info)
			reportError(errorCode, message, typeRef);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:TypeHierarchyHelper.java

示例4: checkEnumLiteralIsUnique

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
@Check
public void checkEnumLiteralIsUnique(EnumLiteralDeclaration decl) {
	EnumRule rule = GrammarUtil.containingEnumRule(decl);
	List<EnumLiteralDeclaration> declarations = EcoreUtil2.getAllContentsOfType(rule, EnumLiteralDeclaration.class);
	String literal = decl.getLiteral().getValue();
	if (literal != null) {
		for (EnumLiteralDeclaration otherDecl : declarations) {
			if (otherDecl != decl && literal.equals(otherDecl.getLiteral().getValue())) {
				error("Enum literal '" + literal + "' is used multiple times in enum rule '" + rule.getName() + "'.",
						XtextPackage.Literals.ENUM_LITERAL_DECLARATION__LITERAL);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:15,代码来源:XtextValidator.java

示例5: addQualified

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
protected String addQualified(String result, AbstractElement ele) {
	if (!showQualified && !showRule)
		return result;
	AbstractRule rule = GrammarUtil.containingRule(ele);
	if (rule == null)
		return "<AbstractElement not contained in AbstractRule!>:" + result;
	if (!showQualified)
		return result + ":" + rule.getName();
	GrammarElementTitleSwitch others = copy();
	others.showQualified = false;
	others.showRule = false;
	List<AbstractElement> elementsWithSameName = Lists.newArrayList();
	for (AbstractElement candidate : EcoreUtil2.getAllContentsOfType(rule, ele.getClass()))
		if (candidate == ele || result.equals(others.doSwitch(candidate)))
			elementsWithSameName.add(candidate);
	if (elementsWithSameName.size() < 2) {
		if (showRule)
			return rule.getName() + ":" + result;
		return result;
	}
	Map<CompoundElement, Node> nodes = Maps.newHashMap();
	for (AbstractElement collision : elementsWithSameName) {
		EObject current = EcoreUtil2.getContainerOfType(collision, CompoundElement.class);
		Node node = new Node(null, collision == ele ? result : "");
		while (current instanceof CompoundElement) {
			CompoundElement container = (CompoundElement) current;
			Node cntNode = nodes.get(container);
			if (cntNode == null)
				nodes.put(container, cntNode = new Node(container, null));
			if (!cntNode.children.contains(node))
				cntNode.children.add(node);
			node = cntNode;
			current = current.eContainer();
		}
	}
	if (showRule)
		return rule.getName() + ":" + nodes.get(rule.getAlternatives());
	return nodes.get(rule.getAlternatives()).toString();
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:40,代码来源:GrammarElementTitleSwitch.java

示例6: deriveEnums

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
private void deriveEnums(EnumRule rule) {
	EEnum returnType = (EEnum) rule.getType().getClassifier();
	if (returnType != null) {
		List<EnumLiteralDeclaration> decls = EcoreUtil2.getAllContentsOfType(rule, EnumLiteralDeclaration.class);
		for(EnumLiteralDeclaration decl : decls) {
			if (decl.getEnumLiteral() == null) {
				List<INode> nodes = NodeModelUtils.findNodesForFeature(decl, XtextPackage.Literals.ENUM_LITERAL_DECLARATION__ENUM_LITERAL);
				if (!nodes.isEmpty()) {
					if (nodes.size() > 1)
						throw new IllegalStateException("Unexpected nodes found: " + nodes);
					INode node = nodes.get(0);
					String text = node.getText();
					EEnumLiteral literal = null;
					if (rule.getType().getMetamodel() instanceof ReferencedMetamodel) {
						literal = returnType.getEEnumLiteral(text);
					} else {
						EEnumLiteral existing = returnType.getEEnumLiteral(text);
						if (existing == null) {
							literal = EcoreFactory.eINSTANCE.createEEnumLiteral();
							int index = returnType.getELiterals().size();
							returnType.getELiterals().add(literal);
							literal.setName(text);
							literal.setValue(index);
							if (decl.getLiteral() != null) {
								literal.setLiteral(decl.getLiteral().getValue());
							} else {
								literal.setLiteral(text);
							}
						} else {
							literal = existing;
						}
						SourceAdapter.adapt(literal, decl);
					}
					if (literal == null) {
						reportError(new TransformationException(TransformationErrorCode.InvalidFeature, "Enum literal '" + text + "' does not exist.", decl));
					} else {
						decl.setEnumLiteral(literal);
					}
				}
			}
			if (decl.getLiteral() == null && decl.getEnumLiteral() != null) {
				Keyword kw = XtextFactory.eINSTANCE.createKeyword();
				kw.setValue(decl.getEnumLiteral().getLiteral());
				decl.setLiteral(kw);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:49,代码来源:Xtext2EcoreTransformer.java

示例7: checkNegatedTokenNotEOF

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
@Check
public void checkNegatedTokenNotEOF(NegatedToken token) {
	for (EOF eof : EcoreUtil2.getAllContentsOfType(token, EOF.class)) {
		error("It is not possible to negate EOF", eof, null);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:7,代码来源:XtextValidator.java

示例8: checkEnums

import org.eclipse.xtext.EcoreUtil2; //导入方法依赖的package包/类
private void checkEnums(Grammar grammar) {
	List<EnumLiteralDeclaration> decls = EcoreUtil2.getAllContentsOfType(grammar, EnumLiteralDeclaration.class);
	for(EnumLiteralDeclaration decl: decls) {
		assertNotNull(decl.getLiteral());
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:7,代码来源:GrammarParserTest.java


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