diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java
index ff79b5b9fbd..676e44bb153 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CAutoIndentTest.java
@@ -534,5 +534,22 @@ public class CAutoIndentTest extends TestCase {
tester.paste(copy);
assertEquals(copy+copy, tester.fDoc.get());
}
+
+ public void testIndentInsideNamespaceDefinition_Bug188007() throws Exception {
+ AutoEditTester tester = createAutoEditTester();
+
+ tester.type("namespace ns {\n");
+ assertEquals("", tester.getLine());
+ assertEquals(0, tester.getCaretColumn());
+
+ DefaultCodeFormatterOptions defaultOptions= DefaultCodeFormatterOptions.getDefaultSettings();
+ defaultOptions.indent_body_declarations_compare_to_namespace_header= true;
+ CCorePlugin.setOptions(new HashMap(defaultOptions.getMap()));
+ tester = createAutoEditTester();
+
+ tester.type("namespace ns {\n");
+ assertEquals("\t", tester.getLine());
+ assertEquals(1, tester.getCaretColumn());
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
index 4477d6b57ec..8b41e252511 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* QNX Software System
+ * Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui;
@@ -244,6 +245,14 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
}
return true;
}
+ if (element instanceof IProject) {
+ IProject project= (IProject)element;
+ return project.isAccessible();
+ }
+ if (element instanceof IFolder) {
+ IFolder folder= (IFolder)element;
+ return folder.isAccessible();
+ }
if (element instanceof IParent) {
// when we have C children return true, else we fetch all the children
@@ -251,6 +260,9 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return true;
}
}
+ if (element instanceof CElementGrouping) {
+ return true;
+ }
Object[] children= getChildren(element);
return (children != null) && children.length > 0;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java
index f6320116bff..b530475dc08 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java
@@ -508,6 +508,8 @@ public final class CHeuristicScanner implements Symbols {
return TokenVIRTUAL;
break;
case 9:
+ if ("namespace".equals(s)) //$NON-NLS-1$
+ return TokenNAMESPACE;
if ("protected".equals(s)) //$NON-NLS-1$
return TokenPROTECTED;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
index 5ae9d9d5900..83d4a906a78 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java
@@ -62,6 +62,7 @@ public final class CIndenter {
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 @@ public final class CIndenter {
prefMethodBodyIndent= prefMethodBodyIndent();
prefTypeIndent= prefTypeIndent();
prefAccessSpecifierIndent= prefAccessSpecifierIndent();
+ prefNamespaceBodyIndent= prefNamespaceBodyIndent();
prefIndentBracesForArrays= prefIndentBracesForArrays();
prefIndentBracesForMethods= prefIndentBracesForMethods();
prefIndentBracesForTypes= prefIndentBracesForTypes();
@@ -308,6 +310,13 @@ public final class CIndenter {
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 @@ public final class CIndenter {
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 @@ public final class CIndenter {
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
@@ -1504,6 +1512,24 @@ public final class CIndenter {
return false;
}
+ /**
+ * 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
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java
index 97774ddfa3a..7ec5bcae367 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java
@@ -58,5 +58,6 @@ public interface Symbols {
int TokenUNION= 1030;
int TokenENUM= 1031;
int TokenVIRTUAL= 1032;
+ int TokenNAMESPACE= 1033;
int TokenIDENT= 2000;
}
diff --git a/core/org.eclipse.cdt.ui/templates/default-templates.xml b/core/org.eclipse.cdt.ui/templates/default-templates.xml
index d27c3fd000a..f0b57a9e72e 100644
--- a/core/org.eclipse.cdt.ui/templates/default-templates.xml
+++ b/core/org.eclipse.cdt.ui/templates/default-templates.xml
@@ -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});