use of org.eclipse.xtext.example.domainmodel.domainmodel.Entity in project xtext-eclipse by eclipse.
the class DomainmodelParsingTest method testParsing.
@Test
public void testParsing() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package example {");
_builder.newLine();
_builder.append(" ");
_builder.append("entity MyEntity {");
_builder.newLine();
_builder.append(" ");
_builder.append("property : String");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final DomainModel model = this._parseHelper.parse(_builder);
AbstractElement _head = IterableExtensions.<AbstractElement>head(model.getElements());
final PackageDeclaration pack = ((PackageDeclaration) _head);
Assert.assertEquals("example", pack.getName());
AbstractElement _head_1 = IterableExtensions.<AbstractElement>head(pack.getElements());
final Entity entity = ((Entity) _head_1);
Assert.assertEquals("MyEntity", entity.getName());
Feature _head_2 = IterableExtensions.<Feature>head(entity.getFeatures());
final Property property = ((Property) _head_2);
Assert.assertEquals("property", property.getName());
Assert.assertEquals("java.lang.String", property.getType().getIdentifier());
}
use of org.eclipse.xtext.example.domainmodel.domainmodel.Entity in project xtext-eclipse by eclipse.
the class DomainmodelParsingTest method testReturnTypeInference.
@Test
public void testReturnTypeInference() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package example {");
_builder.newLine();
_builder.append(" ");
_builder.append("entity MyEntity {");
_builder.newLine();
_builder.append(" ");
_builder.append("property : String");
_builder.newLine();
_builder.append(" ");
_builder.append("op foo(String s) {");
_builder.newLine();
_builder.append(" \t");
_builder.append("return property.toUpperCase + s");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final DomainModel model = this._parseHelper.parse(_builder);
AbstractElement _head = IterableExtensions.<AbstractElement>head(model.getElements());
final PackageDeclaration pack = ((PackageDeclaration) _head);
AbstractElement _head_1 = IterableExtensions.<AbstractElement>head(pack.getElements());
final Entity entity = ((Entity) _head_1);
Feature _last = IterableExtensions.<Feature>last(entity.getFeatures());
final Operation op = ((Operation) _last);
EObject _head_2 = IterableExtensions.<EObject>head(this._iJvmModelAssociations.getJvmElements(op));
final JvmOperation method = ((JvmOperation) _head_2);
Assert.assertEquals("String", method.getReturnType().getSimpleName());
}
use of org.eclipse.xtext.example.domainmodel.domainmodel.Entity in project xtext-eclipse by eclipse.
the class DomainmodelCodeMiningProvider method createCodeMinings.
@Override
protected void createCodeMinings(IDocument document, XtextResource resource, CancelIndicator indicator, IAcceptor<? super ICodeMining> acceptor) throws BadLocationException {
if (resource.getContents().isEmpty()) {
return;
}
// get all entities in the open document
List<Entity> allEntities = EcoreUtil2.eAllOfType(resource.getContents().get(0), Entity.class);
for (Entity e : allEntities) {
int propertiesCount = (int) e.getFeatures().stream().filter(f -> (f instanceof Property)).count();
String propertiesHeaderText = propertiesCount + " " + (propertiesCount == 1 ? "property" : "properties");
int operationsCount = (int) e.getFeatures().stream().filter(f -> (f instanceof Operation)).count();
String operationsHeaderText = operationsCount + " operation" + (operationsCount == 1 ? "" : "s");
ICompositeNode node = NodeModelUtils.getNode(e);
int beforeLineNumber = document.getLineOfOffset(node.getOffset());
// create two line header code minings before the entity: one for the properties, one for the operations
acceptor.accept(createNewLineHeaderCodeMining(beforeLineNumber, document, propertiesHeaderText));
acceptor.accept(createNewLineHeaderCodeMining(beforeLineNumber, document, operationsHeaderText));
}
// get all operations in the open document
List<Operation> allOperations = EcoreUtil2.eAllOfType(resource.getContents().get(0), Operation.class);
// get keyword for ')'
Keyword rightParenthesisKeyword_4 = grammar.getOperationAccess().getRightParenthesisKeyword_4();
for (Operation o : allOperations) {
// inline annotations only for methods with no return type
if (o.getType() != null) {
continue;
}
// get return type name from operation
JvmOperation inferredOp = (JvmOperation) jvmModelAssociations.getPrimaryJvmElement(o);
if (inferredOp == null || inferredOp.getReturnType() == null) {
// broken model
continue;
}
String returnTypeName = inferredOp.getReturnType().getSimpleName();
// find document offset for inline annotation
ICompositeNode node = NodeModelUtils.findActualNodeFor(o);
for (Iterator<INode> it = node.getAsTreeIterable().iterator(); it.hasNext(); ) {
INode child = it.next();
if (rightParenthesisKeyword_4.equals(child.getGrammarElement())) {
// create line content code mining for inline annotation after grammarElement ')'
String annotationText = " : " + returnTypeName;
acceptor.accept(createNewLineContentCodeMining(child.getTotalOffset() + 1, annotationText));
}
}
}
}
use of org.eclipse.xtext.example.domainmodel.domainmodel.Entity in project xtext-eclipse by eclipse.
the class DomainmodelLinkingDiagnosticMessageProvider method getUnresolvedProxyMessage.
@Override
public DiagnosticMessage getUnresolvedProxyMessage(final ILinkingDiagnosticContext context) {
EObject element = context.getContext();
if (element instanceof JvmTypeReference) {
JvmTypeReference jvmTypeReference = (JvmTypeReference) element;
DiagnosticMessage diagnosticMessage = new DomainmodelSwitch<DiagnosticMessage>() {
@Override
public DiagnosticMessage caseEntity(Entity entity) {
return new DiagnosticMessage("Missing supertype " + context.getLinkText(), Severity.ERROR, IssueCodes.MISSING_TYPE, context.getLinkText());
}
@Override
public DiagnosticMessage caseProperty(Property property) {
return new DiagnosticMessage("Missing property type " + context.getLinkText(), Severity.ERROR, IssueCodes.MISSING_TYPE, context.getLinkText());
}
@Override
public DiagnosticMessage caseOperation(Operation operation) {
return new DiagnosticMessage("Missing return type " + context.getLinkText(), Severity.ERROR, IssueCodes.MISSING_TYPE, context.getLinkText());
}
}.doSwitch(jvmTypeReference.eContainer());
if (diagnosticMessage != null)
return diagnosticMessage;
}
return super.getUnresolvedProxyMessage(context);
}
use of org.eclipse.xtext.example.domainmodel.domainmodel.Entity in project xtext-eclipse by eclipse.
the class AssociationHierarchyBuilder method findDeclaration.
@Override
protected IEObjectDescription findDeclaration(final URI objectURI) {
final IEObjectDescription description = this.getDescription(objectURI);
EClass _eClass = null;
if (description != null) {
_eClass = description.getEClass();
}
boolean _isJvmType = this.isJvmType(_eClass);
if (_isJvmType) {
final IUnitOfWork<IEObjectDescription, EObject> _function = (EObject targetElement) -> {
final EObject sourceElement = this._iJvmModelAssociations.getPrimarySourceElement(targetElement);
EClass _eClass_1 = null;
if (sourceElement != null) {
_eClass_1 = sourceElement.eClass();
}
boolean _isEntity = this.isEntity(_eClass_1);
if (_isEntity) {
return this.getDescription(sourceElement);
}
return null;
};
return this.<IEObjectDescription>readOnly(description.getEObjectURI(), _function);
}
EClass _eClass_1 = null;
if (description != null) {
_eClass_1 = description.getEClass();
}
boolean _isEntity = this.isEntity(_eClass_1);
if (_isEntity) {
return description;
}
final IUnitOfWork<IEObjectDescription, EObject> _function_1 = (EObject object) -> {
return this.getDescription(EcoreUtil2.<Entity>getContainerOfType(object, Entity.class));
};
return this.<IEObjectDescription>readOnly(objectURI, _function_1);
}
Aggregations