use of com.nedap.archie.aom.Archetype in project archetype-languageserver by nedap.
the class AQLStorage method completion.
public Either<List<CompletionItem>, CompletionList> completion(CompletionParams position) {
String uri = position.getTextDocument().getUri();
AQLDocument aqlDocument = this.aqlDocumentsByUri.get(uri);
if (aqlDocument == null) {
return Either.forRight(new CompletionList());
}
List<CompletionItem> items = new ArrayList<>();
CompletionList result = new CompletionList(items);
MetaModels metaModels = BuiltinReferenceModels.getMetaModels();
for (ArchetypePathReference reference : aqlDocument.getArchetypePathReferences()) {
// copy the range, adding one because typing at the end of course
Range range = new Range();
range.setStart(new Position(reference.getRange().getStart().getLine(), reference.getRange().getStart().getCharacter()));
range.setEnd(new Position(reference.getRange().getEnd().getLine(), reference.getRange().getEnd().getCharacter() + 1));
if (reference.getArchetypeId() != null && Ranges.containsPosition(range, position.getPosition())) {
// TODO: get operational template here. I think that should be cached?
ValidationResult validationResult = archetypeRepository.getValidationResult(reference.getArchetypeId());
if (validationResult != null && validationResult.getFlattened() != null) {
// ok we have code completion!
// now to find the correct archetype path
Archetype flat = validationResult.getFlattened();
metaModels.selectModel(flat);
PartialAOMPathQuery partialAOMPathQuery = new PartialAOMPathQuery(reference.getPath());
// TODO: get path UP TO where we are typing!
PartialAOMPathQuery.PartialMatch partial = partialAOMPathQuery.findLSPPartial(flat.getDefinition());
// TODO: add BMM path traversal here as well, so you can do /value/magnitude
for (ArchetypeModelObject object : partial.getMatches()) {
if (object instanceof CObject) {
for (CAttribute attribute : ((CObject) object).getAttributes()) {
for (CObject child : attribute.getChildren()) {
if (child.getNodeId() != null && !"id9999".equalsIgnoreCase(child.getNodeId())) {
String text = child.getTerm() == null ? attribute.getRmAttributeName() + "[" + child.getNodeId() + "] (" + child.getRmTypeName() + ")" : child.getTerm().getText() + " (" + attribute.getRmAttributeName() + " " + child.getRmTypeName() + "[" + child.getNodeId() + "])";
CompletionItem completionItem = new CompletionItem(text);
completionItem.setInsertText(attribute.getRmAttributeName() + "[" + child.getNodeId() + "]");
completionItem.setFilterText(attribute.getRmAttributeName() + "[" + child.getNodeId() + "]" + text);
// the 0 is to sort this before others
completionItem.setSortText(attribute.getRmAttributeName() + "0" + text);
completionItem.setKind(CompletionItemKind.Reference);
items.add(completionItem);
}
}
}
BmmClass classDefinition = metaModels.getSelectedBmmModel().getClassDefinition(BmmDefinitions.typeNameToClassKey(((CObject) object).getRmTypeName()));
if (classDefinition != null) {
for (BmmProperty property : classDefinition.getFlatProperties().values()) {
CompletionItem completionItem = new CompletionItem(property.getName() + "(" + property.getType().toDisplayString() + ")");
completionItem.setInsertText(property.getName());
// sort this last please
completionItem.setSortText(property.getName() + "zzzz");
completionItem.setKind(CompletionItemKind.Reference);
items.add(completionItem);
}
}
} else if (object instanceof CAttribute) {
for (CObject child : ((CAttribute) object).getChildren()) {
if (child.getNodeId() != null && !child.getNodeId().equalsIgnoreCase("id9999")) {
CompletionItem completionItem = new CompletionItem();
completionItem.setLabel(child.getTerm() == null ? child.getRmTypeName() : child.getTerm().getText());
completionItem.setInsertText("[" + child.getNodeId() + "]");
completionItem.setKind(CompletionItemKind.Reference);
// completionItem.setInsertText();
items.add(completionItem);
}
}
}
}
}
}
}
return Either.forRight(result);
}
use of com.nedap.archie.aom.Archetype in project archetype-languageserver by nedap.
the class ConvertToOptCommand method apply.
public void apply() {
String documentUri = ((JsonPrimitive) params.getArguments().get(0)).getAsString();
String format = ((JsonPrimitive) params.getArguments().get(1)).getAsString();
String serializedOpt = null;
Flattener flattener = new Flattener(storage, BuiltinReferenceModels.getMetaModels(), FlattenerConfiguration.forOperationalTemplate());
DocumentInformation documentInformation = storage.getDocumentInformation(documentUri);
Archetype archetype = storage.getArchetype(documentInformation.getArchetypeId());
OperationalTemplate opt = (OperationalTemplate) flattener.flatten(archetype);
String extension;
switch(format) {
case "adl":
extension = ".opt2";
serializedOpt = ADLArchetypeSerializer.serialize(opt);
break;
case "json":
extension = "_opt.json";
try {
serializedOpt = JacksonUtil.getObjectMapper().writeValueAsString(opt);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
break;
case "xml":
{
extension = "_opt.xml";
StringWriter sw = new StringWriter();
try {
Marshaller marshaller = JAXBUtil.getArchieJAXBContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(opt, sw);
} catch (JAXBException e) {
throw new RuntimeException(e);
}
serializedOpt = sw.toString();
break;
}
//
default:
throw new UnsupportedOperationException("unsupported format: " + format);
}
String uriToWrite = documentUri.substring(0, documentUri.lastIndexOf("/")) + "/opt/" + opt.getArchetypeId() + extension;
textDocumentService.writeFile(uriToWrite, "opt in " + format, serializedOpt);
}
use of com.nedap.archie.aom.Archetype in project archetype-languageserver by nedap.
the class DocumentLinks method resolveLinkInternal.
/**
* Re-resolve all document links.
* TODO: add incremental compile?
* @param repository
* @param documentLink
* @return
*/
private DocumentLink resolveLinkInternal(BroadcastingArchetypeRepository repository, DocumentLink documentLink) {
if (documentLink.getData() != null) {
String ref = (String) documentLink.getData();
TextDocumentItem document = repository.getDocument(ref);
if (document != null) {
documentLink.setTarget(document.getUri());
DocumentInformation information = repository.getDocumentInformation(document.getUri());
if (information != null && information.getArchetypeId() != null) {
Archetype archetype = repository.getArchetype(information.getArchetypeId());
if (archetype != null && archetype.getOriginalLanguage() != null) {
ArchetypeTerm term = archetype.getTerm(archetype.getDefinition(), archetype.getOriginalLanguage().getCodeString());
if (term != null) {
documentLink.setTooltip(term.getText() + "\n" + term.getDescription());
}
}
}
}
}
return documentLink;
}
use of com.nedap.archie.aom.Archetype in project archetype-languageserver by nedap.
the class ADL14ConvertingStorage method addFile.
public void addFile(TextDocumentItem item) {
ADL14Parser adl14Parser = new ADL14Parser(BuiltinReferenceModels.getMetaModels());
Archetype archetype = null;
try {
archetype = adl14Parser.parse(item.getText(), configuration);
textService.pushDiagnostics(new VersionedTextDocumentIdentifier(item.getUri(), item.getVersion()), null, new ValidationResult(archetype));
adl14Files.put(item.getUri(), archetype);
} catch (ADLParseException ex) {
textService.pushDiagnostics(new VersionedTextDocumentIdentifier(item.getUri(), item.getVersion()), ex.getErrors());
}
}
use of com.nedap.archie.aom.Archetype in project archetype-languageserver by nedap.
the class BroadcastingArchetypeRepository method isDescendant.
private boolean isDescendant(Archetype archetype, String parent) {
Archetype archetypeToCheck = archetype;
int maxTreeDepth = 75;
int i = 0;
while (archetypeToCheck != null && i < maxTreeDepth && archetypeToCheck.getParentArchetypeId() != null) {
if (archetypeToCheck.getParentArchetypeId().startsWith(parent)) {
return true;
}
String parentArchetypeId = archetypeToCheck.getParentArchetypeId();
archetypeToCheck = getArchetype(parentArchetypeId);
i++;
}
return false;
}
Aggregations