Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 252035 Details for
Bug 400670
[Save actions] Correct indentation conflicts with formatter causing staircase effect
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix + tests
eclipse.jdt.ui.patch (text/plain), 14.39 KB, created by
Noopur Gupta
on 2015-03-31 07:16:27 EDT
(
hide
)
Description:
Fix + tests
Filename:
MIME Type:
Creator:
Noopur Gupta
Created:
2015-03-31 07:16:27 EDT
Size:
14.39 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/IndentActionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/IndentActionTest.java >index ff90b17..1e662c8 100644 >--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/IndentActionTest.java >+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/IndentActionTest.java >@@ -207,4 +207,35 @@ > selectAll(); > assertIndentResult(); > } >+ >+ public void testBug400670() throws Exception { >+ String indentOnColumn= DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_NEXT_PER_LINE, DefaultCodeFormatterConstants.INDENT_ON_COLUMN); >+ IJavaProject project= IndentTestSetup.getProject(); >+ String value1= project.getOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS, true); >+ project.setOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS, indentOnColumn); >+ String value2= project.getOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, true); >+ project.setOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, indentOnColumn); >+ String value3= project.getOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_ARRAY_INITIALIZER, true); >+ project.setOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_ARRAY_INITIALIZER, indentOnColumn); >+ try { >+ selectAll(); >+ assertIndentResult(); >+ } finally { >+ project.setOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS, value1); >+ project.setOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, value2); >+ project.setOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_EXPRESSIONS_IN_ARRAY_INITIALIZER, value3); >+ } >+ } >+ >+ public void testBug458763() throws Exception { >+ IJavaProject project= IndentTestSetup.getProject(); >+ String value= project.getOption(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH, true); >+ project.setOption(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH, DefaultCodeFormatterConstants.FALSE); >+ try { >+ selectAll(); >+ assertIndentResult(); >+ } finally { >+ project.setOption(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER, value); >+ } >+ } > } >diff --git a/org.eclipse.jdt.text.tests/testResources/indentation/bug400670/Before.java b/org.eclipse.jdt.text.tests/testResources/indentation/bug400670/Before.java >new file mode 100644 >index 0000000..4772c0c >--- /dev/null >+++ b/org.eclipse.jdt.text.tests/testResources/indentation/bug400670/Before.java >@@ -0,0 +1,51 @@ >+package p; >+ >+public enum TestEnum { >+ FIRST_ENUM("first type", >+ new SomeClass(), >+ new OtherEnumType[] { OtherEnumType.FOO }), >+ SECOND_ENUM("second type", >+ new SomeClassOtherClass(), >+ new OtherEnumType[] { OtherEnumType.BAR }), >+ THIRD_ENUM("third type", >+ new SomeThirdClass(), >+ new OtherEnumType[] { OtherEnumType.BAZ }), >+ FOURTH_ENUM("fourth type", >+ new YetAnotherClass(), >+ new OtherEnumType[] { OtherEnumType.FOOBAR, >+ OtherEnumType.FOO, >+ OtherEnumType.FOOBARBAZ, >+ OtherEnumType.LONGERFOOBARBAZ, >+ OtherEnumType.REALLYLONGFOOBARBAZ, >+ OtherEnumType.MORELETTERSINHERE }); >+ >+ /* data members and methods go here */ >+ TestEnum(String s, Cls s1, OtherEnumType[] e) { >+ } >+} >+ >+enum OtherEnumType { >+ FOOBAR, >+ FOOBARBAZ, >+ FOO, >+ LONGERFOOBARBAZ, >+ REALLYLONGFOOBARBAZ, >+ MORELETTERSINHERE, >+ BAR, >+ BAZ >+} >+ >+class Cls { >+} >+ >+class SomeClass extends Cls { >+} >+ >+class SomeThirdClass extends Cls { >+} >+ >+class SomeClassOtherClass extends Cls { >+} >+ >+class YetAnotherClass extends Cls { >+} >\ No newline at end of file >diff --git a/org.eclipse.jdt.text.tests/testResources/indentation/bug400670/Modified.java b/org.eclipse.jdt.text.tests/testResources/indentation/bug400670/Modified.java >new file mode 100644 >index 0000000..4772c0c >--- /dev/null >+++ b/org.eclipse.jdt.text.tests/testResources/indentation/bug400670/Modified.java >@@ -0,0 +1,51 @@ >+package p; >+ >+public enum TestEnum { >+ FIRST_ENUM("first type", >+ new SomeClass(), >+ new OtherEnumType[] { OtherEnumType.FOO }), >+ SECOND_ENUM("second type", >+ new SomeClassOtherClass(), >+ new OtherEnumType[] { OtherEnumType.BAR }), >+ THIRD_ENUM("third type", >+ new SomeThirdClass(), >+ new OtherEnumType[] { OtherEnumType.BAZ }), >+ FOURTH_ENUM("fourth type", >+ new YetAnotherClass(), >+ new OtherEnumType[] { OtherEnumType.FOOBAR, >+ OtherEnumType.FOO, >+ OtherEnumType.FOOBARBAZ, >+ OtherEnumType.LONGERFOOBARBAZ, >+ OtherEnumType.REALLYLONGFOOBARBAZ, >+ OtherEnumType.MORELETTERSINHERE }); >+ >+ /* data members and methods go here */ >+ TestEnum(String s, Cls s1, OtherEnumType[] e) { >+ } >+} >+ >+enum OtherEnumType { >+ FOOBAR, >+ FOOBARBAZ, >+ FOO, >+ LONGERFOOBARBAZ, >+ REALLYLONGFOOBARBAZ, >+ MORELETTERSINHERE, >+ BAR, >+ BAZ >+} >+ >+class Cls { >+} >+ >+class SomeClass extends Cls { >+} >+ >+class SomeThirdClass extends Cls { >+} >+ >+class SomeClassOtherClass extends Cls { >+} >+ >+class YetAnotherClass extends Cls { >+} >\ No newline at end of file >diff --git a/org.eclipse.jdt.text.tests/testResources/indentation/bug424772/Modified.java b/org.eclipse.jdt.text.tests/testResources/indentation/bug424772/Modified.java >index 8a94591..dcc47c6 100644 >--- a/org.eclipse.jdt.text.tests/testResources/indentation/bug424772/Modified.java >+++ b/org.eclipse.jdt.text.tests/testResources/indentation/bug424772/Modified.java >@@ -15,7 +15,7 @@ > > String t3(int i, > int j) >- [] [] >+ [] [] > { > return new String[0][0]; > } >diff --git a/org.eclipse.jdt.text.tests/testResources/indentation/bug458763/Before.java b/org.eclipse.jdt.text.tests/testResources/indentation/bug458763/Before.java >new file mode 100644 >index 0000000..15eb6b5 >--- /dev/null >+++ b/org.eclipse.jdt.text.tests/testResources/indentation/bug458763/Before.java >@@ -0,0 +1,17 @@ >+package p; >+ >+public enum Direction {NORTH, SOUTH, EAST, WEST; // note semicolon here >+public Direction opposite() { >+ switch (this) { >+ case NORTH: >+ return SOUTH; >+ case SOUTH: >+ return NORTH; >+ case EAST: >+ return WEST; >+ case WEST: >+ return EAST; >+ default: return null; >+ } >+} >+} >\ No newline at end of file >diff --git a/org.eclipse.jdt.text.tests/testResources/indentation/bug458763/Modified.java b/org.eclipse.jdt.text.tests/testResources/indentation/bug458763/Modified.java >new file mode 100644 >index 0000000..9c99b4d >--- /dev/null >+++ b/org.eclipse.jdt.text.tests/testResources/indentation/bug458763/Modified.java >@@ -0,0 +1,17 @@ >+package p; >+ >+public enum Direction {NORTH, SOUTH, EAST, WEST; // note semicolon here >+ public Direction opposite() { >+ switch (this) { >+ case NORTH: >+ return SOUTH; >+ case SOUTH: >+ return NORTH; >+ case EAST: >+ return WEST; >+ case WEST: >+ return EAST; >+ default: return null; >+ } >+ } >+} >\ No newline at end of file >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java >index 93942c9..6fc1f7f 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java >@@ -71,6 +71,8 @@ > final int prefContinuationIndent; > final boolean prefHasGenerics; > final String prefTabChar; >+ final int prefEnumConstantIndent; >+ final boolean prefEnumConstantDeepIndent; > > private final IJavaProject fProject; > >@@ -128,6 +130,8 @@ > prefIndentBracesForTypes= false; > prefHasGenerics= false; > prefTabChar= JavaCore.TAB; >+ prefEnumConstantDeepIndent= false; >+ prefEnumConstantIndent= 1; > } else { > prefUseTabs= prefUseTabs(); > prefTabSize= prefTabSize(); >@@ -157,6 +161,8 @@ > prefIndentBracesForTypes= prefIndentBracesForTypes(); > prefHasGenerics= hasGenerics(); > prefTabChar= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); >+ prefEnumConstantIndent= prefEnumConstantIndent(); >+ prefEnumConstantDeepIndent= prefEnumConstantDeepIndent(); > } > } > >@@ -362,6 +368,27 @@ > } > private boolean hasGenerics() { > return JavaCore.VERSION_1_5.compareTo(getCoreFormatterOption(JavaCore.COMPILER_SOURCE)) <= 0; >+ } >+ >+ private boolean prefEnumConstantDeepIndent() { >+ String option= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS); >+ try { >+ return DefaultCodeFormatterConstants.getIndentStyle(option) == DefaultCodeFormatterConstants.INDENT_ON_COLUMN; >+ } catch (IllegalArgumentException e) { >+ // ignore and return default >+ } >+ return false; >+ } >+ >+ private int prefEnumConstantIndent() { // see bug 458208 comment 22 >+ String option= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS); >+ try { >+ if (DefaultCodeFormatterConstants.getIndentStyle(option) == DefaultCodeFormatterConstants.INDENT_BY_ONE) >+ return 2; >+ } catch (IllegalArgumentException e) { >+ // ignore and return default >+ } >+ return 1; > } > } > >@@ -1037,10 +1064,14 @@ > if (isTryWithResources()) { > fIndent= fPrefs.prefContinuationIndent; > return fPosition; >- } else { >- fPosition= pos; >- return skipToStatementStart(danglingElse, false); > } >+ fPosition= pos; >+ if (isSemicolonPartOfEnumBodyDeclaration()) { >+ fIndent= getBlockIndent(false, true); >+ return fPosition; >+ } >+ fPosition= pos; >+ return skipToStatementStart(danglingElse, false); > } > // scope introduction: special treat who special is > case Symbols.TokenLPAREN: >@@ -1537,6 +1568,8 @@ > case Symbols.TokenRBRACE: > case Symbols.TokenGREATERTHAN: > skipScope(); >+ startLine= fLine; >+ startPosition= fPosition; > break; > > // scope introduction: special treat who special is >@@ -1686,6 +1719,16 @@ > case Symbols.TokenLBRACE: > pos= fPosition; // store > >+ if (looksLikeEnumDeclaration()) { >+ if (fPrefs.prefEnumConstantDeepIndent) { >+ return setFirstElementAlignment(pos, bound); >+ } else { >+ fIndent= fPrefs.prefEnumConstantIndent; >+ return pos; >+ } >+ } >+ fPosition= pos; // restore >+ > // special: array initializer > if (looksLikeArrayInitializerIntro()) > if (fPrefs.prefArrayDeepIndent) >@@ -1757,13 +1800,84 @@ > } > > /** >- * Skips over the next <code>if</code> keyword. The current token when calling >- * this method must be an <code>else</code> keyword. Returns <code>true</code> >- * if a matching <code>if</code> could be found, <code>false</code> otherwise. >- * The cursor (<code>fPosition</code>) is set to the offset of the <code>if</code> >- * token. >+ * Returns <code>true</code> if the current position looks like a part of enum declaration >+ * header. It calls {@link #nextToken} to scan backwards. > * >- * @return <code>true</code> if a matching <code>if</code> token was found, <code>false</code> otherwise >+ * @return <code>true</code> if the current position looks like a part of enum declaration >+ * header >+ * @since 3.11 >+ */ >+ private boolean looksLikeEnumDeclaration() { >+ while (true) { >+ nextToken(); >+ switch (fToken) { >+ case Symbols.TokenENUM: >+ return true; >+ case Symbols.TokenIDENT: >+ case Symbols.TokenCOMMA: >+ case Symbols.TokenAT: >+ break; >+ case Symbols.TokenOTHER: >+ try { >+ if (fDocument.getChar(fPosition) != '.') { >+ return false; >+ } >+ } catch (BadLocationException e) { >+ return false; >+ } >+ break; >+ case Symbols.TokenRPAREN: >+ case Symbols.TokenRBRACKET: >+ case Symbols.TokenRBRACE: >+ case Symbols.TokenGREATERTHAN: >+ skipScope(); >+ break; >+ case Symbols.TokenEOF: >+ return false; >+ default: >+ return false; >+ } >+ } >+ } >+ >+ /** >+ * Checks if the semicolon at the current position is part of enum body declaration. >+ * >+ * @return returns <code>true</code> if the semicolon at the current position is part of enum >+ * body declaration >+ * @since 3.11 >+ */ >+ private boolean isSemicolonPartOfEnumBodyDeclaration() { >+ while (true) { >+ nextToken(); >+ switch (fToken) { >+ case Symbols.TokenLBRACE: >+ return looksLikeEnumDeclaration(); >+ case Symbols.TokenIDENT: >+ case Symbols.TokenCOMMA: >+ break; >+ case Symbols.TokenRPAREN: >+ case Symbols.TokenRBRACKET: >+ case Symbols.TokenRBRACE: >+ case Symbols.TokenGREATERTHAN: >+ skipScope(); >+ break; >+ case Symbols.TokenEOF: >+ return false; >+ default: >+ return false; >+ } >+ } >+ } >+ >+ /** >+ * Skips over the next <code>if</code> keyword. The current token when calling this method must >+ * be an <code>else</code> keyword. Returns <code>true</code> if a matching <code>if</code> >+ * could be found, <code>false</code> otherwise. The cursor (<code>fPosition</code>) is set to >+ * the offset of the <code>if</code> token. >+ * >+ * @return <code>true</code> if a matching <code>if</code> token was found, <code>false</code> >+ * otherwise > */ > private boolean skipNextIF() { > Assert.isTrue(fToken == Symbols.TokenELSE);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 400670
:
226996
|
251894
|
251896
|
252004
|
252035
|
252631