1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-04-04 11:11:57 -07:00
parent ffc583c84d
commit 710e358931
10 changed files with 90 additions and 93 deletions

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
@ -51,7 +51,7 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
@Override
public void runTest() throws Exception {
final ASTModificationStore modStore = new ASTModificationStore();
IFile testFile = importFile("source.h", source); //$NON-NLS-1$
IFile testFile = importFile("source.h", source); //$NON-NLS-1$
ASTVisitor visitor = createModificator(modStore);
@ -63,15 +63,15 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
assertTrue("The indexing operation of the test CProject has not finished jet. This should not happen...", joined);
IASTTranslationUnit unit = CoreModelUtil.findTranslationUnit(testFile).getAST();
final ChangeGenerator changeGenerator = new ChangeGenerator(modStore,
ASTCommenter.getCommentedNodeMap(unit));
final ChangeGenerator changeGenerator =
new ChangeGenerator(modStore, ASTCommenter.getCommentedNodeMap(unit));
unit.accept(visitor);
changeGenerator.generateChange(unit);
Document doc = new Document(source);
for (Change curChange : ((CompositeChange) changeGenerator.getChange()).getChildren()) {
if (curChange instanceof TextFileChange) {
TextFileChange textChange = (TextFileChange) curChange;
for (Change change : ((CompositeChange) changeGenerator.getChange()).getChildren()) {
if (change instanceof TextFileChange) {
TextFileChange textChange = (TextFileChange) change;
textChange.getEdit().apply(doc);
}
}

View file

@ -1,13 +1,13 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software (IFS)- initial API and implementation
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software (IFS)- initial API and implementation
******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
@ -41,7 +41,7 @@ public class AddDeclarationBug extends ChangeGeneratorTest {
super("AddDeclarationBug");
}
public static Test suite() {
public static Test suite() {
return new AddDeclarationBug();
}
@ -64,11 +64,11 @@ public class AddDeclarationBug extends ChangeGeneratorTest {
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
ICPPASTCompositeTypeSpecifier classNode = (ICPPASTCompositeTypeSpecifier) declSpec;
IASTSimpleDeclaration newDecl = new CPPASTSimpleDeclaration();
IASTSimpleDeclSpecifier returnTyp = new CPPASTSimpleDeclSpecifier();
returnTyp.setType(IASTSimpleDeclSpecifier.t_int);
newDecl.setDeclSpecifier(returnTyp);
IASTStandardFunctionDeclarator declarator = new CPPASTFunctionDeclarator(
new CPPASTName("exp".toCharArray())); //$NON-NLS-1$
IASTSimpleDeclSpecifier paramTyp = new CPPASTSimpleDeclSpecifier();
@ -77,7 +77,7 @@ public class AddDeclarationBug extends ChangeGeneratorTest {
ICPPASTParameterDeclaration param = new CPPASTParameterDeclaration(paramTyp, decl);
declarator.addParameterDeclaration(param);
newDecl.addDeclarator(declarator);
ASTModification mod = new ASTModification(ModificationKind.APPEND_CHILD, classNode,
newDecl, null);
modStore.storeModification(null, mod);

View file

@ -1,26 +1,26 @@
/*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class ArrayModifierTest extends ChangeGeneratorTest {
@ -40,18 +40,17 @@ public class ArrayModifierTest extends ChangeGeneratorTest {
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitDeclarators = true;
}
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof IASTArrayDeclarator) {
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
ASTModification modification = new ASTModification(ModificationKind.REPLACE, modifiers[0], null, null);
modStore.storeModification(null, modification);

View file

@ -1,29 +1,29 @@
/*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class ArrayModifierTest extends ChangeGeneratorTest {
@ -42,22 +42,20 @@ public class ArrayModifierTest extends ChangeGeneratorTest {
return new ArrayModifierTest();
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitDeclarators = true;
}
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof IASTArrayDeclarator) {
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
IASTArrayModifier newModifier = new CPPASTArrayModifier();
IASTExpression expr = new CPPASTLiteralExpression(0, "15"); //$NON-NLS-1$
IASTExpression expr = new CPPASTLiteralExpression(0, "15".toCharArray()); //$NON-NLS-1$
newModifier.setConstantExpression(expr);
ASTModification modification = new ASTModification(ModificationKind.REPLACE, modifiers[0], newModifier, null);
modStore.storeModification(null, modification);

View file

@ -7,7 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
*******************************************************************************/
package org.eclipse.cdt.core.dom.rewrite;
import java.util.List;
@ -42,14 +42,14 @@ import org.eclipse.text.edits.TextEditGroup;
* progress. There is no guarantee that this API will work or that it will remain the same.
* Please do not use this API without consulting with the CDT team.
* </p>
*
*
* @since 5.0
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public final class ASTRewrite {
/**
* Defines the positions of the comment.
*
*
* @since 5.3
*/
public enum CommentPosition {
@ -67,7 +67,7 @@ public final class ASTRewrite {
*/
freestanding
}
/**
* Creates a rewriter for a translation unit.
*/
@ -80,7 +80,7 @@ public final class ASTRewrite {
private final ASTModificationStore fModificationStore;
private final ASTModification fParentMod;
private final NodeCommentMap fCommentMap;
private enum Operation {
insertBefore,
replace,
@ -99,8 +99,8 @@ public final class ASTRewrite {
* Creates and returns a node for a source string that is to be inserted into
* the output document.
* The string will be inserted without being reformatted beyond correcting
* the indentation level.
*
* the indentation level.
*
* @param code the string to be inserted; lines should not have extra indentation
* @return a synthetic node representing the literal code.
* @throws IllegalArgumentException if the code is null.
@ -115,7 +115,7 @@ public final class ASTRewrite {
*
* @param node the node being removed
* @param editGroup the edit group in which to collect the corresponding
* text edits, or <code>null</code>
* text edits, or <code>null</code>
* @throws IllegalArgumentException if the node is null, the node is not
* part of this rewriter's AST.
*/
@ -129,13 +129,13 @@ public final class ASTRewrite {
/**
* Replaces the given node in this rewriter. The ast is not modified, the rewriter
* just records the replacement.
* The replacement node can be part of a translation-unit or it is a synthetic
* The replacement node can be part of a translation-unit or it is a synthetic
* (newly created) node.
*
* @param node the node being replaced
* @param replacement the node replacing the given one
* @param editGroup the edit group in which to collect the corresponding text edits,
* or <code>null</code>
* or <code>null</code>
* @return a rewriter for further rewriting the replacement node.
* @throws IllegalArgumentException if the node or the replacement is null, or if the node is
* not part of this rewriter's AST
@ -155,14 +155,14 @@ public final class ASTRewrite {
/**
* Inserts the given node in this rewriter. The ast is not modified, the rewriter
* just records the insertion.
* The new node can be part of a translation-unit or it is a synthetic
* The new node can be part of a translation-unit or it is a synthetic
* (newly created) node.
* @param parent the parent the new node is added to.
* @param insertionPoint the node before which the insertion shall be done, or <code>null</code>
* for inserting after the last child.
* @param newNode the node being inserted
* @param newNode the node being inserted
* @param editGroup the edit group in which to collect the corresponding
* text edits, or <code>null</code>
* text edits, or <code>null</code>
* @return a rewriter for further rewriting the inserted node.
* @throws IllegalArgumentException if the parent or the newNode is null, or if the parent is
* not part of this rewriter's AST, or the insertionPoint is not a child of the parent.
@ -191,17 +191,17 @@ public final class ASTRewrite {
fModificationStore.storeModification(fParentMod, mod);
return new ASTRewrite(newNode, fModificationStore, mod, fCommentMap);
}
/**
* Converts all modifications recorded by this rewriter into the change object required by
* the refactoring framework.
* <p>
* Calling this methods does not discard the modifications on record. Subsequence modifications
* Calling this methods does not discard the modifications on record. Subsequence modifications
* are added to the ones already on record. If this method is called again later,
* the resulting text edit object will accurately reflect the net cumulative affect of all those
* changes.
* </p>
*
*
* @return Change object describing the changes to the document corresponding to the changes
* recorded by this rewriter
* @since 5.0
@ -210,7 +210,8 @@ public final class ASTRewrite {
if (!(fRoot instanceof IASTTranslationUnit)) {
throw new IllegalArgumentException("This API can only be used for the root rewrite object."); //$NON-NLS-1$
}
return ASTRewriteAnalyzer.rewriteAST((IASTTranslationUnit) fRoot, fModificationStore, fCommentMap);
return ASTRewriteAnalyzer.rewriteAST((IASTTranslationUnit) fRoot, fModificationStore,
fCommentMap);
}
private void checkBelongsToAST(IASTNode node) {
@ -222,7 +223,7 @@ public final class ASTRewrite {
}
throw new IllegalArgumentException();
}
private void checkSupportedNode(IASTNode node, Operation op) {
if (node instanceof IASTComment) {
if (op != Operation.remove) {
@ -234,12 +235,12 @@ public final class ASTRewrite {
}
if (node instanceof IASTProblem) {
throw new IllegalArgumentException("Rewriting problem nodes is not supported"); //$NON-NLS-1$
}
}
}
/**
* Assigns the comment to the node.
*
*
* @param node the node.
* @param comment the comment to be attached to the node at the given position.
* @param pos the position of the comment.
@ -261,7 +262,7 @@ public final class ASTRewrite {
/**
* Returns comments for the given node.
*
*
* @param node the node
* @param pos the position of the comments
* @return All comments assigned to the node at this position

View file

@ -27,8 +27,8 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
public class CPPASTWhileStatement extends ASTNode
implements ICPPASTWhileStatement, IASTAmbiguityParent {
private IASTExpression condition;
private IASTStatement body;
private IASTDeclaration condition2;
private IASTStatement body;
private IScope scope;
public CPPASTWhileStatement() {

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -20,7 +20,8 @@ import org.eclipse.ltk.core.refactoring.TextFileChange;
public class ASTRewriteAnalyzer {
private static ICTextFileChangeFactory sFileChangeFactory;
public static Change rewriteAST(IASTTranslationUnit root, ASTModificationStore modificationStore, NodeCommentMap commentMap) {
public static Change rewriteAST(IASTTranslationUnit root, ASTModificationStore modificationStore,
NodeCommentMap commentMap) {
ChangeGenerator rewriter = new ChangeGenerator(modificationStore, commentMap);
rewriter.generateChange(root);
return rewriter.getChange();
@ -29,7 +30,7 @@ public class ASTRewriteAnalyzer {
public static void setCTextFileChangeFactory(ICTextFileChangeFactory factory) {
sFileChangeFactory= factory;
}
public static TextFileChange createCTextFileChange(IFile file) {
if (sFileChangeFactory == null) {
return new TextFileChange(file.getName(), file);

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
@ -333,7 +333,6 @@ public class ExtractLocalVariableRefactoringTest extends RefactoringTestBase {
}
//A.cpp
//
//template<class T>
//class Foo {
//};
@ -345,7 +344,6 @@ public class ExtractLocalVariableRefactoringTest extends RefactoringTestBase {
// return 0;
//}
//====================
//
//template<class T>
//class Foo {
//};

View file

@ -643,8 +643,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
insertion = new InsertionInfo(parent, functionToExtractFrom);
}
if (insertion.getPrologue() != null) {
rewrite.insertBefore(insertion.getParentNode(),
insertion.getInsertBeforeNode(), insertion.getPrologue(), group);
rewrite.insertBefore(insertion.getParentNode(), insertion.getInsertBeforeNode(),
insertion.getPrologue(), group);
}
subRewrite = rewrite.insertBefore(insertion.getParentNode(),
insertion.getInsertBeforeNode(), nodeToInsert, group);

View file

@ -120,9 +120,9 @@ public class ToggleFromImplementationToHeaderOrClassStrategy implements IToggleR
ICPPASTCompositeTypeSpecifier.class);
IASTNode parentnode = null;
if (parent != null) {
parentnode = parent;
parentnode = parent;
} else {
parentnode =context.getDeclarationAST();
parentnode = context.getDeclarationAST();
}
return parentnode;
}