mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 188007: Namespace indenting preference is not honored
Patch by Sergey Prigogin (Google)
This commit is contained in:
parent
77bb9964a6
commit
d8c6b82a23
6 changed files with 73 additions and 11 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 <code>true</code> if the the current token is "namespace", or the current token
|
||||
* is an identifier and the previous token is "namespace".
|
||||
*
|
||||
* @return <code>true</code> 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 <code>if</code> keyword. The current token when calling
|
||||
* this method must be an <code>else</code> keyword. Returns <code>true</code>
|
||||
|
|
|
@ -58,5 +58,6 @@ public interface Symbols {
|
|||
int TokenUNION= 1030;
|
||||
int TokenENUM= 1031;
|
||||
int TokenVIRTUAL= 1032;
|
||||
int TokenNAMESPACE= 1033;
|
||||
int TokenIDENT= 2000;
|
||||
}
|
||||
|
|
|
@ -64,14 +64,18 @@
|
|||
}
|
||||
</template>
|
||||
<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} {
|
||||
public:
|
||||
${cursor}
|
||||
|
||||
private:
|
||||
};</template>
|
||||
<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};
|
||||
<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};
|
||||
</template>
|
||||
<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} {
|
||||
<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} {
|
||||
|
||||
${cursor}
|
||||
}</template>
|
||||
|
||||
} // namespace ${name}</template>
|
||||
<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>
|
||||
<template name="comment" description="%defaultmultilinecomment" context="org.eclipse.cdt.ui.text.templates.c" id="org.eclipse.cdt.ui.text.templates.c.comment" enabled="true">
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue