|
Lines 71-76
Link Here
|
| 71 |
final int prefContinuationIndent; |
71 |
final int prefContinuationIndent; |
| 72 |
final boolean prefHasGenerics; |
72 |
final boolean prefHasGenerics; |
| 73 |
final String prefTabChar; |
73 |
final String prefTabChar; |
|
|
74 |
final int prefEnumConstantIndent; |
| 75 |
final boolean prefEnumConstantDeepIndent; |
| 74 |
|
76 |
|
| 75 |
private final IJavaProject fProject; |
77 |
private final IJavaProject fProject; |
| 76 |
|
78 |
|
|
Lines 128-133
Link Here
|
| 128 |
prefIndentBracesForTypes= false; |
130 |
prefIndentBracesForTypes= false; |
| 129 |
prefHasGenerics= false; |
131 |
prefHasGenerics= false; |
| 130 |
prefTabChar= JavaCore.TAB; |
132 |
prefTabChar= JavaCore.TAB; |
|
|
133 |
prefEnumConstantDeepIndent= false; |
| 134 |
prefEnumConstantIndent= 1; |
| 131 |
} else { |
135 |
} else { |
| 132 |
prefUseTabs= prefUseTabs(); |
136 |
prefUseTabs= prefUseTabs(); |
| 133 |
prefTabSize= prefTabSize(); |
137 |
prefTabSize= prefTabSize(); |
|
Lines 157-162
Link Here
|
| 157 |
prefIndentBracesForTypes= prefIndentBracesForTypes(); |
161 |
prefIndentBracesForTypes= prefIndentBracesForTypes(); |
| 158 |
prefHasGenerics= hasGenerics(); |
162 |
prefHasGenerics= hasGenerics(); |
| 159 |
prefTabChar= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); |
163 |
prefTabChar= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); |
|
|
164 |
prefEnumConstantIndent= prefEnumConstantIndent(); |
| 165 |
prefEnumConstantDeepIndent= prefEnumConstantDeepIndent(); |
| 160 |
} |
166 |
} |
| 161 |
} |
167 |
} |
| 162 |
|
168 |
|
|
Lines 362-367
Link Here
|
| 362 |
} |
368 |
} |
| 363 |
private boolean hasGenerics() { |
369 |
private boolean hasGenerics() { |
| 364 |
return JavaCore.VERSION_1_5.compareTo(getCoreFormatterOption(JavaCore.COMPILER_SOURCE)) <= 0; |
370 |
return JavaCore.VERSION_1_5.compareTo(getCoreFormatterOption(JavaCore.COMPILER_SOURCE)) <= 0; |
|
|
371 |
} |
| 372 |
|
| 373 |
private boolean prefEnumConstantDeepIndent() { |
| 374 |
String option= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS); |
| 375 |
try { |
| 376 |
return DefaultCodeFormatterConstants.getIndentStyle(option) == DefaultCodeFormatterConstants.INDENT_ON_COLUMN; |
| 377 |
} catch (IllegalArgumentException e) { |
| 378 |
// ignore and return default |
| 379 |
} |
| 380 |
return false; |
| 381 |
} |
| 382 |
|
| 383 |
private int prefEnumConstantIndent() { // see bug 458208 comment 22 |
| 384 |
String option= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS); |
| 385 |
try { |
| 386 |
if (DefaultCodeFormatterConstants.getIndentStyle(option) == DefaultCodeFormatterConstants.INDENT_BY_ONE) |
| 387 |
return 2; |
| 388 |
} catch (IllegalArgumentException e) { |
| 389 |
// ignore and return default |
| 390 |
} |
| 391 |
return 1; |
| 365 |
} |
392 |
} |
| 366 |
} |
393 |
} |
| 367 |
|
394 |
|
|
Lines 1037-1046
Link Here
|
| 1037 |
if (isTryWithResources()) { |
1064 |
if (isTryWithResources()) { |
| 1038 |
fIndent= fPrefs.prefContinuationIndent; |
1065 |
fIndent= fPrefs.prefContinuationIndent; |
| 1039 |
return fPosition; |
1066 |
return fPosition; |
| 1040 |
} else { |
|
|
| 1041 |
fPosition= pos; |
| 1042 |
return skipToStatementStart(danglingElse, false); |
| 1043 |
} |
1067 |
} |
|
|
1068 |
fPosition= pos; |
| 1069 |
if (isSemicolonPartOfEnumBodyDeclaration()) { |
| 1070 |
fIndent= getBlockIndent(false, true); |
| 1071 |
return fPosition; |
| 1072 |
} |
| 1073 |
fPosition= pos; |
| 1074 |
return skipToStatementStart(danglingElse, false); |
| 1044 |
} |
1075 |
} |
| 1045 |
// scope introduction: special treat who special is |
1076 |
// scope introduction: special treat who special is |
| 1046 |
case Symbols.TokenLPAREN: |
1077 |
case Symbols.TokenLPAREN: |
|
Lines 1537-1542
Link Here
|
| 1537 |
case Symbols.TokenRBRACE: |
1568 |
case Symbols.TokenRBRACE: |
| 1538 |
case Symbols.TokenGREATERTHAN: |
1569 |
case Symbols.TokenGREATERTHAN: |
| 1539 |
skipScope(); |
1570 |
skipScope(); |
|
|
1571 |
startLine= fLine; |
| 1572 |
startPosition= fPosition; |
| 1540 |
break; |
1573 |
break; |
| 1541 |
|
1574 |
|
| 1542 |
// scope introduction: special treat who special is |
1575 |
// scope introduction: special treat who special is |
|
Lines 1686-1691
Link Here
|
| 1686 |
case Symbols.TokenLBRACE: |
1719 |
case Symbols.TokenLBRACE: |
| 1687 |
pos= fPosition; // store |
1720 |
pos= fPosition; // store |
| 1688 |
|
1721 |
|
|
|
1722 |
if (looksLikeEnumDeclaration()) { |
| 1723 |
if (fPrefs.prefEnumConstantDeepIndent) { |
| 1724 |
return setFirstElementAlignment(pos, bound); |
| 1725 |
} else { |
| 1726 |
fIndent= fPrefs.prefEnumConstantIndent; |
| 1727 |
return pos; |
| 1728 |
} |
| 1729 |
} |
| 1730 |
fPosition= pos; // restore |
| 1731 |
|
| 1689 |
// special: array initializer |
1732 |
// special: array initializer |
| 1690 |
if (looksLikeArrayInitializerIntro()) |
1733 |
if (looksLikeArrayInitializerIntro()) |
| 1691 |
if (fPrefs.prefArrayDeepIndent) |
1734 |
if (fPrefs.prefArrayDeepIndent) |
|
Lines 1757-1769
Link Here
|
| 1757 |
} |
1800 |
} |
| 1758 |
|
1801 |
|
| 1759 |
/** |
1802 |
/** |
| 1760 |
* Skips over the next <code>if</code> keyword. The current token when calling |
1803 |
* Returns <code>true</code> if the current position looks like a part of enum declaration |
| 1761 |
* this method must be an <code>else</code> keyword. Returns <code>true</code> |
1804 |
* header. It calls {@link #nextToken} to scan backwards. |
| 1762 |
* if a matching <code>if</code> could be found, <code>false</code> otherwise. |
|
|
| 1763 |
* The cursor (<code>fPosition</code>) is set to the offset of the <code>if</code> |
| 1764 |
* token. |
| 1765 |
* |
1805 |
* |
| 1766 |
* @return <code>true</code> if a matching <code>if</code> token was found, <code>false</code> otherwise |
1806 |
* @return <code>true</code> if the current position looks like a part of enum declaration |
|
|
1807 |
* header |
| 1808 |
* @since 3.11 |
| 1809 |
*/ |
| 1810 |
private boolean looksLikeEnumDeclaration() { |
| 1811 |
while (true) { |
| 1812 |
nextToken(); |
| 1813 |
switch (fToken) { |
| 1814 |
case Symbols.TokenENUM: |
| 1815 |
return true; |
| 1816 |
case Symbols.TokenIDENT: |
| 1817 |
case Symbols.TokenCOMMA: |
| 1818 |
case Symbols.TokenAT: |
| 1819 |
break; |
| 1820 |
case Symbols.TokenOTHER: |
| 1821 |
try { |
| 1822 |
if (fDocument.getChar(fPosition) != '.') { |
| 1823 |
return false; |
| 1824 |
} |
| 1825 |
} catch (BadLocationException e) { |
| 1826 |
return false; |
| 1827 |
} |
| 1828 |
break; |
| 1829 |
case Symbols.TokenRPAREN: |
| 1830 |
case Symbols.TokenRBRACKET: |
| 1831 |
case Symbols.TokenRBRACE: |
| 1832 |
case Symbols.TokenGREATERTHAN: |
| 1833 |
skipScope(); |
| 1834 |
break; |
| 1835 |
case Symbols.TokenEOF: |
| 1836 |
return false; |
| 1837 |
default: |
| 1838 |
return false; |
| 1839 |
} |
| 1840 |
} |
| 1841 |
} |
| 1842 |
|
| 1843 |
/** |
| 1844 |
* Checks if the semicolon at the current position is part of enum body declaration. |
| 1845 |
* |
| 1846 |
* @return returns <code>true</code> if the semicolon at the current position is part of enum |
| 1847 |
* body declaration |
| 1848 |
* @since 3.11 |
| 1849 |
*/ |
| 1850 |
private boolean isSemicolonPartOfEnumBodyDeclaration() { |
| 1851 |
while (true) { |
| 1852 |
nextToken(); |
| 1853 |
switch (fToken) { |
| 1854 |
case Symbols.TokenLBRACE: |
| 1855 |
return looksLikeEnumDeclaration(); |
| 1856 |
case Symbols.TokenIDENT: |
| 1857 |
case Symbols.TokenCOMMA: |
| 1858 |
break; |
| 1859 |
case Symbols.TokenRPAREN: |
| 1860 |
case Symbols.TokenRBRACKET: |
| 1861 |
case Symbols.TokenRBRACE: |
| 1862 |
case Symbols.TokenGREATERTHAN: |
| 1863 |
skipScope(); |
| 1864 |
break; |
| 1865 |
case Symbols.TokenEOF: |
| 1866 |
return false; |
| 1867 |
default: |
| 1868 |
return false; |
| 1869 |
} |
| 1870 |
} |
| 1871 |
} |
| 1872 |
|
| 1873 |
/** |
| 1874 |
* Skips over the next <code>if</code> keyword. The current token when calling this method must |
| 1875 |
* be an <code>else</code> keyword. Returns <code>true</code> if a matching <code>if</code> |
| 1876 |
* could be found, <code>false</code> otherwise. The cursor (<code>fPosition</code>) is set to |
| 1877 |
* the offset of the <code>if</code> token. |
| 1878 |
* |
| 1879 |
* @return <code>true</code> if a matching <code>if</code> token was found, <code>false</code> |
| 1880 |
* otherwise |
| 1767 |
*/ |
1881 |
*/ |
| 1768 |
private boolean skipNextIF() { |
1882 |
private boolean skipNextIF() { |
| 1769 |
Assert.isTrue(fToken == Symbols.TokenELSE); |
1883 |
Assert.isTrue(fToken == Symbols.TokenELSE); |