View | Details | Raw Unified | Return to bug 188007
Collapse All | Expand All

(-)src/org/eclipse/cdt/internal/ui/text/CIndenter.java (-6 / +32 lines)
Lines 62-67 Link Here
62
		final int prefMethodBodyIndent;
62
		final int prefMethodBodyIndent;
63
		final int prefTypeIndent;
63
		final int prefTypeIndent;
64
		final int prefAccessSpecifierIndent;
64
		final int prefAccessSpecifierIndent;
65
		final int prefNamespaceBodyIndent;
65
		final boolean prefIndentBracesForBlocks;
66
		final boolean prefIndentBracesForBlocks;
66
		final boolean prefIndentBracesForArrays;
67
		final boolean prefIndentBracesForArrays;
67
		final boolean prefIndentBracesForMethods;
68
		final boolean prefIndentBracesForMethods;
Lines 111-116 Link Here
111
			prefMethodBodyIndent= prefMethodBodyIndent();
112
			prefMethodBodyIndent= prefMethodBodyIndent();
112
			prefTypeIndent= prefTypeIndent();
113
			prefTypeIndent= prefTypeIndent();
113
			prefAccessSpecifierIndent= prefAccessSpecifierIndent();
114
			prefAccessSpecifierIndent= prefAccessSpecifierIndent();
115
			prefNamespaceBodyIndent= prefNamespaceBodyIndent();
114
			prefIndentBracesForArrays= prefIndentBracesForArrays();
116
			prefIndentBracesForArrays= prefIndentBracesForArrays();
115
			prefIndentBracesForMethods= prefIndentBracesForMethods();
117
			prefIndentBracesForMethods= prefIndentBracesForMethods();
116
			prefIndentBracesForTypes= prefIndentBracesForTypes();
118
			prefIndentBracesForTypes= prefIndentBracesForTypes();
Lines 308-313 Link Here
308
				return 0;
310
				return 0;
309
		}
311
		}
310
312
313
		private int prefNamespaceBodyIndent() {
314
			if (DefaultCodeFormatterConstants.TRUE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_NAMESPACE_HEADER)))
315
				return prefBlockIndent();
316
			else
317
				return 0;
318
		}
319
311
		private boolean prefIndentBracesForBlocks() {
320
		private boolean prefIndentBracesForBlocks() {
312
			return DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_BLOCK));
321
			return DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_BLOCK));
313
		}
322
		}
Lines 1009-1018 Link Here
1009
					case Symbols.TokenTRY:
1018
					case Symbols.TokenTRY:
1010
						return fPosition;
1019
						return fPosition;
1011
1020
1012
					case Symbols.TokenSTATIC:
1013
						mayBeMethodBody= READ_IDENT; // treat static blocks like methods
1014
						break;
1015
1016
					case Symbols.TokenCLASS:
1021
					case Symbols.TokenCLASS:
1017
					case Symbols.TokenENUM:
1022
					case Symbols.TokenENUM:
1018
						isTypeBody= true;
1023
						isTypeBody= true;
Lines 1435-1447 Link Here
1435
				pos= fPosition; // store
1440
				pos= fPosition; // store
1436
1441
1437
				// special: array initializer
1442
				// special: array initializer
1438
				if (looksLikeArrayInitializerIntro())
1443
				if (looksLikeArrayInitializerIntro()) {
1439
					if (fPrefs.prefArrayDeepIndent)
1444
					if (fPrefs.prefArrayDeepIndent)
1440
						return setFirstElementAlignment(pos, bound);
1445
						return setFirstElementAlignment(pos, bound);
1441
					else
1446
					else
1442
						fIndent= fPrefs.prefArrayIndent;
1447
						fIndent= fPrefs.prefArrayIndent;
1443
				else
1448
				} else if (isNamespace()) {
1449
					fIndent= fPrefs.prefNamespaceBodyIndent;
1450
				} else {
1444
					fIndent= fPrefs.prefBlockIndent;
1451
					fIndent= fPrefs.prefBlockIndent;
1452
				}
1445
1453
1446
				// normal: skip to the statement start before the scope introducer
1454
				// normal: skip to the statement start before the scope introducer
