|
Lines 22-27
Link Here
|
| 22 |
|
22 |
|
| 23 |
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil; |
23 |
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil; |
| 24 |
|
24 |
|
|
|
25 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
| 25 |
|
26 |
|
| 26 |
/** |
27 |
/** |
| 27 |
* Uses the {@link org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner} to |
28 |
* Uses the {@link org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner} to |
|
Lines 771-777
Link Here
|
| 771 |
case Symbols.TokenLBRACE: // for opening-brace-on-new-line style |
772 |
case Symbols.TokenLBRACE: // for opening-brace-on-new-line style |
| 772 |
if (bracelessBlockStart && !fPrefs.prefIndentBracesForBlocks) |
773 |
if (bracelessBlockStart && !fPrefs.prefIndentBracesForBlocks) |
| 773 |
unindent= true; |
774 |
unindent= true; |
| 774 |
else if ((prevToken == Symbols.TokenCOLON || prevToken == Symbols.TokenEQUAL || prevToken == Symbols.TokenRBRACKET) && !fPrefs.prefIndentBracesForArrays) |
775 |
//Bracket Indentation Fix |
|
|
776 |
else if ((prevToken == Symbols.TokenCOLON || prevToken == Symbols.TokenEQUAL) && !fPrefs.prefIndentBracesForArrays) |
| 775 |
unindent= true; |
777 |
unindent= true; |
| 776 |
else if (!bracelessBlockStart && fPrefs.prefIndentBracesForMethods) |
778 |
else if (!bracelessBlockStart && fPrefs.prefIndentBracesForMethods) |
| 777 |
indent= true; |
779 |
indent= true; |
|
Lines 787-792
Link Here
|
| 787 |
case Symbols.TokenTHROWS: |
789 |
case Symbols.TokenTHROWS: |
| 788 |
throwsClause= true; |
790 |
throwsClause= true; |
| 789 |
break; |
791 |
break; |
|
|
792 |
case Symbols.TokenPLUS: |
| 793 |
int position= handleStringContinuation(offset); |
| 794 |
if (position != JavaHeuristicScanner.NOT_FOUND) { |
| 795 |
fAlign= JavaHeuristicScanner.NOT_FOUND; |
| 796 |
fIndent= fPrefs.prefContinuationIndent; |
| 797 |
return position; |
| 798 |
} |
| 799 |
break; |
| 790 |
} |
800 |
} |
| 791 |
} catch (BadLocationException e) { |
801 |
} catch (BadLocationException e) { |
| 792 |
} |
802 |
} |
|
Lines 804-809
Link Here
|
| 804 |
} |
814 |
} |
| 805 |
|
815 |
|
| 806 |
/** |
816 |
/** |
|
|
817 |
* Specifically handles the case of extra indentation for second line of string continuation. |
| 818 |
* |
| 819 |
* @param offset the offset for which the reference is computed |
| 820 |
* @return the reference statement relative to which <code>offset</code> should be indented, or |
| 821 |
* {@link JavaHeuristicScanner#NOT_FOUND} |
| 822 |
* @since 3.7 |
| 823 |
*/ |
| 824 |
private int handleStringContinuation(int offset) { |
| 825 |
int prevNonWSCharPosition= fScanner.findNonWhitespaceBackwardInAnyPartition(offset - 1, JavaHeuristicScanner.UNBOUND); |
| 826 |
if (prevNonWSCharPosition != JavaHeuristicScanner.NOT_FOUND) { |
| 827 |
try { |
| 828 |
char c= fDocument.getChar(prevNonWSCharPosition); |
| 829 |
if (c == '"' || c == '+') { |
| 830 |
int initialLine= fDocument.getLineOfOffset(offset); |
| 831 |
nextToken(offset); |
| 832 |
while (fToken == Symbols.TokenPLUS) { |
| 833 |
if ((initialLine - fLine) > 1) |
| 834 |
return JavaHeuristicScanner.NOT_FOUND; |
| 835 |
nextToken(); |
| 836 |
} |
| 837 |
int lineDiff= initialLine - fLine; |
| 838 |
if (lineDiff > 0) { |
| 839 |
int bound= fDocument.getLineOffset(fLine) + fDocument.getLineLength(fLine) - 1; |
| 840 |
int nextNonWSCharPosition= fScanner.findNonWhitespaceForwardInAnyPartition(fPosition + 1, bound); |
| 841 |
if (lineDiff < 3 && fPreviousPos != offset && nextNonWSCharPosition != JavaHeuristicScanner.NOT_FOUND && fDocument.getChar(nextNonWSCharPosition) != '"') |
| 842 |
return fPreviousPos; |
| 843 |
else |
| 844 |
return fPosition; |
| 845 |
} |
| 846 |
} |
| 847 |
} catch (BadLocationException e) { |
| 848 |
JavaPlugin.log(e); |
| 849 |
} |
| 850 |
} |
| 851 |
return JavaHeuristicScanner.NOT_FOUND; |
| 852 |
} |
| 853 |
|
| 854 |
/** |
| 807 |
* Returns the reference position regarding to indentation for <code>position</code>, or |
855 |
* Returns the reference position regarding to indentation for <code>position</code>, or |
| 808 |
* <code>NOT_FOUND</code>.<code>fIndent</code> will contain the relative indentation (in |
856 |
* <code>NOT_FOUND</code>.<code>fIndent</code> will contain the relative indentation (in |
| 809 |
* indentation units, not characters) after the call. If there is a special alignment (e.g. for |
857 |
* indentation units, not characters) after the call. If there is a special alignment (e.g. for |
|
Lines 961-966
Link Here
|
| 961 |
|
1009 |
|
| 962 |
case Symbols.TokenTRY: |
1010 |
case Symbols.TokenTRY: |
| 963 |
return skipToStatementStart(danglingElse, false); |
1011 |
return skipToStatementStart(danglingElse, false); |
|
|
1012 |
//Bracket Indentation Fix |
| 1013 |
case Symbols.TokenRBRACKET: |
| 1014 |
fIndent= fPrefs.prefContinuationIndent; |
| 1015 |
return fPosition; |
| 1016 |
|
| 964 |
case Symbols.TokenRPAREN: |
1017 |
case Symbols.TokenRPAREN: |
| 965 |
if (throwsClause) { |
1018 |
if (throwsClause) { |
| 966 |
fIndent= fPrefs.prefContinuationIndent; |
1019 |
fIndent= fPrefs.prefContinuationIndent; |