mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Bug 416317 - Toggle refactoring creates .cpp file when in a C project
Change-Id: I60f4d4def8f5f2a52c3bc07979d317ec4f6d2d06 Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Reviewed-on: https://git.eclipse.org/r/16089 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
1c122ce5af
commit
67aac2386d
3 changed files with 91 additions and 22 deletions
|
@ -0,0 +1,80 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008, 2013 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
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
|
* Marc-Andre Laperle (Ericsson)
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.refactoring.togglefunction;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||||
|
import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleRefactoring;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for ToggleRefactoring for C projects.
|
||||||
|
*/
|
||||||
|
public class ToggleRefactoringCTest extends RefactoringTestBase {
|
||||||
|
private ToggleRefactoring refactoring;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
createEmptyFiles = false;
|
||||||
|
setCpp(false);
|
||||||
|
super.setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CRefactoring createRefactoring() {
|
||||||
|
refactoring = new ToggleRefactoring(getSelectedTranslationUnit(), getSelection(), getCProject());
|
||||||
|
return refactoring;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void simulateUserInput() {
|
||||||
|
refactoring.getContext().setSettedDefaultAnswer(true);
|
||||||
|
refactoring.getContext().setDefaultAnswer(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.h
|
||||||
|
//void /*$*/freefunction/*$$*/() {
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//void freefunction();
|
||||||
|
|
||||||
|
//A.c
|
||||||
|
//====================
|
||||||
|
//#include "A.h"
|
||||||
|
//
|
||||||
|
//void freefunction() {
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
public void testFileFromHeaderToImpl() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//A.c
|
||||||
|
//#include "A.h"
|
||||||
|
//
|
||||||
|
//void /*$*/test/*$$*/() {
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//#include "A.h"
|
||||||
|
|
||||||
|
//A.h
|
||||||
|
//void test();
|
||||||
|
//====================
|
||||||
|
//void test() {
|
||||||
|
//}
|
||||||
|
public void testToggleCFunction() throws Exception {
|
||||||
|
assertRefactoringSuccess();
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleRefactoring;
|
import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleRefactoring;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for Generate Getters and Setters refactoring.
|
* Tests for ToggleRefactoring for C++ projects.
|
||||||
*/
|
*/
|
||||||
public class ToggleRefactoringTest extends RefactoringTestBase {
|
public class ToggleRefactoringTest extends RefactoringTestBase {
|
||||||
private ToggleRefactoring refactoring;
|
private ToggleRefactoring refactoring;
|
||||||
|
@ -37,6 +37,7 @@ public class ToggleRefactoringTest extends RefactoringTestBase {
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
TestSuite suite = suite(ToggleRefactoringTest.class);
|
TestSuite suite = suite(ToggleRefactoringTest.class);
|
||||||
|
suite.addTestSuite(ToggleRefactoringCTest.class);
|
||||||
suite.addTestSuite(ToggleNodeHelperTest.class);
|
suite.addTestSuite(ToggleNodeHelperTest.class);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
@ -2862,21 +2863,4 @@ public class ToggleRefactoringTest extends RefactoringTestBase {
|
||||||
public void testImplToHeaderTopCommentWithoutDeclaration() throws Exception {
|
public void testImplToHeaderTopCommentWithoutDeclaration() throws Exception {
|
||||||
assertRefactoringSuccess();
|
assertRefactoringSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
//A.c
|
|
||||||
//#include "A.h"
|
|
||||||
//
|
|
||||||
//void /*$*/test/*$$*/() {
|
|
||||||
//}
|
|
||||||
//====================
|
|
||||||
//#include "A.h"
|
|
||||||
|
|
||||||
//A.h
|
|
||||||
//void test();
|
|
||||||
//====================
|
|
||||||
//void test() {
|
|
||||||
//}
|
|
||||||
public void testToggleCFunction() throws Exception {
|
|
||||||
assertRefactoringSuccess();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2011, 2012 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2011, 2013 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others.
|
* Rapperswil, University of applied sciences 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
|
||||||
|
@ -7,17 +7,20 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
||||||
* Sergey Prigogin (Google)
|
* Sergey Prigogin (Google)
|
||||||
|
* Marc-Andre Laperle (Ericsson)
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.text.edits.TextEditGroup;
|
import org.eclipse.text.edits.TextEditGroup;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCProjectNature;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||||
|
@ -247,7 +250,9 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
|
||||||
private boolean newFileCheck() throws CoreException {
|
private boolean newFileCheck() throws CoreException {
|
||||||
implAst = context.getASTForPartnerFile();
|
implAst = context.getASTForPartnerFile();
|
||||||
if (implAst == null) {
|
if (implAst == null) {
|
||||||
ToggleFileCreator fileCreator = new ToggleFileCreator(context, ".cpp"); //$NON-NLS-1$
|
IProject project = context.getSelectionTU().getCProject().getProject();
|
||||||
|
boolean isCC = project.hasNature(CCProjectNature.CC_NATURE_ID);
|
||||||
|
ToggleFileCreator fileCreator = new ToggleFileCreator(context, isCC ? ".cpp" : ".c"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
if (fileCreator.askUserForFileCreation(context)) {
|
if (fileCreator.askUserForFileCreation(context)) {
|
||||||
IFile file = fileCreator.createNewFile();
|
IFile file = fileCreator.createNewFile();
|
||||||
implAst = context.getAST(file, null);
|
implAst = context.getAST(file, null);
|
||||||
|
|
Loading…
Add table
Reference in a new issue