Search in sources :

Example 1 with AbstractNode

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;
}
Also used : JsonReference(com.reprezen.swagedit.core.json.references.JsonReference) IFile(org.eclipse.core.resources.IFile) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) URI(java.net.URI) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with AbstractNode

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)));
    }
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) StyledString(org.eclipse.jface.viewers.StyledString)

Example 3 with AbstractNode

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;
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) Position(org.eclipse.jface.text.Position) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with AbstractNode

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());
}
Also used : AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) ComplexTypeDefinition(com.reprezen.swagedit.core.schema.ComplexTypeDefinition) MultipleTypeDefinition(com.reprezen.swagedit.core.schema.MultipleTypeDefinition) ComplexTypeDefinition(com.reprezen.swagedit.core.schema.ComplexTypeDefinition) TypeDefinition(com.reprezen.swagedit.core.schema.TypeDefinition)

Example 5 with AbstractNode

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;
        }
    };
}
Also used : JsonReference(com.reprezen.swagedit.core.json.references.JsonReference) IFile(org.eclipse.core.resources.IFile) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) OpenApi3ReferenceFactory(com.reprezen.swagedit.openapi3.validation.OpenApi3ReferenceValidator.OpenApi3ReferenceFactory) JsonDocumentManager(com.reprezen.swagedit.core.json.references.JsonDocumentManager) URI(java.net.URI)

Aggregations

AbstractNode (com.reprezen.swagedit.core.model.AbstractNode)29 Model (com.reprezen.swagedit.core.model.Model)6 JsonPointer (com.fasterxml.jackson.core.JsonPointer)5 JsonReference (com.reprezen.swagedit.core.json.references.JsonReference)5 URI (java.net.URI)5 IFile (org.eclipse.core.resources.IFile)5 IRegion (org.eclipse.jface.text.IRegion)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)4 Proposal (com.reprezen.swagedit.core.assist.Proposal)3 JsonDocumentManager (com.reprezen.swagedit.core.json.references.JsonDocumentManager)3 TypeDefinition (com.reprezen.swagedit.core.schema.TypeDefinition)3 Matcher (java.util.regex.Matcher)3 SwaggerHyperlink (com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink)2 JsonReferenceFactory (com.reprezen.swagedit.core.json.references.JsonReferenceFactory)2 ArrayNode (com.reprezen.swagedit.core.model.ArrayNode)2 ComplexTypeDefinition (com.reprezen.swagedit.core.schema.ComplexTypeDefinition)2 MultipleTypeDefinition (com.reprezen.swagedit.core.schema.MultipleTypeDefinition)2 Position (org.eclipse.jface.text.Position)2 JsonDocument (com.reprezen.swagedit.core.editor.JsonDocument)1