use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.
the class FlattenedGrammarAccess method copyTypeRef.
private TypeRef copyTypeRef(final TypeRef ref) {
if ((ref == null)) {
return null;
}
final TypeRef copy = this.<TypeRef>copy(ref);
copy.setClassifier(ref.getClassifier());
return copy;
}
use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.
the class NodeModelSemanticSequencer method createSequence.
@Override
public void createSequence(ISerializationContext context, EObject semanticObject) {
SemanticNodeIterator ni = new SemanticNodeIterator(semanticObject);
while (ni.hasNext()) {
Triple<INode, AbstractElement, EObject> node = ni.next();
if (node.getSecond() instanceof RuleCall) {
RuleCall rc = (RuleCall) node.getSecond();
TypeRef ruleType = rc.getRule().getType();
if (ruleType == null || ruleType.getClassifier() instanceof EClass)
acceptSemantic(semanticObject, rc, node.getThird(), node.getFirst());
else if (GrammarUtil.containingCrossReference(node.getSecond()) != null) {
EStructuralFeature feature = FeatureFinderUtil.getFeature(node.getSecond(), semanticObject.eClass());
acceptSemantic(semanticObject, rc, semanticObject.eGet(feature), node.getFirst());
} else {
String strVal = NodeModelUtils.getTokenText(node.getFirst());
Object val = valueConverter.toValue(strVal, ruleNames.getQualifiedName(rc.getRule()), node.getFirst());
acceptSemantic(semanticObject, rc, val, node.getFirst());
}
} else if (node.getSecond() instanceof Keyword)
acceptSemantic(semanticObject, node.getSecond(), node.getFirst().getText(), node.getFirst());
else if (node.getSecond() instanceof Action) {
acceptSemantic(semanticObject, node.getSecond(), semanticObject, node.getFirst());
}
}
}
use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.
the class TreeConstNFAToDot method newNode.
@Override
protected Node newNode(EObject semanticObject, String label) {
TreeConstState nfas = nfaProvider.getNFA((AbstractElement) semanticObject);
List<String> types = Lists.newArrayList();
for (TypeRef typeRef : nfas.getTypesToCheck()) types.add(typeRef == null ? "null" : typeRef.getClassifier().getName());
if (semanticObject.eContainer() instanceof AbstractRule) {
AbstractRule rule = (AbstractRule) semanticObject.eContainer();
String typesAsString = types.isEmpty() ? "" : " [" + Joiner.on(",").join(types) + "]";
return new Node(semanticObject, rule.getName() + typesAsString + ":\\n" + label, "record");
} else {
String typesAsString = types.isEmpty() ? "" : "[" + Joiner.on(",").join(types) + "]\\n";
return new Node(semanticObject, typesAsString + label);
}
}
use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method getOrComputeReturnType.
private TypeRef getOrComputeReturnType(AbstractRule rule) {
TypeRef result = rule.getType();
if (result == null) {
EClassifier classifier = getClassifierFor(rule);
if (classifier == null) {
if (rule.getName() == null)
return null;
result = getTypeRef(rule.getName());
} else
result = getTypeRef(classifier);
if (result.getMetamodel() == null) {
AbstractMetamodelDeclaration bestMatch = null;
for (AbstractMetamodelDeclaration decl : grammar.getMetamodelDeclarations()) {
if (decl instanceof GeneratedMetamodel && Strings.isEmpty(decl.getAlias())) {
bestMatch = decl;
break;
}
}
if (result.getMetamodel() == null)
result.setMetamodel(bestMatch);
}
rule.setType(result);
}
return result;
}
use of org.eclipse.xtext.TypeRef in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method getTypeRef.
TypeRef getTypeRef(EClassifier classifier) {
TypeRef result = XtextFactory.eINSTANCE.createTypeRef();
result.setClassifier(classifier);
EPackage pack = classifier.getEPackage();
for (AbstractMetamodelDeclaration decl : GrammarUtil.allMetamodelDeclarations(grammar)) {
if (pack.equals(decl.getEPackage())) {
result.setMetamodel(decl);
return result;
}
}
return result;
}
Aggregations