### Eclipse Workspace Patch 1.0
#P org.eclipse.cdt.ui
Index: src/org/eclipse/cdt/internal/ui/text/CIndenter.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java,v
retrieving revision 1.6
diff -u -r1.6 CIndenter.java
--- src/org/eclipse/cdt/internal/ui/text/CIndenter.java 18 Apr 2007 14:41:32 -0000 1.6
+++ src/org/eclipse/cdt/internal/ui/text/CIndenter.java 27 May 2007 00:19:20 -0000
@@ -62,6 +62,7 @@
final int prefMethodBodyIndent;
final int prefTypeIndent;
final int prefAccessSpecifierIndent;
+ final int prefNamespaceBodyIndent;
final boolean prefIndentBracesForBlocks;
final boolean prefIndentBracesForArrays;
final boolean prefIndentBracesForMethods;
@@ -111,6 +112,7 @@
prefMethodBodyIndent= prefMethodBodyIndent();
prefTypeIndent= prefTypeIndent();
prefAccessSpecifierIndent= prefAccessSpecifierIndent();
+ prefNamespaceBodyIndent= prefNamespaceBodyIndent();
prefIndentBracesForArrays= prefIndentBracesForArrays();
prefIndentBracesForMethods= prefIndentBracesForMethods();
prefIndentBracesForTypes= prefIndentBracesForTypes();
@@ -308,6 +310,13 @@
return 0;
}
+ private int prefNamespaceBodyIndent() {
+ if (DefaultCodeFormatterConstants.TRUE.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_NAMESPACE_HEADER)))
+ return prefBlockIndent();
+ else
+ return 0;
+ }
+
private boolean prefIndentBracesForBlocks() {
return DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_BLOCK));
}
@@ -1009,10 +1018,6 @@
case Symbols.TokenTRY:
return fPosition;
- case Symbols.TokenSTATIC:
- mayBeMethodBody= READ_IDENT; // treat static blocks like methods
- break;
-
case Symbols.TokenCLASS:
case Symbols.TokenENUM:
isTypeBody= true;
@@ -1435,13 +1440,16 @@
pos= fPosition; // store
// special: array initializer
- if (looksLikeArrayInitializerIntro())
+ if (looksLikeArrayInitializerIntro()) {
if (fPrefs.prefArrayDeepIndent)
return setFirstElementAlignment(pos, bound);
else
fIndent= fPrefs.prefArrayIndent;
- else
+ } else if (isNamespace()) {
+ fIndent= fPrefs.prefNamespaceBodyIndent;
+ } else {
fIndent= fPrefs.prefBlockIndent;
+ }
// normal: skip to the statement start before the scope introducer
// opening braces are often on differently ending indents than e.g. a method definition
@@ -1505,6 +1513,24 @@
}
/**
+ * Returns true
if the the current token is "namespace", or the current token
+ * is an identifier and the previous token is "namespace".
+ *
+ * @return true
if the next elements look like the start of a namespace declaration.
+ */
+ private boolean isNamespace() {
+ if (fToken == Symbols.TokenNAMESPACE) {
+ return true; // Anonymous namespace
+ } else if (fToken == Symbols.TokenIDENT) {
+ nextToken(); // Get previous token
+ if (fToken == Symbols.TokenNAMESPACE) {
+ return true; // Named namespace
+ }
+ }
+ return false;
+ }
+
+ /**
* Skips over the next if
keyword. The current token when calling
* this method must be an else
keyword. Returns true
* if a matching if
could be found, false
otherwise.
Index: src/org/eclipse/cdt/internal/ui/text/Symbols.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java,v
retrieving revision 1.6
diff -u -r1.6 Symbols.java
--- src/org/eclipse/cdt/internal/ui/text/Symbols.java 3 Apr 2007 14:07:09 -0000 1.6
+++ src/org/eclipse/cdt/internal/ui/text/Symbols.java 27 May 2007 00:19:20 -0000
@@ -58,5 +58,6 @@
int TokenUNION= 1030;
int TokenENUM= 1031;
int TokenVIRTUAL= 1032;
+ int TokenNAMESPACE= 1033;
int TokenIDENT= 2000;
}
Index: src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java,v
retrieving revision 1.8
diff -u -r1.8 CHeuristicScanner.java
--- src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java 6 Apr 2007 11:54:17 -0000 1.8
+++ src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java 27 May 2007 00:19:20 -0000
@@ -508,6 +508,8 @@
return TokenVIRTUAL;
break;
case 9:
+ if ("namespace".equals(s)) //$NON-NLS-1$
+ return TokenNAMESPACE;
if ("protected".equals(s)) //$NON-NLS-1$
return TokenPROTECTED;
}
Index: templates/default-templates.xml
===================================================================
RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/templates/default-templates.xml,v
retrieving revision 1.7
diff -u -r1.7 default-templates.xml
--- templates/default-templates.xml 23 Mar 2007 14:16:53 -0000 1.7
+++ templates/default-templates.xml 27 May 2007 00:19:20 -0000
@@ -64,14 +64,18 @@
}
class ${name} {
+public:
${cursor}
+
private:
};
-using namespace ${namespace};
+using namespace ${name};
-namespace ${namespace} {
- ${cursor}
-}
+namespace ${name} {
+
+${cursor}
+
+} // namespace ${name}
${type} ${name} = new ${type}(${arguments});