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);
|
tester.paste(copy);
|
||||||
assertEquals(copy+copy, tester.fDoc.get());
|
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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* QNX Software System
|
* QNX Software System
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui;
|
package org.eclipse.cdt.internal.ui;
|
||||||
|
|
||||||
|
@ -244,6 +245,14 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
||||||
}
|
}
|
||||||
return true;
|
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) {
|
if (element instanceof IParent) {
|
||||||
// when we have C children return true, else we fetch all the children
|
// when we have C children return true, else we fetch all the children
|
||||||
|
@ -251,6 +260,9 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (element instanceof CElementGrouping) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Object[] children= getChildren(element);
|
Object[] children= getChildren(element);
|
||||||
return (children != null) && children.length > 0;
|
return (children != null) && children.length > 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,6 +508,8 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
return TokenVIRTUAL;
|
return TokenVIRTUAL;
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
|
if ("namespace".equals(s)) //$NON-NLS-1$
|
||||||
|
return TokenNAMESPACE;
|
||||||
if ("protected".equals(s)) //$NON-NLS-1$
|
if ("protected".equals(s)) //$NON-NLS-1$
|
||||||
return TokenPROTECTED;
|
return TokenPROTECTED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ public final class CIndenter {
|
||||||
final int prefMethodBodyIndent;
|
final int prefMethodBodyIndent;
|
||||||
final int prefTypeIndent;
|
final int prefTypeIndent;
|
||||||
final int prefAccessSpecifierIndent;
|
final int prefAccessSpecifierIndent;
|
||||||
|
final int prefNamespaceBodyIndent;
|
||||||
final boolean prefIndentBracesForBlocks;
|
final boolean prefIndentBracesForBlocks;
|
||||||
final boolean prefIndentBracesForArrays;
|
final boolean prefIndentBracesForArrays;
|
||||||
final boolean prefIndentBracesForMethods;
|
final boolean prefIndentBracesForMethods;
|
||||||
|
@ -111,6 +112,7 @@ public final class CIndenter {
|
||||||
prefMethodBodyIndent= prefMethodBodyIndent();
|
prefMethodBodyIndent= prefMethodBodyIndent();
|
||||||
prefTypeIndent= prefTypeIndent();
|
prefTypeIndent= prefTypeIndent();
|
||||||
prefAccessSpecifierIndent= prefAccessSpecifierIndent();
|
prefAccessSpecifierIndent= prefAccessSpecifierIndent();
|
||||||
|
prefNamespaceBodyIndent= prefNamespaceBodyIndent();
|
||||||
prefIndentBracesForArrays= prefIndentBracesForArrays();
|
prefIndentBracesForArrays= prefIndentBracesForArrays();
|
||||||
prefIndentBracesForMethods= prefIndentBracesForMethods();
|
prefIndentBracesForMethods= prefIndentBracesForMethods();
|
||||||
prefIndentBracesForTypes= prefIndentBracesForTypes();
|
prefIndentBracesForTypes= prefIndentBracesForTypes();
|
||||||
|
@ -308,6 +310,13 @@ public final class CIndenter {
|
||||||
return 0;
|
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() {
|
private boolean prefIndentBracesForBlocks() {
|
||||||
return DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_BLOCK));
|
return DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_BLOCK));
|
||||||
}
|
}
|
||||||
|
@ -1009,10 +1018,6 @@ public final class CIndenter {
|
||||||
case Symbols.TokenTRY:
|
case Symbols.TokenTRY:
|
||||||
return fPosition;
|
return fPosition;
|
||||||
|
|
||||||
case Symbols.TokenSTATIC:
|
|
||||||
mayBeMethodBody= READ_IDENT; // treat static blocks like methods
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Symbols.TokenCLASS:
|
case Symbols.TokenCLASS:
|
||||||
case Symbols.TokenENUM:
|
case Symbols.TokenENUM:
|
||||||
isTypeBody= true;
|
isTypeBody= true;
|
||||||
|
@ -1435,13 +1440,16 @@ public final class CIndenter {
|
||||||
pos= fPosition; // store
|
pos= fPosition; // store
|
||||||
|
|
||||||
// special: array initializer
|
// special: array initializer
|
||||||
if (looksLikeArrayInitializerIntro())
|
if (looksLikeArrayInitializerIntro()) {
|
||||||
if (fPrefs.prefArrayDeepIndent)
|
if (fPrefs.prefArrayDeepIndent)
|
||||||
return setFirstElementAlignment(pos, bound);
|
return setFirstElementAlignment(pos, bound);
|
||||||
else
|
else
|
||||||
fIndent= fPrefs.prefArrayIndent;
|
fIndent= fPrefs.prefArrayIndent;
|
||||||
else
|
} else if (isNamespace()) {
|
||||||
|
fIndent= fPrefs.prefNamespaceBodyIndent;
|
||||||
|
} else {
|
||||||
fIndent= fPrefs.prefBlockIndent;
|
fIndent= fPrefs.prefBlockIndent;
|
||||||
|
}
|
||||||
|
|
||||||
// normal: skip to the statement start before the scope introducer
|
// normal: skip to the statement start before the scope introducer
|
||||||
// opening braces are often on differently ending indents than e.g. a method definition
|
// opening braces are often on differently ending indents than e.g. a method definition
|
||||||
|
@ -1504,6 +1512,24 @@ public final class CIndenter {
|
||||||
return false;
|
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
|
* 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>
|
* this method must be an <code>else</code> keyword. Returns <code>true</code>
|
||||||
|
|
|
@ -58,5 +58,6 @@ public interface Symbols {
|
||||||
int TokenUNION= 1030;
|
int TokenUNION= 1030;
|
||||||
int TokenENUM= 1031;
|
int TokenENUM= 1031;
|
||||||
int TokenVIRTUAL= 1032;
|
int TokenVIRTUAL= 1032;
|
||||||
|
int TokenNAMESPACE= 1033;
|
||||||
int TokenIDENT= 2000;
|
int TokenIDENT= 2000;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,14 +64,18 @@
|
||||||
}
|
}
|
||||||
</template>
|
</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} {
|
<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}
|
${cursor}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};</template>
|
};</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>
|
||||||
<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>
|
${cursor}
|
||||||
|
|
||||||
|
} // 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="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">
|
<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