Skip to content

Commit 45c47bb

Browse files
committed
Merge branch 'master' into task/347
2 parents b6c652e + 720a642 commit 45c47bb

25 files changed

+652
-87
lines changed

com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/assist/ext/ResponseCodeContentAssistExt.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public Collection<Proposal> getProposals(TypeDefinition type, AbstractNode node,
6969
String description = current.get("description").asText();
7070
String phase = current.get("phrase").asText();
7171

72-
proposals.add(new Proposal("'" + code + "':", code, description, phase));
72+
String replacement = ("default".equals(code) ? code : "'" + code + "'") + ":";
73+
74+
proposals.add(new Proposal(replacement, code, description, phase));
7375
}
7476

7577
proposals.add(new Proposal("x-", "x-", null, "vendorExtension"));

com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/hyperlinks/JsonReferenceHyperlinkDetector.java

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,86 +10,25 @@
1010
*******************************************************************************/
1111
package com.reprezen.swagedit.core.hyperlinks;
1212

13-
import java.net.URI;
14-
1513
import org.eclipse.core.resources.IFile;
1614
import org.eclipse.jface.text.IRegion;
17-
import org.eclipse.jface.text.ITextViewer;
18-
import org.eclipse.jface.text.hyperlink.IHyperlink;
19-
import org.eclipse.ui.part.FileEditorInput;
2015

2116
import com.fasterxml.jackson.core.JsonPointer;
22-
import com.reprezen.swagedit.core.editor.JsonDocument;
23-
import com.reprezen.swagedit.core.json.references.JsonReference;
24-
import com.reprezen.swagedit.core.json.references.JsonReferenceFactory;
25-
import com.reprezen.swagedit.core.model.AbstractNode;
26-
import com.reprezen.swagedit.core.utils.DocumentUtils;
2717

