use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonReferenceHyperlinkDetector method doDetect.
@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
URI baseURI = getBaseURI();
AbstractNode node = doc.getModel().find(pointer);
JsonReference reference = getFactory().createSimpleReference(getBaseURI(), node);
if (reference == null) {
reference = getFactory().create(node);
}
if (reference.isInvalid() || reference.isMissing(doc, getBaseURI())) {
return null;
}
if (reference.isLocal()) {
IRegion target = doc.getRegion(reference.getPointer());
if (target == null) {
return null;
}
return new IHyperlink[] { new SwaggerHyperlink(reference.getPointer().toString(), viewer, info.region, target) };
} else {
URI resolved;
try {
resolved = baseURI.resolve(reference.getUri());
} catch (IllegalArgumentException e) {
// the given string violates RFC 2396
return null;
}
IFile file = DocumentUtils.getWorkspaceFile(resolved);
if (file != null && file.exists()) {
return new IHyperlink[] { createFileHyperlink(info.region, info.text, file, reference.getPointer()) };
}
}
return null;
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class OutlineStyledLabelProvider method update.
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
if (element instanceof AbstractNode) {
StyledString styledString = getStyledString((AbstractNode) element);
cell.setText(styledString.toString());
cell.setStyleRanges(styledString.getStyleRanges());
cell.setImage(getImage(getIcon((AbstractNode) element)));
}
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonEditor method show.
@Override
public boolean show(ShowInContext context) {
ISelection selection = context.getSelection();
if (selection instanceof IStructuredSelection) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
if (selected instanceof AbstractNode) {
Position position = ((AbstractNode) selected).getPosition(getSourceViewer().getDocument());
selectAndReveal(position.getOffset(), position.getLength());
return true;
}
}
return false;
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class ComponentContextType method isReferenceToComponent.
protected boolean isReferenceToComponent(Model model, JsonPointer pointer) {
AbstractNode parentNode = model.find(pointer.head());
if (parentNode == null) {
return false;
}
TypeDefinition parentType = parentNode.getType();
if (parentType instanceof ComplexTypeDefinition) {
Collection<TypeDefinition> types = ((ComplexTypeDefinition) parentType).getComplexTypes();
for (TypeDefinition type : types) {
if (hasRefToComponent(type.getContent())) {
return true;
}
}
}
return hasRefToComponent(parentType.getContent());
}
use of com.reprezen.swagedit.core.model.AbstractNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class Mocks method mockJsonReferenceFactory.
public static OpenApi3ReferenceFactory mockJsonReferenceFactory(final Map<URI, JsonNode> entries) {
final IFile file = mock(IFile.class);
when(file.exists()).thenReturn(true);
return new OpenApi3ReferenceValidator.OpenApi3ReferenceFactory() {
public JsonReference create(AbstractNode node) {
JsonReference ref = super.create(node);
ref.setDocumentManager(new JsonDocumentManager() {
@Override
public IFile getFile(URI uri) {
return file;
}
@Override
public JsonNode getDocument(URI uri) {
return entries.get(uri);
}
});
return ref;
}
};
}
Aggregations