1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 16:55:38 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-02-06 20:36:09 -08:00
parent 8a73a23e9d
commit 38803901ec
15 changed files with 80 additions and 92 deletions

View file

@ -11,7 +11,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
/** /**
* This interface represents a binary expression. * This interface represents a binary expression.
* *
@ -36,15 +35,14 @@ public interface IASTBinaryExpression extends IASTExpression {
"IASTBinaryExpression.OPERAND_TWO - IASTExpression for RHS"); //$NON-NLS-1$ "IASTBinaryExpression.OPERAND_TWO - IASTExpression for RHS"); //$NON-NLS-1$
/** /**
* Set the operator. * Sets the operator.
* *
* @param op * @param op value to set.
* Value to set.
*/ */
public void setOperator(int op); public void setOperator(int op);
/** /**
* Get the operator. * Returns the operator.
* *
* @return int value as operator * @return int value as operator
*/ */
@ -244,7 +242,6 @@ public interface IASTBinaryExpression extends IASTExpression {
* @param expression * @param expression
* <code>IASTExpression</code> value. * <code>IASTExpression</code> value.
*/ */
public void setOperand1(IASTExpression expression); public void setOperand1(IASTExpression expression);
/** /**

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn (Wind River Systems) - Initial API and implementation * Markus Schorn (Wind River Systems) - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
@ -25,7 +25,7 @@ public interface IASTBinaryTypeIdExpression extends IASTExpression {
public static enum Operator {__is_base_of} public static enum Operator {__is_base_of}
/** /**
* Get the operator for the expression. * Returns the operator for the expression.
*/ */
public Operator getOperator(); public Operator getOperator();
@ -40,22 +40,23 @@ public interface IASTBinaryTypeIdExpression extends IASTExpression {
public IASTTypeId getOperand2(); public IASTTypeId getOperand2();
/** /**
* Set the operator for the expression. * Sets the operator for the expression.
*/ */
public void setOperator(Operator value); public void setOperator(Operator value);
/** /**
* Set the first operand. * Sets the first operand.
*/ */
public void setOperand1(IASTTypeId typeId); public void setOperand1(IASTTypeId typeId);
/** /**
* Set the second operand. * Sets the second operand.
*/ */
public void setOperand2(IASTTypeId typeId); public void setOperand2(IASTTypeId typeId);
@Override @Override
public IASTBinaryTypeIdExpression copy(); public IASTBinaryTypeIdExpression copy();
@Override @Override
public IASTBinaryTypeIdExpression copy(CopyStyle style); public IASTBinaryTypeIdExpression copy(CopyStyle style);
} }

View file

