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

FIXED - bug 284973: "Internal Error" while using "Source -> Generate getters/setters"

https://bugs.eclipse.org/bugs/show_bug.cgi?id=284973
This commit is contained in:
Emanuel Graf 2009-08-18 08:43:42 +00:00
parent 7bbba2e9ec
commit 6f00ced625
5 changed files with 31 additions and 15 deletions

View file

@ -26,6 +26,7 @@ import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.osgi.util.NLS;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@ -184,6 +185,7 @@ public abstract class CRefactoring extends Refactoring {
}
if(!loadTranslationUnit(initStatus, sm.newChild(8))){
initStatus.addError(Messages.Refactoring_CantLoadTU);
return initStatus;
}
if(isProgressMonitorCanceld(sm, initStatus)) {
return initStatus;
@ -234,6 +236,10 @@ public abstract class CRefactoring extends Refactoring {
try {
subMonitor.subTask(Messages.Refactoring_PM_ParseTU);
unit = loadTranslationUnit(file);
if(unit == null) {
subMonitor.done();
return false;
}
subMonitor.worked(2);
if(isProgressMonitorCanceld(subMonitor, initStatus)) {
return true;
@ -258,6 +264,10 @@ public abstract class CRefactoring extends Refactoring {
protected IASTTranslationUnit loadTranslationUnit(IFile file) throws CoreException {
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(file);
if(tu == null){
initStatus.addFatalError(NLS.bind(Messages.CRefactoring_FileNotFound, file.getName()));
return null;
}
return tu.getAST(fIndex, AST_STYLE);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008, 2009 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
@ -35,6 +35,7 @@ public final class Messages extends NLS {
public static String CreateFileChange_CreateFile;
public static String CreateFileChange_UnknownLoc;
public static String CreateFileChange_FileExists;
public static String CRefactoring_FileNotFound;
public static String Refactoring_SelectionNotValid;
public static String Refactoring_CantLoadTU;
public static String Refactoring_Ambiguity;

View file

@ -93,12 +93,14 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
super.checkInitialConditions(sm.newChild(6));
initRefactoring(pm);
if(context.existingFields.size() == 0) {
initStatus.addFatalError(Messages.GenerateGettersAndSettersRefactoring_NoFields);
}
if(!initStatus.hasFatalError()) {
initRefactoring(pm);
if(context.existingFields.size() == 0) {
initStatus.addFatalError(Messages.GenerateGettersAndSettersRefactoring_NoFields);
}
}
return initStatus;
}

View file

@ -78,19 +78,21 @@ public class ImplementMethodRefactoring extends CRefactoring {
SubMonitor sm = SubMonitor.convert(pm, 10);
super.checkInitialConditions(sm.newChild(6));
data.setMethodDeclarations(findUnimplementedMethodDeclarations(unit));
if(!initStatus.hasFatalError()) {
if(region.getLength()>0) {
IASTSimpleDeclaration methodDeclaration = SelectionHelper.findFirstSelectedDeclaration(region, unit);
if (NodeHelper.isMethodDeclaration(methodDeclaration)) {
for (MethodToImplementConfig config : data.getMethodDeclarations()) {
if(config.getDeclaration() == methodDeclaration) {
config.setChecked(true);
data.setMethodDeclarations(findUnimplementedMethodDeclarations(unit));
if(region.getLength()>0) {
IASTSimpleDeclaration methodDeclaration = SelectionHelper.findFirstSelectedDeclaration(region, unit);
if (NodeHelper.isMethodDeclaration(methodDeclaration)) {
for (MethodToImplementConfig config : data.getMethodDeclarations()) {
if(config.getDeclaration() == methodDeclaration) {
config.setChecked(true);
}
}
}
}
}
sm.done();
return initStatus;
}

View file

@ -23,6 +23,7 @@ AddDeclarationNodeToClassChange_AddDeclaration=Add Declaration to Class {0}.
CreateFileChange_CreateFile=Create file: {0}
CreateFileChange_UnknownLoc=Unknown Location: {0}
CreateFileChange_FileExists=File already exists: {0}
CRefactoring_FileNotFound=File {0} not found in the Project Source Path.
Refactoring_SelectionNotValid=Selection is not valid.
Refactoring_CantLoadTU=Can not load translation unit.
Refactoring_Ambiguity=Translation unit is ambiguous.