2818
/**
2919
* Hyperlink detector that detects links from JSON references.
30-
*
3120
*/
32-
public abstract class JsonReferenceHyperlinkDetector extends AbstractJsonHyperlinkDetector {
33-
34-
protected final JsonReferenceFactory factory = new JsonReferenceFactory();
35-
36-
protected abstract JsonFileHyperlink createFileHyperlink(IRegion linkRegion, String label, IFile file, JsonPointer pointer) ;
37-
38-
@Override
39-
protected boolean canDetect(JsonPointer pointer) {
40-
return pointer != null && pointer.toString().endsWith("$ref");
41-
}
21+
public abstract class JsonReferenceHyperlinkDetector extends ReferenceHyperlinkDetector {
4222

4323
@Override
44-
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
45-
URI baseURI = getBaseURI();
46-
47-
AbstractNode node = doc.getModel().find(pointer);
48-
JsonReference reference = getFactory().createSimpleReference(getBaseURI(), node);
49-
if (reference == null) {
50-
reference = getFactory().create(node);
51-
}
52-
53-
if (reference.isInvalid() || reference.isMissing(doc, getBaseURI())) {
54-
return null;
55-
}
56-
57-
if (reference.isLocal()) {
58-
IRegion target = doc.getRegion(reference.getPointer());
59-
if (target == null) {
60-
return null;
61-
}
62-
return new IHyperlink[] { new SwaggerHyperlink(reference.getPointer().toString(), viewer, info.region,
63-
target) };
64-
} else {
65-
URI resolved;
66-
try {
67-
resolved = baseURI.resolve(reference.getUri());
68-
} catch (IllegalArgumentException e) {
69-
// the given string violates RFC 2396
70-
return null;
71-
}
72-
IFile file = DocumentUtils.getWorkspaceFile(resolved);
73-
if (file != null && file.exists()) {
74-
return new IHyperlink[] { createFileHyperlink(info.region, info.text, file, reference.getPointer()) };
75-
}
76-
}
77-
24+
protected JsonFileHyperlink createFileHyperlink(IRegion linkRegion, String label, IFile file, JsonPointer pointer) {
25+
// TODO Auto-generated method stub
7826
return null;
7927
}
8028

81-
protected FileEditorInput getActiveEditor() {
82-
return DocumentUtils.getActiveEditorInput();
83-
}
84-
85-
protected URI getBaseURI() {
86-
FileEditorInput editor = getActiveEditor();
87-
88-
return editor != null ? editor.getURI() : null;
89-
}
90-
91-
protected JsonReferenceFactory getFactory() {
92-
return factory;
29+
@Override
30+
protected boolean canDetect(JsonPointer pointer) {
31+
return pointer != null && pointer.toString().endsWith("$ref");
9332
}
9433

9534
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2016 ModelSolv, Inc. and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* ModelSolv, Inc. - initial API and implementation and/or initial documentation
10+
*******************************************************************************/
11+
package com.reprezen.swagedit.core.hyperlinks;
12+
13+
import java.net.URI;
14+
15+
import org.eclipse.core.resources.IFile;
16+
import org.eclipse.jface.text.IRegion;
17+
import org.eclipse.jface.text.ITextViewer;
18+
import org.eclipse.jface.text.hyperlink.IHyperlink;
19+
import org.eclipse.ui.part.FileEditorInput;
20+
21+
import com.fasterxml.jackson.core.JsonPointer;
22+
import com.reprezen.swagedit.core.editor.JsonDocument;
23+
import com.reprezen.swagedit.core.json.references.JsonReference;
24+
import com.reprezen.swagedit.core.json.references.JsonReferenceFactory;
25+
import com.reprezen.swagedit.core.model.AbstractNode;
26+
import com.reprezen.swagedit.core.utils.DocumentUtils;
27+
28+
public abstract class ReferenceHyperlinkDetector extends AbstractJsonHyperlinkDetector {
29+
30+
protected final JsonReferenceFactory factory = new JsonReferenceFactory();
31+
32+
protected abstract JsonFileHyperlink createFileHyperlink(IRegion linkRegion, String label, IFile file,
33+
JsonPointer pointer);
34+
35+
@Override
36+
protected abstract boolean canDetect(JsonPointer pointer);
37+
38+
@Override
39+
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
40+
URI baseURI = getBaseURI();
41+
42+
AbstractNode node = doc.getModel().find(pointer);
43+
JsonReference reference = getFactory().createSimpleReference(getBaseURI(), node);
44+
if (reference == null) {
45+
reference = getFactory().create(node);
46+
}
47+
48+
if (reference.isInvalid() || reference.isMissing(doc, getBaseURI())) {
49+
return null;
50+
}
51+
52+
if (reference.isLocal()) {
53+
IRegion target = doc.getRegion(reference.getPointer());
54+
if (target == null) {
55+
return null;
56+
}
57+
return new IHyperlink[] {
58+
new SwaggerHyperlink(reference.getPointer().toString(), viewer, info.region, target) };
59+
} else {
60+
URI resolved;
61+
try {
62+
resolved = baseURI.resolve(reference.getUri());
63+
} catch (IllegalArgumentException e) {
64+
// the given string violates RFC 2396
65+
return null;
66+
}
67+
IFile file = DocumentUtils.getWorkspaceFile(resolved);
68+
if (file != null && file.exists()) {
69+
return new IHyperlink[] { createFileHyperlink(info.region, info.text, file, reference.getPointer()) };
70+
}
71+
}
72+
73+
return null;
74+
}
75+
76+
protected FileEditorInput getActiveEditor() {
77+
return DocumentUtils.getActiveEditorInput();
78+
}
79+
80+
protected URI getBaseURI() {
81+
FileEditorInput editor = getActiveEditor();
82+
83+
return editor != null ? editor.getURI() : null;
84+
}
85+
86+
protected JsonReferenceFactory getFactory() {
87+
return factory;
88+
}
89+
90+
}

com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/hyperlinks/SwaggerHyperlink.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public String getHyperlinkText() {
4343
return text;
4444
}
4545

46+
public IRegion getTarget() {
47+
return target;
48+
}
49+
4650
@Override
4751
public void open() {
4852
if (viewer != null) {

com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/json/references/JsonReferenceFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ public JsonReference doCreate(String value, Object source) {
114114
String fragment = uri.getFragment();
115115
JsonPointer pointer = null;
116116
try {
117+
// Pointer fails to resolve if ends with /
118+
if (fragment != null && fragment.length() > 1 && fragment.endsWith("/")) {
119+
fragment = fragment.substring(0, fragment.length() - 1);
120+
}
121+
117122
pointer = JsonPointer.compile(Strings.emptyToNull(fragment));
118123
} catch (IllegalArgumentException e) {
119124
// let the pointer be null

com.reprezen.swagedit.openapi3.tests/src/com/reprezen/swagedit/openapi3/assist/OpenApi3ContentAssistProcessorTest.xtend

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2016 ModelSolv, Inc. and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* ModelSolv, Inc. - initial API and implementation and/or initial documentation
10+
*******************************************************************************/
111
package com.reprezen.swagedit.openapi3.assist
212

313
import com.reprezen.swagedit.core.assist.StyledCompletionProposal
@@ -174,7 +184,7 @@ class OpenApi3ContentAssistProcessorTest {
174184
val proposals = test.apply(processor, "1")
175185
assertThat(
176186
proposals.map[(it as StyledCompletionProposal).replacementString],
177-
hasItems("'100':", "'200':", "'300':", "'400':", "'500':", "'default':", "x-")
187+
hasItems("'100':", "'200':", "'300':", "'400':", "'500':", "default:", "x-")
178188
)
179189
}
180190

0 commit comments

Comments
 (0)