@ -11,7 +11,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
/** /**
* This is the root class of expressions. * This is the root class of expressions.
* *
@ -28,7 +27,7 @@ public interface IASTExpression extends IASTInitializerClause {
*/ */
LVALUE, LVALUE,
/** /**
* Expiring value as introduced by c++ 0x. * Expiring value as introduced by c++11.
*/ */
XVALUE, XVALUE,
/** /**
@ -42,6 +41,7 @@ public interface IASTExpression extends IASTInitializerClause {
public boolean isRValue() { public boolean isRValue() {
return this != LVALUE; return this != LVALUE;
} }
/** /**
* A generalized lvalue is either an lvalue or an xvalue. * A generalized lvalue is either an lvalue or an xvalue.
*/ */
@ -53,7 +53,7 @@ public interface IASTExpression extends IASTInitializerClause {
/** /**
* Empty expression array. * Empty expression array.
*/ */
public static final IASTExpression[] EMPTY_EXPRESSION_ARRAY = new IASTExpression[0]; public static final IASTExpression[] EMPTY_EXPRESSION_ARRAY = {};
public IType getExpressionType(); public IType getExpressionType();

View file

@ -17,7 +17,6 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTUnaryExpression extends IASTExpression { public interface IASTUnaryExpression extends IASTExpression {
/** /**
* Prefix increment. * Prefix increment.
* <code>op_prefixIncr</code> ++exp * <code>op_prefixIncr</code> ++exp
@ -32,7 +31,7 @@ public interface IASTUnaryExpression extends IASTExpression {
/** /**
* Operator plus. * Operator plus.
* <code>op_plus</code> ==> + exp * <code>op_plus</code> ==> +exp
*/ */
public static final int op_plus = 2; public static final int op_plus = 2;

View file

@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* John Camelon (IBM) - Initial API and implementation * John Camelon (IBM) - Initial API and implementation
* Mike Kucera (IBM) * Mike Kucera (IBM)
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
@ -22,7 +22,6 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface ICPPASTBinaryExpression extends IASTBinaryExpression, IASTImplicitNameOwner { public interface ICPPASTBinaryExpression extends IASTBinaryExpression, IASTImplicitNameOwner {
/** /**
* <code>op_pmdot</code> pointer-to-member field dereference. * <code>op_pmdot</code> pointer-to-member field dereference.
*/ */

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2011 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2012 Wind River Systems, Inc. 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
@ -260,9 +260,10 @@ public final class ASTRewrite {
} }
/** /**
* Returns comments for the given node.
* *
* @param node the node * @param node the node
* @param pos the position * @param pos the position of the comments
* @return All comments assigned to the node at this position * @return All comments assigned to the node at this position
* @since 5.3 * @since 5.3
*/ */

View file

@ -20,7 +20,6 @@ package org.eclipse.cdt.core.dom.rewrite;
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
*/ */
public interface ITrackedNodePosition { public interface ITrackedNodePosition {
/** /**
* Returns the original or modified start position of the tracked node depending if called before * Returns the original or modified start position of the tracked node depending if called before
* or after the rewrite is applied. <code>-1</code> is returned for removed nodes. * or after the rewrite is applied. <code>-1</code> is returned for removed nodes.

View file

@ -259,7 +259,7 @@ public abstract class ASTNode implements IASTNode {
ASTNode astNode= (ASTNode) node; ASTNode astNode= (ASTNode) node;
final int offset = getOffset(); final int offset = getOffset();
final int nodeOffset= astNode.getOffset(); final int nodeOffset= astNode.getOffset();
return offset <= nodeOffset && nodeOffset+astNode.length <= offset+length; return offset <= nodeOffset && nodeOffset + astNode.length <= offset + length;
} }
return false; return false;
} }
@ -267,7 +267,7 @@ public abstract class ASTNode implements IASTNode {
@Override @Override
public IToken getSyntax() throws ExpansionOverlapsBoundaryException { public IToken getSyntax() throws ExpansionOverlapsBoundaryException {
final int offset = getOffset(); final int offset = getOffset();
return getSyntax(offset, offset+length, 0); return getSyntax(offset, offset + length, 0);
} }
@Override @Override
@ -279,7 +279,7 @@ public abstract class ASTNode implements IASTNode {
@Override @Override
public IToken getTrailingSyntax() throws ExpansionOverlapsBoundaryException { public IToken getTrailingSyntax() throws ExpansionOverlapsBoundaryException {
int right= getBoundary(1); int right= getBoundary(1);
return getSyntax(getOffset()+length, right, 1); return getSyntax(getOffset() + length, right, 1);
} }
/** /**
@ -296,15 +296,14 @@ public abstract class ASTNode implements IASTNode {
ASTNode astNode= (ASTNode) sib; ASTNode astNode= (ASTNode) sib;
int offset= astNode.getOffset(); int offset= astNode.getOffset();
if (direction < 0) { if (direction < 0) {
offset+= astNode.getLength(); offset += astNode.getLength();
} }
return offset; return offset;
} }
// no parent // No parent.
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
private IToken getSyntax(int fromSequenceNumber, int nextSequenceNumber, int direction) throws ExpansionOverlapsBoundaryException { private IToken getSyntax(int fromSequenceNumber, int nextSequenceNumber, int direction) throws ExpansionOverlapsBoundaryException {
final IASTTranslationUnit tu= getTranslationUnit(); final IASTTranslationUnit tu= getTranslationUnit();
if (!(tu instanceof ASTNode)) if (!(tu instanceof ASTNode))
@ -315,7 +314,7 @@ public abstract class ASTNode implements IASTNode {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
int endSequenceNumber= lr.convertToSequenceEndNumber(nextSequenceNumber); int endSequenceNumber= lr.convertToSequenceEndNumber(nextSequenceNumber);
IASTFileLocation total= lr.getMappedFileLocation(fromSequenceNumber, endSequenceNumber-fromSequenceNumber); IASTFileLocation total= lr.getMappedFileLocation(fromSequenceNumber, endSequenceNumber - fromSequenceNumber);
IASTFileLocation myfloc= getFileLocation(); IASTFileLocation myfloc= getFileLocation();
if (total == null || myfloc == null) if (total == null || myfloc == null)
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
@ -324,13 +323,13 @@ public abstract class ASTNode implements IASTNode {
throw new ExpansionOverlapsBoundaryException(); throw new ExpansionOverlapsBoundaryException();
if (fromSequenceNumber > 0) { if (fromSequenceNumber > 0) {
IASTFileLocation fl= lr.getMappedFileLocation(fromSequenceNumber-1, endSequenceNumber-fromSequenceNumber+1); IASTFileLocation fl= lr.getMappedFileLocation(fromSequenceNumber-1, endSequenceNumber - fromSequenceNumber + 1);
if (fl.getFileName().equals(total.getFileName()) && fl.getNodeOffset() == total.getNodeOffset()) if (fl.getFileName().equals(total.getFileName()) && fl.getNodeOffset() == total.getNodeOffset())
throw new ExpansionOverlapsBoundaryException(); throw new ExpansionOverlapsBoundaryException();
} }
if (endSequenceNumber < ((ASTNode) tu).getOffset() + ((ASTNode) tu).getLength()) { if (endSequenceNumber < ((ASTNode) tu).getOffset() + ((ASTNode) tu).getLength()) {
IASTFileLocation fl= lr.getMappedFileLocation(fromSequenceNumber, nextSequenceNumber-fromSequenceNumber+1); IASTFileLocation fl= lr.getMappedFileLocation(fromSequenceNumber, nextSequenceNumber - fromSequenceNumber + 1);
if (fl.getFileName().equals(total.getFileName()) && fl.getNodeLength() == total.getNodeLength()) if (fl.getFileName().equals(total.getFileName()) && fl.getNodeLength() == total.getNodeLength())
throw new ExpansionOverlapsBoundaryException(); throw new ExpansionOverlapsBoundaryException();
} }
@ -345,7 +344,7 @@ public abstract class ASTNode implements IASTNode {
try { try {
Token result= null; Token result= null;
Token last= null; Token last= null;
for (;;) { while (true) {
Token t= lex.nextToken(); Token t= lex.nextToken();
switch (t.getType()) { switch (t.getType()) {
case IToken.tEND_OF_INPUT: case IToken.tEND_OF_INPUT:
@ -366,12 +365,12 @@ public abstract class ASTNode implements IASTNode {
} }
} }
} catch (OffsetLimitReachedException e) { } catch (OffsetLimitReachedException e) {
// does not happen without using content assist limit // Does not happen without using content assist limit.
} }
return null; return null;
} }
protected void setCopyLocation(IASTNode originalNode) { protected void setCopyLocation(IASTNode originalNode) {
locations = new IASTNodeLocation[] {new ASTCopyLocation(originalNode)}; locations = new IASTNodeLocation[] { new ASTCopyLocation(originalNode) };
} }
} }

View file

@ -51,8 +51,8 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
@Override @Override
public CPPASTLiteralExpression copy(CopyStyle style) { public CPPASTLiteralExpression copy(CopyStyle style) {
CPPASTLiteralExpression copy = new CPPASTLiteralExpression(kind, value == null ? null CPPASTLiteralExpression copy = new CPPASTLiteralExpression(kind,
: value.clone()); value == null ? null : value.clone());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) { if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this); copy.setCopyLocation(this);

View file

@ -59,7 +59,7 @@ abstract class ASTPreprocessorNode extends ASTNode {
setParent(parent); setParent(parent);
setPropertyInParent(property); setPropertyInParent(property);
setOffset(startNumber); setOffset(startNumber);
setLength(endNumber-startNumber); setLength(endNumber - startNumber);
} }
protected char[] getSource(int offset, int length) { protected char[] getSource(int offset, int length) {
@ -597,9 +597,9 @@ class ASTFunctionStyleMacroDefinition extends ASTMacroDefinition implements IAST
} }
} }
class ASTUndef extends ASTPreprocessorNode implements IASTPreprocessorUndefStatement { class ASTUndef extends ASTPreprocessorNode implements IASTPreprocessorUndefStatement {
private final ASTPreprocessorName fName; private final ASTPreprocessorName fName;
public ASTUndef(IASTTranslationUnit parent, char[] name, int startNumber, int nameNumber, int nameEndNumber, IBinding binding, boolean isActive) { public ASTUndef(IASTTranslationUnit parent, char[] name, int startNumber, int nameNumber, int nameEndNumber, IBinding binding, boolean isActive) {
super(parent, IASTTranslationUnit.PREPROCESSOR_STATEMENT, startNumber, nameEndNumber); super(parent, IASTTranslationUnit.PREPROCESSOR_STATEMENT, startNumber, nameEndNumber);
fName= new ASTPreprocessorName(this, IASTPreprocessorStatement.MACRO_NAME, nameNumber, nameEndNumber, name, binding); fName= new ASTPreprocessorName(this, IASTPreprocessorStatement.MACRO_NAME, nameNumber, nameEndNumber, name, binding);
@ -686,7 +686,7 @@ class ASTFileLocation implements IASTFileLocation {
@Override @Override
public int getEndingLineNumber() { public int getEndingLineNumber() {
int end= fLength > 0 ? fOffset+fLength-1 : fOffset; int end= fLength > 0 ? fOffset + fLength - 1 : fOffset;
return fLocationCtx.getLineNumber(end); return fLocationCtx.getLineNumber(end);
} }
@ -701,7 +701,7 @@ class ASTFileLocation implements IASTFileLocation {
@Override @Override
public String toString() { public String toString() {
return getFileName() + "[" + fOffset + "," + (fOffset+fLength) + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ return getFileName() + "[" + fOffset + "," + (fOffset + fLength) + "]"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
} }
public int getSequenceNumber() { public int getSequenceNumber() {
@ -709,7 +709,7 @@ class ASTFileLocation implements IASTFileLocation {
} }
public int getSequenceEndNumber() { public int getSequenceEndNumber() {
return fLocationCtx.getSequenceNumberForOffset(fOffset+fLength, true); return fLocationCtx.getSequenceNumberForOffset(fOffset + fLength, true);
} }
public LocationCtxFile getLocationContext() { public LocationCtxFile getLocationContext() {
@ -723,7 +723,6 @@ class ASTFileLocation implements IASTFileLocation {
} }
class ASTMacroExpansion extends ASTPreprocessorNode implements IASTPreprocessorMacroExpansion { class ASTMacroExpansion extends ASTPreprocessorNode implements IASTPreprocessorMacroExpansion {
private LocationCtxMacroExpansion fContext; private LocationCtxMacroExpansion fContext;
public ASTMacroExpansion(IASTNode parent, int startNumber, int endNumber) { public ASTMacroExpansion(IASTNode parent, int startNumber, int endNumber) {
@ -765,7 +764,6 @@ class ASTMacroExpansion extends ASTPreprocessorNode implements IASTPreprocessorM
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
class ASTMacroExpansionLocation implements IASTMacroExpansionLocation, org.eclipse.cdt.core.dom.ast.IASTMacroExpansion { class ASTMacroExpansionLocation implements IASTMacroExpansionLocation, org.eclipse.cdt.core.dom.ast.IASTMacroExpansion {
private LocationCtxMacroExpansion fContext; private LocationCtxMacroExpansion fContext;
private int fOffset; private int fOffset;
private int fLength; private int fLength;
@ -817,7 +815,7 @@ class ASTMacroExpansionLocation implements IASTMacroExpansionLocation, org.eclip
@Override @Override
public String toString() { public String toString() {
return fContext.getMacroDefinition().getName().toString() + "[" + fOffset + "," + (fOffset+fLength) + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ return fContext.getMacroDefinition().getName().toString() + "[" + fOffset + "," + (fOffset+fLength) + "]"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
} }
public IASTImageLocation getImageLocation() { public IASTImageLocation getImageLocation() {
@ -872,7 +870,6 @@ class ASTFileLocationForBuiltins implements IASTFileLocation {
} }
} }
class ASTImageLocation extends ASTFileLocationForBuiltins implements IASTImageLocation { class ASTImageLocation extends ASTFileLocationForBuiltins implements IASTImageLocation {
private final int fKind; private final int fKind;

View file

@ -34,7 +34,7 @@ class LocationCtxMacroExpansion extends LocationCtx {
fLength= length; fLength= length;
fLocationInfos= imageLocations; fLocationInfos= imageLocations;
fExpansionName= expansionName; fExpansionName= expansionName;
if (expansionName.getParent() instanceof ASTMacroExpansion == false) { if (!(expansionName.getParent() instanceof ASTMacroExpansion)) {
throw new IllegalArgumentException(expansionName.toString() + " is not a macro expansion name"); //$NON-NLS-1$ throw new IllegalArgumentException(expansionName.toString() + " is not a macro expansion name"); //$NON-NLS-1$
} }
} }

View file

@ -58,7 +58,7 @@ import org.eclipse.cdt.internal.ui.refactoring.NameInformation;
* @author Mirko Stocker * @author Mirko Stocker
*/ */
public class ExtractExpression extends ExtractedFunctionConstructionHelper { public class ExtractExpression extends ExtractedFunctionConstructionHelper {
final static char[] ZERO= { '0' }; private final static char[] ZERO= { '0' };
@Override @Override
public void constructMethodBody(IASTCompoundStatement compound, List<IASTNode> list, public void constructMethodBody(IASTCompoundStatement compound, List<IASTNode> list,
@ -74,12 +74,12 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
private IASTExpression getExpression(List<IASTNode> list) { private IASTExpression getExpression(List<IASTNode> list) {
if (list.size() > 1) { if (list.size() > 1) {
CPPASTBinaryExpression bExp = new CPPASTBinaryExpression(); CPPASTBinaryExpression expression = new CPPASTBinaryExpression();
bExp.setParent(list.get(0).getParent()); expression.setParent(list.get(0).getParent());
bExp.setOperand1((IASTExpression) list.get(0).copy(CopyStyle.withLocations)); expression.setOperand1((IASTExpression) list.get(0).copy(CopyStyle.withLocations));
bExp.setOperator(((IASTBinaryExpression) list.get(1).getParent()).getOperator()); expression.setOperator(((IASTBinaryExpression) list.get(1).getParent()).getOperator());
bExp.setOperand2(getExpression(list.subList(1, list.size()))); expression.setOperand2(getExpression(list.subList(1, list.size())));
return bExp; return expression;
} else { } else {
return (IASTExpression) list.get(0).copy(CopyStyle.withLocations); return (IASTExpression) list.get(0).copy(CopyStyle.withLocations);
} }

View file

@ -34,9 +34,9 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.ASTHelper;
*/ */
public class ExtractStatement extends ExtractedFunctionConstructionHelper { public class ExtractStatement extends ExtractedFunctionConstructionHelper {
@Override @Override
public void constructMethodBody(IASTCompoundStatement compound, List<IASTNode> list, public void constructMethodBody(IASTCompoundStatement compound, List<IASTNode> nodes,
ASTRewrite rewrite, TextEditGroup group) { ASTRewrite rewrite, TextEditGroup group) {
for (IASTNode node : list) { for (IASTNode node : nodes) {
rewrite.insertBefore(compound, null, node, group); rewrite.insertBefore(compound, null, node, group);
} }
} }
@ -48,8 +48,8 @@ public class ExtractStatement extends ExtractedFunctionConstructionHelper {
IASTNode decl = ASTHelper.getDeclarationForNode(returnVariable.getDeclarationName()); IASTNode decl = ASTHelper.getDeclarationForNode(returnVariable.getDeclarationName());
return ASTHelper.getDeclarationSpecifier(decl).copy(CopyStyle.withLocations); return ASTHelper.getDeclarationSpecifier(decl).copy(CopyStyle.withLocations);
} }
IASTDeclSpecifier declSpec = new CPPASTSimpleDeclSpecifier(); IASTSimpleDeclSpecifier declSpec = new CPPASTSimpleDeclSpecifier();
((IASTSimpleDeclSpecifier) declSpec).setType(IASTSimpleDeclSpecifier.t_void); declSpec.setType(IASTSimpleDeclSpecifier.t_void);
return declSpec.copy(CopyStyle.withLocations); return declSpec.copy(CopyStyle.withLocations);
} }

View file

@ -57,10 +57,10 @@ import org.eclipse.cdt.internal.ui.refactoring.Container;
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefactoringStrategy { public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefactoringStrategy {
private IASTTranslationUnit impl_unit; private IASTTranslationUnit implUnit;
private ToggleRefactoringContext context; private ToggleRefactoringContext context;
private TextEditGroup infoText; private TextEditGroup infoText;
private ASTLiteralNode includenode; private ASTLiteralNode includeNode;
public ToggleFromInHeaderToImplementationStrategy(final ToggleRefactoringContext context) { public ToggleFromInHeaderToImplementationStrategy(final ToggleRefactoringContext context) {
this.infoText = new TextEditGroup(Messages.EditGroupName); this.infoText = new TextEditGroup(Messages.EditGroupName);
@ -80,9 +80,9 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
replaceDefinitionWithDeclaration(collector); replaceDefinitionWithDeclaration(collector);
} }
ASTRewrite implRewrite = collector.rewriterForTranslationUnit(impl_unit); ASTRewrite implRewrite = collector.rewriterForTranslationUnit(implUnit);
if (includenode != null) { if (includeNode != null) {
implRewrite.insertBefore(impl_unit, null, includenode, infoText); implRewrite.insertBefore(implUnit, null, includeNode, infoText);
} }
IASTNode insertionParent = null; IASTNode insertionParent = null;
@ -93,11 +93,11 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
insertionParent = searchNamespaceInImplementation(parent.getName()); insertionParent = searchNamespaceInImplementation(parent.getName());
if (insertionParent == null) { if (insertionParent == null) {
insertionParent = createNamespace(parent); insertionParent = createNamespace(parent);
implRewrite = implRewrite.insertBefore(impl_unit.getTranslationUnit(), implRewrite = implRewrite.insertBefore(implUnit.getTranslationUnit(),
null, insertionParent, infoText); null, insertionParent, infoText);
} }
} else { } else {
insertionParent = impl_unit.getTranslationUnit(); insertionParent = implUnit.getTranslationUnit();
} }
newDefinition.setParent(insertionParent); newDefinition.setParent(insertionParent);
@ -241,13 +241,13 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
} }
private boolean newFileCheck() { private boolean newFileCheck() {
impl_unit = context.getTUForSiblingFile(); implUnit = context.getTUForSiblingFile();
if (impl_unit == null) { if (implUnit == null) {
ToggleFileCreator filecreator = new ToggleFileCreator(context, ".cpp"); //$NON-NLS-1$ ToggleFileCreator filecreator = new ToggleFileCreator(context, ".cpp"); //$NON-NLS-1$
if (filecreator.askUserForFileCreation(context)) { if (filecreator.askUserForFileCreation(context)) {
filecreator.createNewFile(); filecreator.createNewFile();
impl_unit = filecreator.loadTranslationUnit(); implUnit = filecreator.loadTranslationUnit();
includenode = new ASTLiteralNode(filecreator.getIncludeStatement()); includeNode = new ASTLiteralNode(filecreator.getIncludeStatement());
return true; return true;
} else { } else {
return false; return false;
@ -342,7 +342,7 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
private CPPASTNamespaceDefinition createNamespace(ICPPASTNamespaceDefinition parent_namespace) { private CPPASTNamespaceDefinition createNamespace(ICPPASTNamespaceDefinition parent_namespace) {
CPPASTNamespaceDefinition insertionParent = new CPPASTNamespaceDefinition( CPPASTNamespaceDefinition insertionParent = new CPPASTNamespaceDefinition(
parent_namespace.getName().copy(CopyStyle.withLocations)); parent_namespace.getName().copy(CopyStyle.withLocations));
insertionParent.setParent(impl_unit); insertionParent.setParent(implUnit);
return insertionParent; return insertionParent;
} }
@ -354,7 +354,7 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
private IASTNode searchNamespaceInImplementation(final IASTName name) { private IASTNode searchNamespaceInImplementation(final IASTName name) {
final Container<IASTNode> result = new Container<IASTNode>(); final Container<IASTNode> result = new Container<IASTNode>();
this.impl_unit.accept(new ASTVisitor() { this.implUnit.accept(new ASTVisitor() {
{ {
shouldVisitNamespaces = true; shouldVisitNamespaces = true;
} }

View file

@ -32,12 +32,11 @@ import org.eclipse.cdt.ui.CUIPlugin;
* @since 5.0 * @since 5.0
*/ */
public final class ProjectTemplateStore { public final class ProjectTemplateStore {
private static final String KEY= "org.eclipse.cdt.ui.text.custom_code_templates"; //$NON-NLS-1$ private static final String KEY= "org.eclipse.cdt.ui.text.custom_code_templates"; //$NON-NLS-1$
private final TemplateStore fInstanceStore; private final TemplateStore fInstanceStore;
private final TemplateStore fProjectStore; private final TemplateStore fProjectStore;
public ProjectTemplateStore(IProject project) { public ProjectTemplateStore(IProject project) {
fInstanceStore= CUIPlugin.getDefault().getCodeTemplateStore(); fInstanceStore= CUIPlugin.getDefault().getCodeTemplateStore();
if (project == null) { if (project == null) {
@ -57,21 +56,20 @@ public final class ProjectTemplateStore {
internalAdd(data); internalAdd(data);
} }
} }
@Override @Override
public void save() throws IOException { public void save() throws IOException {
StringWriter output= new StringWriter(); StringWriter output= new StringWriter();
TemplateReaderWriter writer= new TemplateReaderWriter(); TemplateReaderWriter writer= new TemplateReaderWriter();
writer.save(getTemplateData(false), output); writer.save(getTemplateData(false), output);
projectSettings.setValue(KEY, output.toString()); projectSettings.setValue(KEY, output.toString());
projectSettings.save(); projectSettings.save();
} }
}; };
} }
} }
public static boolean hasProjectSpecificTempates(IProject project) { public static boolean hasProjectSpecificTempates(IProject project) {
String pref= new ProjectScope(project).getNode(CUIPlugin.PLUGIN_ID).get(KEY, null); String pref= new ProjectScope(project).getNode(CUIPlugin.PLUGIN_ID).get(KEY, null);
if (pref != null && pref.trim().length() > 0) { if (pref != null && pref.trim().length() > 0) {
@ -87,29 +85,28 @@ public final class ProjectTemplateStore {
} }
return false; return false;
} }
public TemplatePersistenceData[] getTemplateData() { public TemplatePersistenceData[] getTemplateData() {
if (fProjectStore != null) { if (fProjectStore != null) {
return fProjectStore.getTemplateData(true); return fProjectStore.getTemplateData(true);
} }
return fInstanceStore.getTemplateData(true); return fInstanceStore.getTemplateData(true);
} }
public Template findTemplateById(String id) { public Template findTemplateById(String id) {
Template template= null; Template template= null;
if (fProjectStore != null) if (fProjectStore != null)
template= fProjectStore.findTemplateById(id); template= fProjectStore.findTemplateById(id);
if (template == null) if (template == null)
template= fInstanceStore.findTemplateById(id); template= fInstanceStore.findTemplateById(id);
return template; return template;
} }
public void load() throws IOException { public void load() throws IOException {
if (fProjectStore != null) { if (fProjectStore != null) {
fProjectStore.load(); fProjectStore.load();
Set<String> datas= new HashSet<String>(); Set<String> datas= new HashSet<String>();
TemplatePersistenceData[] data= fProjectStore.getTemplateData(false); TemplatePersistenceData[] data= fProjectStore.getTemplateData(false);
for (TemplatePersistenceData element : data) { for (TemplatePersistenceData element : data) {
@ -119,7 +116,7 @@ public final class ProjectTemplateStore {
} }
datas.add(id); datas.add(id);
} }
data= fInstanceStore.getTemplateData(false); data= fInstanceStore.getTemplateData(false);
for (TemplatePersistenceData orig : data) { for (TemplatePersistenceData orig : data) {
String origId= orig.getId(); String origId= orig.getId();
@ -134,22 +131,21 @@ public final class ProjectTemplateStore {
} }
} }
} }
public boolean isProjectSpecific(String id) { public boolean isProjectSpecific(String id) {
if (id == null) { if (id == null) {
return false; return false;
} }
if (fProjectStore == null) if (fProjectStore == null)
return false; return false;
return fProjectStore.findTemplateById(id) != null; return fProjectStore.findTemplateById(id) != null;
} }
public void setProjectSpecific(String id, boolean projectSpecific) { public void setProjectSpecific(String id, boolean projectSpecific) {
Assert.isNotNull(fProjectStore); Assert.isNotNull(fProjectStore);
TemplatePersistenceData data= fProjectStore.getTemplateData(id); TemplatePersistenceData data= fProjectStore.getTemplateData(id);
if (data == null) { if (data == null) {
return; // does not exist return; // does not exist
@ -164,7 +160,7 @@ public final class ProjectTemplateStore {
fProjectStore.restoreDefaults(); fProjectStore.restoreDefaults();
} }
} }
public void save() throws IOException { public void save() throws IOException {
if (fProjectStore == null) { if (fProjectStore == null) {
fInstanceStore.save(); fInstanceStore.save();
@ -172,7 +168,7 @@ public final class ProjectTemplateStore {
fProjectStore.save(); fProjectStore.save();
} }
} }
public void revertChanges() throws IOException { public void revertChanges() throws IOException {
if (fProjectStore != null) { if (fProjectStore != null) {
// nothing to do // nothing to do