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


Java GrammarUtil.getTypeRefName方法代码示例

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


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

示例1: caseTypeRef

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public EClassifier caseTypeRef(TypeRef object) {
	if (object.getClassifier() == null) {
		if (object.getMetamodel() == null || object.getMetamodel().getEPackage() == null)
			return null;
		String name = GrammarUtil.getTypeRefName(object);
		if (Strings.isEmpty(name))
			return null;
		EClassifierInfo info = classifierInfos.getInfo(object.getMetamodel(), name);
		if (info != null)
			object.setClassifier(info.getEClassifier());
	}
	return object.getClassifier();
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:15,代码来源:ElementTypeCalculator.java

示例2: createEClassifierInfo

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private EClassifierInfo createEClassifierInfo(TypeRef typeRef, String name) throws TransformationException {
	if (eClassifierInfos.getInfo(typeRef) != null)
		throw new IllegalArgumentException("Cannot create EClass for same type twice "
				+ typeRef.getClassifier().getName());
	//					+ GrammarUtil.getQualifiedName(typeRef));

	String classifierName = GrammarUtil.getTypeRefName(typeRef);
	if (classifierName == null)
		classifierName = name;
	if (classifierName == null)
		throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot reference unnamed type.", typeRef);

	AbstractMetamodelDeclaration metaModel = typeRef.getMetamodel();
	if (metaModel == null)
		throw new TransformationException(TransformationErrorCode.UnknownMetaModelAlias, "Cannot create type for " + classifierName
				+ " because its EPackage is unknown.", typeRef);
	EPackage generatedEPackage = getGeneratedEPackage(metaModel);
	if (generatedEPackage == null) {
		throw new TransformationException(TransformationErrorCode.CannotCreateTypeInSealedMetamodel,
				"Cannot create type '" + classifierName + "' in alias " + typeRef.getMetamodel().getAlias(), typeRef);
	}

	EClassifier classifier = generatedEPackage.getEClassifier(classifierName);
	if (classifier == null) {
		if (GrammarUtil.containingParserRule(typeRef) != null) {
			classifier = EcoreFactory.eINSTANCE.createEClass();
		} else if (GrammarUtil.containingEnumRule(typeRef) != null) {
			classifier = EcoreFactory.eINSTANCE.createEEnum();
		} else {
			for (AbstractMetamodelDeclaration mmd : grammar.getMetamodelDeclarations()) {
				if (mmd instanceof ReferencedMetamodel && mmd.getEPackage() != null && mmd.getEPackage().getNsURI().equals(EcorePackage.eNS_URI)) {
					throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot create datatype " + classifierName, typeRef);
				}
			}
			throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot create datatype " + classifierName + ". If this is supposed to return EString, make sure you have imported '"+EcorePackage.eNS_URI+"'", typeRef);
		}
		classifier.setName(classifierName);
		generatedEPackage.getEClassifiers().add(classifier);
		typeRef.setClassifier(classifier);

		EClassifierInfo result;
		if (classifier instanceof EClass)
			result = EClassifierInfo.createEClassInfo((EClass) classifier, true, getGeneratedEPackageURIs(), GrammarUtil.getGrammar(typeRef));
		else // datatype or enum
			result = EClassifierInfo.createEDataTypeInfo((EDataType) classifier, true);

		if (!eClassifierInfos.addInfo(typeRef, result))
			throw new IllegalStateException("cannot add type for typeRef twice: '" + classifierName + "'");
		SourceAdapter.adapt(classifier, typeRef);
		return result;
	}
	typeRef.setClassifier(classifier);
	SourceAdapter.adapt(classifier, typeRef);
	return eClassifierInfos.getInfo(classifier);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:56,代码来源:Xtext2EcoreTransformer.java

示例3: setDefaultValueImpl

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
protected void setDefaultValueImpl(EObject obj, EReference ref, IDiagnosticProducer producer) {
	if (XtextPackage.eINSTANCE.getTypeRef_Metamodel() == ref) {
		final TypeRef typeRef = (TypeRef) obj;
		final String typeRefName = GrammarUtil.getTypeRefName(typeRef);
		final List<EObject> metamodels = XtextMetamodelReferenceHelper.findBestMetamodelForType(typeRef, "",
				typeRefName, scopeProvider.getScope(typeRef, ref));
		if (metamodels.isEmpty() || metamodels.size() > 1)
			producer.addDiagnostic(new DiagnosticMessage("Cannot find meta model for type '" + typeRefName + "'", Severity.ERROR, null));
		else
			typeRef.setMetamodel((AbstractMetamodelDeclaration) metamodels.get(0));
	} else if (XtextPackage.eINSTANCE.getCrossReference_Terminal() == ref) {
		AbstractRule rule = GrammarUtil.findRuleForName(GrammarUtil.getGrammar(obj), "ID");
		if (rule == null)
			producer.addDiagnostic(new DiagnosticMessage("Cannot resolve implicit reference to rule 'ID'", Severity.ERROR, null));
		else {
			RuleCall call = XtextFactory.eINSTANCE.createRuleCall();
			call.setRule(rule);
			((CrossReference) obj).setTerminal(call);
		}
	} else if (XtextPackage.eINSTANCE.getNamedArgument_Parameter() == ref) {
		final NamedArgument argument = (NamedArgument) obj;
		if (!argument.isCalledByName()) {
			RuleCall ruleCall = EcoreUtil2.getContainerOfType(argument, RuleCall.class);
			AbstractRule calledRule = ruleCall.getRule();
			if (!(calledRule instanceof ParserRule)) {
				producer.addDiagnostic(new DiagnosticMessage("Arguments can only be used with parser rules.", Severity.ERROR, null));	
				return;
			}
			if (!calledRule.eIsProxy()) {
				ParserRule casted = (ParserRule) calledRule;
				int idx = ruleCall.getArguments().indexOf(argument);
				if (idx < casted.getParameters().size()) {
					argument.setParameter(casted.getParameters().get(idx));
					return;
				} else if (casted.getParameters().size() == 0) {
					producer.addDiagnostic(new DiagnosticMessage(
							"Rule " + calledRule.getName() + " has no arguments.", Severity.ERROR, null));
				} else {
					String message = "Invalid number of arguments for rule " + calledRule.getName() + ", expecting "
							+ casted.getParameters().size() + " but was " + (idx+1);
					producer.addDiagnostic(new DiagnosticMessage(message, Severity.ERROR, null));
				}
			}
		}
	} else {
		super.setDefaultValueImpl(obj, ref, producer);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:50,代码来源:XtextLinker.java

示例4: getTypeRefName

import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected String getTypeRefName(TypeRef typeRef) {
	String simpleName = GrammarUtil.getTypeRefName(typeRef);
	if (typeRef.getMetamodel() != null && !Strings.isEmpty(typeRef.getMetamodel().getAlias()))
		return typeRef.getMetamodel().getAlias() + "::" + simpleName;
	return simpleName;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:7,代码来源:XtextRuleInspector.java


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