1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-09 18:15:23 +02:00

Bug 414827 - ClassCastExceptions in ToggleNodeHelper using C file

Change-Id: Ia98176f3a532432a02758c23cc515566d83b3efd
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/15325
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Marc-Andre Laperle 2013-08-11 11:00:19 -04:00 committed by Marc-Andre Laperle
parent a2a965e83e
commit 3ed44ffc55
2 changed files with 27 additions and 8 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 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
@ -9,6 +9,7 @@
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.togglefunction; package org.eclipse.cdt.ui.tests.refactoring.togglefunction;
@ -2861,4 +2862,21 @@ 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();
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2011 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
@ -8,6 +8,7 @@
* *
* Contributors: * Contributors:
* Martin Schwab & Thomas Kallenberg - initial API and implementation * Martin Schwab & Thomas Kallenberg - initial API and implementation
* Marc-Andre Laperle (Ericsson)
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.togglefunction; package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
@ -180,11 +181,11 @@ public class ToggleNodeHelper extends NodeHelper {
static IASTFunctionDefinition createInClassDefinition(IASTFunctionDeclarator dec, static IASTFunctionDefinition createInClassDefinition(IASTFunctionDeclarator dec,
IASTFunctionDefinition def, IASTTranslationUnit insertionAst) { IASTFunctionDefinition def, IASTTranslationUnit insertionAst) {
IASTFunctionDeclarator declarator = dec.copy(CopyStyle.withLocations); IASTFunctionDeclarator declarator = dec.copy(CopyStyle.withLocations);
ICPPASTDeclSpecifier declSpec = IASTDeclSpecifier declSpec =
(ICPPASTDeclSpecifier) def.getDeclSpecifier().copy(CopyStyle.withLocations); def.getDeclSpecifier().copy(CopyStyle.withLocations);
declSpec.setInline(false); declSpec.setInline(false);
if (ToggleNodeHelper.isVirtual(dec)) { if (declSpec instanceof ICPPASTDeclSpecifier && ToggleNodeHelper.isVirtual(dec)) {
declSpec.setVirtual(true); ((ICPPASTDeclSpecifier) declSpec).setVirtual(true);
} }
declSpec.setStorageClass(getStorageClass(dec)); declSpec.setStorageClass(getStorageClass(dec));
@ -202,7 +203,7 @@ public class ToggleNodeHelper extends NodeHelper {
static int getStorageClass(IASTFunctionDeclarator fdec) { static int getStorageClass(IASTFunctionDeclarator fdec) {
if (fdec.getParent() instanceof IASTSimpleDeclaration) { if (fdec.getParent() instanceof IASTSimpleDeclaration) {
IASTSimpleDeclaration dec = (IASTSimpleDeclaration) fdec.getParent(); IASTSimpleDeclaration dec = (IASTSimpleDeclaration) fdec.getParent();
return ((ICPPASTDeclSpecifier) dec.getDeclSpecifier()).getStorageClass(); return dec.getDeclSpecifier().getStorageClass();
} }
return -1; return -1;
} }