View | Details | Raw Unified | Return to bug 65317 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/text/JavaIndenter.java (-6 / +84 lines)
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
(-)ui/org/eclipse/jdt/internal/ui/text/java/JavaAutoIndentStrategy.java (-23 / +21 lines)
Lines 693-724 Link Here
693
				if (lineLength == 0) // don't modify empty lines
693
				if (lineLength == 0) // don't modify empty lines
694
					continue;
694
					continue;
695
695
696
				if (!isIndentDetected) {
697
696
698
					// indent the first pasted line
697
				// indent the first pasted line
699
					String current= getCurrentIndent(temp, l);
698
				String current= getCurrentIndent(temp, l);
700
					StringBuffer correct= indenter.computeIndentation(lineOffset);
699
				StringBuffer correct= indenter.computeIndentation(lineOffset);
701
					if (correct == null)
700
				if (correct == null)
702
						return; // bail out
701
					return; // bail out
703
702
704
					insertLength= subtractIndent(correct, current, addition, tabLength);
703
				insertLength= subtractIndent(correct, current, addition, tabLength);
705
					if (l != first && temp.get(lineOffset, lineLength).trim().length() != 0) {
704
				if (!isIndentDetected && l != first && temp.get(lineOffset, lineLength).trim().length() != 0) {
706
						isIndentDetected= true;
705
					isIndentDetected= true;
707
						if (insertLength == 0) {
706
					if (insertLength == 0) {
708
							 // no adjustment needed, bail out
707
						// no adjustment needed, bail out
709
							if (firstLine == 0) {
708
						if (firstLine == 0) {
710
								// but we still need to adjust the first line
709
							// but we still need to adjust the first line
711
								command.offset= newOffset;
710
							command.offset= newOffset;
712
								command.length= newLength;
711
							command.length= newLength;
713
								if (changed)
712
							if (changed)
714
									break; // still need to get the leading indent of the first line
713
								break; // still need to get the leading indent of the first line
715
							}
716
							return;
717
						}
714
						}
718
						removeJavaStuff(temp);
715
						return;
719
					} else {
720
						changed= insertLength != 0;
721
					}
716
					}
717
					removeJavaStuff(temp);
718
				} else {
719
					changed= insertLength != 0;
722
				}
720
				}
723
721
724
				// relatively indent all pasted lines
722
				// relatively indent all pasted lines

Return to bug 65317