1447
				// opening braces are often on differently ending indents than e.g. a method definition
1455
				// opening braces are often on differently ending indents than e.g. a method definition
Lines 1505-1510 Link Here
1505
	}
1513
	}
1506
1514
1507
	/**
1515
	/**
1516
	 * Returns <code>true</code> if the the current token is "namespace", or the current token
1517
	 * is an identifier and the previous token is "namespace".
1518
	 *
1519
	 * @return <code>true</code> if the next elements look like the start of a namespace declaration.
1520
	 */
1521
	private boolean isNamespace() {
1522
		if (fToken == Symbols.TokenNAMESPACE) {
1523
			return true;		// Anonymous namespace
1524
		} else if (fToken == Symbols.TokenIDENT) {
1525
			nextToken();		// Get previous token
1526
			if (fToken == Symbols.TokenNAMESPACE) {
1527
				return true;	// Named namespace
1528
			}
1529
		}
1530
		return false;
1531
	}
1532
1533
	/**
1508
	 * Skips over the next <code>if</code> keyword. The current token when calling
1534
	 * Skips over the next <code>if</code> keyword. The current token when calling
1509
	 * this method must be an <code>else</code> keyword. Returns <code>true</code>
1535
	 * this method must be an <code>else</code> keyword. Returns <code>true</code>
1510
	 * if a matching <code>if</code> could be found, <code>false</code> otherwise.
1536
	 * if a matching <code>if</code> could be found, <code>false</code> otherwise.
(-)src/org/eclipse/cdt/internal/ui/text/Symbols.java (+1 lines)
Lines 58-62 Link Here
58
	int TokenUNION= 1030;
58
	int TokenUNION= 1030;
59
	int TokenENUM= 1031;
59
	int TokenENUM= 1031;
60
	int TokenVIRTUAL= 1032;
60
	int TokenVIRTUAL= 1032;
61
	int TokenNAMESPACE= 1033;
61
	int TokenIDENT= 2000;
62
	int TokenIDENT= 2000;
62
}
63
}
(-)src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java (+2 lines)
Lines 508-513 Link Here
508
					return TokenVIRTUAL;
508
					return TokenVIRTUAL;
509
				break;
509
				break;
510
			case 9:
510
			case 9:
511
				if ("namespace".equals(s)) //$NON-NLS-1$
512
					return TokenNAMESPACE;
511
				if ("protected".equals(s)) //$NON-NLS-1$
513
				if ("protected".equals(s)) //$NON-NLS-1$
512
					return TokenPROTECTED;
514
					return TokenPROTECTED;
513
		}
515
		}
(-)templates/default-templates.xml (-4 / +8 lines)
Lines 64-77 Link Here
64
}
64
}
65
</template>
65
</template>
66
<template name="class" description="%classDeclaration" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.cpp.class" enabled="true">class ${name} {
66
<template name="class" description="%classDeclaration" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.cpp.class" enabled="true">class ${name} {
67
public:
67
	${cursor}
68
	${cursor}
69
68
private:
70
private:
69
};</template>
71
};</template>
70
<template name="using" description="%usinganamespace" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.cpp.using" enabled="true">using namespace ${namespace};
72
<template name="using" description="%usinganamespace" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.cpp.using" enabled="true">using namespace ${name};
71
</template>
73
</template>
72
<template name="namespace" description="%namespaceDeclaration" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.cpp.namespace" enabled="true">namespace ${namespace} {
74
<template name="namespace" description="%namespaceDeclaration" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.cpp.namespace" enabled="true">namespace ${name} {
73
	${cursor}
75
74
}</template>
76
${cursor}
77
78
}  // namespace ${name}</template>
75
<template name="new" description="%createnewobject" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.cpp.new" enabled="true">${type} ${name} = new ${type}(${arguments});</template>
79
<template name="new" description="%createnewobject" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.cpp.new" enabled="true">${type} ${name} = new ${type}(${arguments});</template>
76
<template name="comment" description="%defaultmultilinecomment" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.c.comment" enabled="true">
80
<template name="comment" description="%defaultmultilinecomment" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.c.comment" enabled="true">
77
/*
81
/*

Return to bug 188007