You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/06/14 09:14:16 UTC
[GitHub] sdedic closed pull request #568: [NetBeans-778] Formatting issue
with var declaration statement
sdedic closed pull request #568: [NetBeans-778] Formatting issue with var declaration statement
URL: https://github.com/apache/incubator-netbeans/pull/568
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java b/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java
index 20af39302..5b359c523 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java
@@ -1196,9 +1196,15 @@ public Boolean visitVariable(VariableTree node, Void p) {
} else {
if (!insideForTryOrCatch)
continuationIndent = true;
- if (node.getType() == null || scan(node.getType(), p)) {
- if (node.getType() != null) {
+ if (node.getType() == null || tokens.token().id() == JavaTokenId.VAR || scan(node.getType(), p)) {
+ if (node.getType() != null && tokens.token().id() != JavaTokenId.VAR) {
spaces(1, fieldGroup);
+ } else {
+ if (tokens.token().id() == JavaTokenId.VAR) {
+ //Add space after 'var' token
+ addDiff(new Diff(tokens.offset() + 3, tokens.offset() + 3, " "));
+ tokens.moveNext();
+ }
}
if (!ERROR.contentEquals(node.getName()))
accept(IDENTIFIER, UNDERSCORE);
diff --git a/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java b/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java
index 59e8969eb..cda1c9f66 100644
--- a/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java
+++ b/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java
@@ -4457,6 +4457,64 @@ public void testForNoCondition() throws Exception {
reformat(doc, content, golden);
}
+ public void testForVar1() throws Exception {
+ testFile = new File(getWorkDir(), "Test.java");
+ TestUtilities.copyStringToFile(testFile, "");
+ FileObject testSourceFO = FileUtil.toFileObject(testFile);
+ DataObject testSourceDO = DataObject.find(testSourceFO);
+ EditorCookie ec = (EditorCookie) testSourceDO.getCookie(EditorCookie.class);
+ String oldLevel = JavaSourceTest.SourceLevelQueryImpl.sourceLevel;
+ JavaSourceTest.SourceLevelQueryImpl.sourceLevel = "1.10";
+ final Document doc = ec.openDocument();
+ doc.putProperty(Language.class, JavaTokenId.language());
+ String content
+ = "package hierbas.del.litoral;\n\n"
+ + "public class Test {\n\n"
+ + " public static void main(String[] args) {\n"
+ + " var v = 10; \n"
+ + " }\n"
+ + "}\n";
+
+ String golden
+ = "package hierbas.del.litoral;\n\n"
+ + "public class Test {\n\n"
+ + " public static void main(String[] args) {\n"
+ + " var v = 10;\n"
+ + " }\n"
+ + "}\n";
+ reformat(doc, content, golden);
+ JavaSourceTest.SourceLevelQueryImpl.sourceLevel = oldLevel;
+ }
+
+ public void testForVar2() throws Exception {
+ testFile = new File(getWorkDir(), "Test.java");
+ TestUtilities.copyStringToFile(testFile, "");
+ FileObject testSourceFO = FileUtil.toFileObject(testFile);
+ DataObject testSourceDO = DataObject.find(testSourceFO);
+ EditorCookie ec = (EditorCookie) testSourceDO.getCookie(EditorCookie.class);
+ String oldLevel = JavaSourceTest.SourceLevelQueryImpl.sourceLevel;
+ JavaSourceTest.SourceLevelQueryImpl.sourceLevel = "1.10";
+ final Document doc = ec.openDocument();
+ doc.putProperty(Language.class, JavaTokenId.language());
+ String content
+ = "package hierbas.del.litoral;\n\n"
+ + "public class Test {\n\n"
+ + " public static void main(String[] args) {\n"
+ + " final var v = 10; \n"
+ + " }\n"
+ + "}\n";
+
+ String golden
+ = "package hierbas.del.litoral;\n\n"
+ + "public class Test {\n\n"
+ + " public static void main(String[] args) {\n"
+ + " final var v = 10;\n"
+ + " }\n"
+ + "}\n";
+ reformat(doc, content, golden);
+ JavaSourceTest.SourceLevelQueryImpl.sourceLevel = oldLevel;
+ }
+
private void reformat(Document doc, String content, String golden) throws Exception {
reformat(doc, content, golden, 0, content.length());
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists