use of com.reprezen.swagedit.core.model.Model in project KaiZen-OpenAPI-Editor by RepreZen.
the class QuickOutline method setInput.
@Override
public void setInput(Object input) {
if (input instanceof Model) {
Model model = (Model) input;
if (model.getPath() == null) {
IFile currentFile = null;
IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof IFileEditorInput) {
currentFile = ((IFileEditorInput) editorInput).getFile();
}
if (currentFile != null) {
model.setPath(currentFile.getFullPath());
}
}
}
treeViewer.setInput(input);
treeViewer.setSelection(null, true);
}
use of com.reprezen.swagedit.core.model.Model in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonContentAssistProcessor method getContextType.
@Override
protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) {
Model model = null;
if (viewer.getDocument() instanceof JsonDocument) {
model = ((JsonDocument) viewer.getDocument()).getModel();
}
String contextType = getContextTypeId(model, currentPath.toString());
ContextTypeRegistry registry = getContextTypeRegistry();
if (registry != null) {
return registry.getContextType(contextType);
} else {
return null;
}
}
use of com.reprezen.swagedit.core.model.Model in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonContentAssistProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
if (!(viewer.getDocument() instanceof JsonDocument)) {
return super.computeCompletionProposals(viewer, documentOffset);
}
maybeSwitchScope(documentOffset);
final JsonDocument document = (JsonDocument) viewer.getDocument();
final ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
int line = 0, lineOffset = 0, column = 0;
try {
line = document.getLineOfOffset(documentOffset);
lineOffset = document.getLineOffset(line);
column = selection.getOffset() - lineOffset;
} catch (BadLocationException e) {
}
final String prefix = extractPrefix(viewer, documentOffset);
// column to resolve the path
if (!prefix.isEmpty()) {
column -= prefix.length();
}
Model model = document.getModel(documentOffset - prefix.length());
currentPath = model.getPath(line, column);
isRefCompletion = referenceProposalProvider.canProvideProposal(model, currentPath);
Collection<Proposal> p;
if (isRefCompletion) {
updateStatus(model);
p = referenceProposalProvider.getProposals(currentPath, document, currentScope);
} else {
clearStatus();
p = proposalProvider.getProposals(currentPath, model, prefix);
}
final Collection<ICompletionProposal> proposals = getCompletionProposals(p, prefix, documentOffset);
// compute template proposals
if (!isRefCompletion) {
final ICompletionProposal[] templateProposals = super.computeCompletionProposals(viewer, documentOffset);
if (templateProposals != null && templateProposals.length > 0) {
proposals.addAll(Lists.newArrayList(templateProposals));
}
}
return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
use of com.reprezen.swagedit.core.model.Model in project KaiZen-OpenAPI-Editor by RepreZen.
the class LinkOperationHyperlinkDetector method doDetect.
@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
Model model = doc.getModel();
AbstractNode node = model.find(pointer);
List<AbstractNode> nodes = model.findByType(JsonPointer.compile("/definitions/operation"));
Iterator<AbstractNode> it = nodes.iterator();
AbstractNode found = null;
while (it.hasNext() && found == null) {
AbstractNode current = it.next();
AbstractNode value = current.get("operationId");
if (value != null && Objects.equals(node.asValue().getValue(), value.asValue().getValue())) {
found = value;
}
}
if (found != null) {
IRegion target = doc.getRegion(found.getPointer());
if (target != null) {
return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
}
}
return null;
}
use of com.reprezen.swagedit.core.model.Model in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonReferenceValidator method findTarget.
protected AbstractNode findTarget(JsonDocument doc, URI baseURI, JsonReference reference) {
Model model = doc.getModel();
AbstractNode valueNode = model.find(reference.getPointer());
if (valueNode == null) {
// Try to load the referenced node from an external document
JsonNode externalDoc = reference.getDocument(doc, baseURI);
if (externalDoc != null) {
try {
Model externalModel = Model.parse(model.getSchema(), externalDoc);
valueNode = externalModel.find(reference.getPointer());
} catch (Exception e) {
// fail to parse the model or the pointer
return null;
}
}
}
return valueNode;
}
Aggregations