Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 887-899
Link Here
|
887 |
int pos= fPosition; |
887 |
int pos= fPosition; |
888 |
if (!skipScope()) |
888 |
if (!skipScope()) |
889 |
fPosition= pos; |
889 |
fPosition= pos; |
890 |
//$FALL-THROUGH$ |
890 |
return skipToStatementStart(danglingElse, false); |
891 |
case Symbols.TokenSEMICOLON: |
891 |
case Symbols.TokenSEMICOLON: |
892 |
// this is the 90% case: after a statement block |
892 |
// this is the 90% case: after a statement block |
893 |
// the end of the previous statement / block previous.end |
893 |
// the end of the previous statement / block previous.end |
894 |
// search to the end of the statement / block before the previous; the token just after that is previous.start |
894 |
// search to the end of the statement / block before the previous; the token just after that is previous.start |
895 |
return skipToStatementStart(danglingElse, false); |
895 |
pos= fPosition; |
896 |
|
896 |
if (isForStatement()) { |
|
|
897 |
fIndent= fPrefs.prefContinuationIndent; |
898 |
return fPosition; |
899 |
} else { |
900 |
fPosition= pos; |
901 |
return skipToStatementStart(danglingElse, false); |
902 |
} |
897 |
// scope introduction: special treat who special is |
903 |
// scope introduction: special treat who special is |
898 |
case Symbols.TokenLPAREN: |
904 |
case Symbols.TokenLPAREN: |
899 |
case Symbols.TokenLBRACE: |
905 |
case Symbols.TokenLBRACE: |
Lines 906-913
Link Here
|
906 |
|
912 |
|
907 |
case Symbols.TokenEQUAL: |
913 |
case Symbols.TokenEQUAL: |
908 |
// indent assignments |
914 |
// indent assignments |
909 |
fIndent= fPrefs.prefAssignmentIndent; |
915 |
return handleAssignmentAndComparison(); |
910 |
return fPosition; |
|
|
911 |
|
916 |
|
912 |
case Symbols.TokenCOLON: |
917 |
case Symbols.TokenCOLON: |
913 |
// TODO handle ternary deep indentation |
918 |
// TODO handle ternary deep indentation |
Lines 958-963
Link Here
|
958 |
fLine= line; |
963 |
fLine= line; |
959 |
|
964 |
|
960 |
return skipToPreviousListItemOrListStart(); |
965 |
return skipToPreviousListItemOrListStart(); |
|
|
966 |
case Symbols.TokenRETURN: |
967 |
fIndent= fPrefs.prefContinuationIndent; |
968 |
return fPosition; |
961 |
case Symbols.TokenCOMMA: |
969 |
case Symbols.TokenCOMMA: |
962 |
// inside a list of some type |
970 |
// inside a list of some type |
963 |
// easy if there is already a list item before with its own indentation - we just align |
971 |
// easy if there is already a list item before with its own indentation - we just align |
Lines 972-977
Link Here
|
972 |
} |
980 |
} |
973 |
|
981 |
|
974 |
/** |
982 |
/** |
|
|
983 |
* Checks if the statement is a continuation and the token at the current position is an assignment or a comparison and sets the |
984 |
* indentation accordingly. |
985 |
* |
986 |
* @return the position of the token |
987 |
* @since 3.7 |
988 |
*/ |
989 |
private int handleAssignmentAndComparison() { |
990 |
int tokenAtPreviousChar; |
991 |
|
992 |
try { |
993 |
//If this line is itself continuation of the previous then do nothing |
994 |
IRegion line; |
995 |
line= fDocument.getLineInformationOfOffset(fPosition); |
996 |
int nonWS= fScanner.findNonWhitespaceBackward(line.getOffset(), JavaHeuristicScanner.UNBOUND); |
997 |
tokenAtPreviousChar= fScanner.nextToken(nonWS, nonWS + 1); |
998 |
if (tokenAtPreviousChar != Symbols.TokenSEMICOLON && tokenAtPreviousChar != Symbols.TokenRBRACE && tokenAtPreviousChar != Symbols.TokenEOF) |
999 |
return fPosition; |
1000 |
} catch (BadLocationException e) { |
1001 |
return fPosition; |
1002 |
} |
1003 |
|
1004 |
tokenAtPreviousChar= fScanner.nextToken(fPosition - 1, fPosition); |
1005 |
if (tokenAtPreviousChar == Symbols.TokenEQUAL || fToken == Symbols.TokenGREATERTHAN || fToken == Symbols.TokenLESSTHAN) { |
1006 |
fIndent= fPrefs.prefContinuationIndent; |
1007 |
fPosition--; |
1008 |
} else { |
1009 |
fIndent= fPrefs.prefAssignmentIndent; |
1010 |
} |
1011 |
return fPosition; |
1012 |
} |
1013 |
|
1014 |
/** |
1015 |
* Checks if the semicolon at the current position is part of a for statement. |
1016 |
* |
1017 |
* @return returns <code>true</code> if current position is part of for statement |
1018 |
* @since 3.7 |
1019 |
*/ |
1020 |
private boolean isForStatement() { |
1021 |
int semiColonCount= 1; |
1022 |
while (true) { |
1023 |
nextToken(); |
1024 |
switch (fToken) { |
1025 |
case Symbols.TokenFOR: |
1026 |
//case Symbols.TokenLPAREN: |
1027 |
return true; |
1028 |
case Symbols.TokenRPAREN: |
1029 |
skipScope(); |
1030 |
break; |
1031 |
case Symbols.TokenSEMICOLON: |
1032 |
semiColonCount++; |
1033 |
if (semiColonCount > 2) |
1034 |
return false; |
1035 |
break; |
1036 |
case Symbols.TokenEOF: |
1037 |
return false; |
1038 |
} |
1039 |
} |
1040 |
} |
1041 |
|
1042 |
/** |
975 |
* Skips to the start of a statement that ends at the current position. |
1043 |
* Skips to the start of a statement that ends at the current position. |
976 |
* |
1044 |
* |
977 |
* @param danglingElse whether to indent aligned with the last <code>if</code> |
1045 |
* @param danglingElse whether to indent aligned with the last <code>if</code> |
Lines 1235-1240
Link Here
|
1235 |
return handleScopeIntroduction(startPosition + 1); |
1303 |
return handleScopeIntroduction(startPosition + 1); |
1236 |
|
1304 |
|
1237 |
case Symbols.TokenSEMICOLON: |
1305 |
case Symbols.TokenSEMICOLON: |
|
|
1306 |
int savedPosition= fPosition; |
1307 |
if (isForStatement()) |
1308 |
fIndent= fPrefs.prefContinuationIndent; |
1309 |
else |
1310 |
fPosition= savedPosition; |
1238 |
return fPosition; |
1311 |
return fPosition; |
1239 |
case Symbols.TokenQUESTIONMARK: |
1312 |
case Symbols.TokenQUESTIONMARK: |
1240 |
if (fPrefs.prefTernaryDeepAlign) { |
1313 |
if (fPrefs.prefTernaryDeepAlign) { |
Lines 1244-1249
Link Here
|
1244 |
fIndent= fPrefs.prefTernaryIndent; |
1317 |
fIndent= fPrefs.prefTernaryIndent; |
1245 |
return fPosition; |
1318 |
return fPosition; |
1246 |
} |
1319 |
} |
|
|
1320 |
case Symbols.TokenRETURN: |
1321 |
fIndent= fPrefs.prefContinuationIndent; |
1322 |
return fPosition; |
1323 |
case Symbols.TokenEQUAL: |
1324 |
return handleAssignmentAndComparison(); |
1247 |
case Symbols.TokenEOF: |
1325 |
case Symbols.TokenEOF: |
1248 |
return 0; |
1326 |
return 0; |
1249 |
|
1327 |
|