-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate files and remove xtend nature from n4js.json
- Loading branch information
mmews
committed
Dec 14, 2023
1 parent
aa47980
commit c096d65
Showing
10 changed files
with
205 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
source.. = src/,\ | ||
src-gen/,\ | ||
xtend-gen/ | ||
src-gen/ | ||
bin.includes = .,\ | ||
META-INF/,\ | ||
plugin.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
plugins/org.eclipse.n4js.json/src/org/eclipse/n4js/json/formatting2/JSONFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/** | ||
* Copyright (c) 2017 NumberFour AG. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* NumberFour AG - Initial API and implementation | ||
*/ | ||
package org.eclipse.n4js.json.formatting2; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.n4js.json.JSON.JSONArray; | ||
import org.eclipse.n4js.json.JSON.JSONDocument; | ||
import org.eclipse.n4js.json.JSON.JSONObject; | ||
import org.eclipse.n4js.json.JSON.JSONValue; | ||
import org.eclipse.n4js.json.JSON.NameValuePair; | ||
import org.eclipse.xtext.formatting2.AbstractFormatter2; | ||
import org.eclipse.xtext.formatting2.IFormattableDocument; | ||
import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion; | ||
import org.eclipse.xtext.xbase.lib.Pair; | ||
|
||
/** | ||
* A simple formatter for JSON files. | ||
* | ||
* Generally, puts name-value-pairs of objects and array elements on a separate line. | ||
*/ | ||
public class JSONFormatter extends AbstractFormatter2 { | ||
|
||
@Override | ||
public void format(Object obj, IFormattableDocument document) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
/** */ | ||
public void format(JSONDocument jSONDocument, IFormattableDocument document) { | ||
// make sure all document elements are formatted | ||
document.format(jSONDocument.getContent()); | ||
for (ISemanticRegion sr : textRegionExtensions.allSemanticRegions(jSONDocument)) { | ||
document.append(sr, f -> f.indent()); | ||
} | ||
} | ||
|
||
/** Put both brackets and every element of a JSONArray on a separate line. */ | ||
public void format(JSONArray al, IFormattableDocument document) { | ||
// avoid comma-only lines | ||
configureCommas(al, document); | ||
|
||
Pair<ISemanticRegion, ISemanticRegion> bracketPair = textRegionExtensions.regionFor(al).keywordPairs("[", "]") | ||
.get(0); | ||
|
||
// if bracePair can be determined | ||
if (bracketPair != null) { | ||
// indent array elements | ||
document.interior(bracketPair, f -> f.indent()); | ||
|
||
// format empty arrays to be a bracket pair without space (nor newline) in between | ||
if (al.getElements().isEmpty()) { | ||
document.append(bracketPair.getKey(), f -> f.noSpace()); | ||
document.prepend(bracketPair.getValue(), f -> f.noSpace()); | ||
return; | ||
} | ||
|
||
// put closing bracket on a separate line | ||
document.prepend(bracketPair.getValue(), f -> f.newLine()); | ||
} | ||
|
||
// put every array element on a separate line | ||
for (JSONValue val : al.getElements()) { | ||
document.prepend(val, f -> f.newLine()); | ||
} | ||
// recursively format each element | ||
for (JSONValue val : al.getElements()) { | ||
document.format(val); | ||
} | ||
} | ||
|
||
/** On the direct level of an semantic Object enforce commas to ", " with autoWrap option. */ | ||
private void configureCommas(EObject semEObject, IFormattableDocument document) { | ||
for (ISemanticRegion sr : textRegionExtensions.regionFor(semEObject).keywords(",")) { | ||
document.prepend(sr, f -> f.noSpace()); | ||
document.append(sr, f -> { | ||
f.oneSpace(); | ||
f.autowrap(); | ||
}); | ||
} | ||
} | ||
|
||
/** Put both curly braces and every name-value-pair of a JSONObject on a separate line. */ | ||
public void format(JSONObject ol, IFormattableDocument document) { | ||
configureCommas(ol, document); | ||
|
||
Pair<ISemanticRegion, ISemanticRegion> bracePair = textRegionExtensions.regionFor(ol).keywordPairs("{", "}") | ||
.get(0); | ||
|
||
// if bracePair can be determined | ||
if (bracePair != null) { | ||
document.interior(bracePair, f -> f.indent()); | ||
|
||
// format empty objects to be a brace pair without space (nor newline) in between | ||
if (ol.getNameValuePairs().isEmpty()) { | ||
document.append(bracePair.getKey(), f -> f.noSpace()); | ||
document.prepend(bracePair.getValue(), f -> f.noSpace()); | ||
return; | ||
} | ||
|
||
document.prepend(bracePair.getValue(), f -> f.newLine()); // format WS in front of closing brace | ||
for (NameValuePair nvp : ol.getNameValuePairs()) { | ||
document.prepend(nvp, f -> f.newLine()); | ||
} | ||
|
||
if (bracePair.getKey() != null | ||
&& bracePair.getKey().getNextSemanticRegion() == bracePair.getValue()) { | ||
// empty multiline, trigger formatting: | ||
document.append(bracePair.getKey(), f -> f.newLine()); | ||
} | ||
} | ||
|
||
// recursively format each name-value pair | ||
for (NameValuePair nvp : ol.getNameValuePairs()) { | ||
document.format(nvp); | ||
} | ||
} | ||
|
||
/***/ | ||
public void format(NameValuePair nameValuePair, IFormattableDocument document) { | ||
ISemanticRegion colon = textRegionExtensions.regionFor(nameValuePair).keyword(":"); | ||
JSONValue value = nameValuePair.getValue(); | ||
|
||
document.prepend(colon, f -> f.noSpace()); | ||
document.append(colon, f -> f.oneSpace()); | ||
|
||
document.format(value); | ||
} | ||
} |
114 changes: 0 additions & 114 deletions
114
plugins/org.eclipse.n4js.json/src/org/eclipse/n4js/json/formatting2/JSONFormatter.xtend
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
....eclipse.n4js.json/src/org/eclipse/n4js/json/resource/JSONResourceDescriptionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.eclipse.n4js.json.resource; | ||
|
||
import java.util.Collection; | ||
|
||
import org.eclipse.n4js.json.extension.IJSONResourceDescriptionExtension; | ||
import org.eclipse.n4js.json.extension.JSONExtensionRegistry; | ||
import org.eclipse.xtext.resource.IResourceDescription; | ||
import org.eclipse.xtext.resource.IResourceDescription.Delta; | ||
import org.eclipse.xtext.resource.IResourceDescriptions; | ||
import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager; | ||
|
||
import com.google.inject.Inject; | ||
|
||
/** | ||
* Resource description manager for JSON files. Delegates to registered JSON extensions. | ||
*/ | ||
public class JSONResourceDescriptionManager extends DefaultResourceDescriptionManager { | ||
|
||
@Inject | ||
private JSONExtensionRegistry extensionRegistry; | ||
|
||
/** | ||
* Delegates to registered resource description extensions. | ||
*/ | ||
@Override | ||
public boolean isAffected(Collection<Delta> deltas, IResourceDescription candidate, IResourceDescriptions context) { | ||
for (IJSONResourceDescriptionExtension ext : extensionRegistry.getResourceDescriptionExtensions()) { | ||
if (ext.isAffected(deltas, candidate, context)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
...eclipse.n4js.json/src/org/eclipse/n4js/json/resource/JSONResourceDescriptionManager.xtend
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
...eclipse.n4js.json/src/org/eclipse/n4js/json/resource/JSONResourceDescriptionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.eclipse.n4js.json.resource; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.n4js.json.JSON.JSONDocument; | ||
import org.eclipse.n4js.json.extension.IJSONResourceDescriptionExtension; | ||
import org.eclipse.n4js.json.extension.JSONExtensionRegistry; | ||
import org.eclipse.xtext.resource.IEObjectDescription; | ||
import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy; | ||
import org.eclipse.xtext.util.IAcceptor; | ||
|
||
import com.google.inject.Inject; | ||
|
||
/** | ||
* JSON resource description strategy based on {@link IJSONResourceDescriptionExtension}. | ||
* | ||
* Does nothing per default, except for the case in which an extension provides a custom resource description. | ||
*/ | ||
public class JSONResourceDescriptionStrategy extends DefaultResourceDescriptionStrategy { | ||
|
||
@Inject | ||
private JSONExtensionRegistry extensionRegistry; | ||
|
||
/** Delegates to registered resource description extensions. */ | ||
@Override | ||
public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) { | ||
if (eObject instanceof JSONDocument) { | ||
for (IJSONResourceDescriptionExtension ext : extensionRegistry.getResourceDescriptionExtensions()) { | ||
ext.createJSONDocumentDescriptions((JSONDocument) eObject, acceptor); | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.