mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06: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:
parent
7bbba2e9ec
commit
6f00ced625
5 changed files with 31 additions and 15 deletions
|
@ -26,6 +26,7 @@ import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor;
|
import org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||||
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
|
@ -184,6 +185,7 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
}
|
}
|
||||||
if(!loadTranslationUnit(initStatus, sm.newChild(8))){
|
if(!loadTranslationUnit(initStatus, sm.newChild(8))){
|
||||||
initStatus.addError(Messages.Refactoring_CantLoadTU);
|
initStatus.addError(Messages.Refactoring_CantLoadTU);
|
||||||
|
return initStatus;
|
||||||
}
|
}
|
||||||
if(isProgressMonitorCanceld(sm, initStatus)) {
|
if(isProgressMonitorCanceld(sm, initStatus)) {
|
||||||
return initStatus;
|
return initStatus;
|
||||||
|
@ -234,6 +236,10 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
try {
|
try {
|
||||||
subMonitor.subTask(Messages.Refactoring_PM_ParseTU);
|
subMonitor.subTask(Messages.Refactoring_PM_ParseTU);
|
||||||
unit = loadTranslationUnit(file);
|
unit = loadTranslationUnit(file);
|
||||||
|
if(unit == null) {
|
||||||
|
subMonitor.done();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
subMonitor.worked(2);
|
subMonitor.worked(2);
|
||||||
if(isProgressMonitorCanceld(subMonitor, initStatus)) {
|
if(isProgressMonitorCanceld(subMonitor, initStatus)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -258,6 +264,10 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
|
|
||||||
protected IASTTranslationUnit loadTranslationUnit(IFile file) throws CoreException {
|
protected IASTTranslationUnit loadTranslationUnit(IFile file) throws CoreException {
|
||||||
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(file);
|
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);
|
return tu.getAST(fIndex, AST_STYLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
* 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
|
||||||
|
@ -35,6 +35,7 @@ public final class Messages extends NLS {
|
||||||
public static String CreateFileChange_CreateFile;
|
public static String CreateFileChange_CreateFile;
|
||||||
public static String CreateFileChange_UnknownLoc;
|
public static String CreateFileChange_UnknownLoc;
|
||||||
public static String CreateFileChange_FileExists;
|
public static String CreateFileChange_FileExists;
|
||||||
|
public static String CRefactoring_FileNotFound;
|
||||||
public static String Refactoring_SelectionNotValid;
|
public static String Refactoring_SelectionNotValid;
|
||||||
public static String Refactoring_CantLoadTU;
|
public static String Refactoring_CantLoadTU;
|
||||||
public static String Refactoring_Ambiguity;
|
public static String Refactoring_Ambiguity;
|
||||||
|
|
|
@ -93,12 +93,14 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
||||||
|
|
||||||
super.checkInitialConditions(sm.newChild(6));
|
super.checkInitialConditions(sm.newChild(6));
|
||||||
|
|
||||||
|
if(!initStatus.hasFatalError()) {
|
||||||
|
|
||||||
initRefactoring(pm);
|
initRefactoring(pm);
|
||||||
|
|
||||||
if(context.existingFields.size() == 0) {
|
if(context.existingFields.size() == 0) {
|
||||||
initStatus.addFatalError(Messages.GenerateGettersAndSettersRefactoring_NoFields);
|
initStatus.addFatalError(Messages.GenerateGettersAndSettersRefactoring_NoFields);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return initStatus;
|
return initStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,8 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
||||||
SubMonitor sm = SubMonitor.convert(pm, 10);
|
SubMonitor sm = SubMonitor.convert(pm, 10);
|
||||||
super.checkInitialConditions(sm.newChild(6));
|
super.checkInitialConditions(sm.newChild(6));
|
||||||
|
|
||||||
|
if(!initStatus.hasFatalError()) {
|
||||||
|
|
||||||
data.setMethodDeclarations(findUnimplementedMethodDeclarations(unit));
|
data.setMethodDeclarations(findUnimplementedMethodDeclarations(unit));
|
||||||
|
|
||||||
if(region.getLength()>0) {
|
if(region.getLength()>0) {
|
||||||
|
@ -90,7 +92,7 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sm.done();
|
sm.done();
|
||||||
return initStatus;
|
return initStatus;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ AddDeclarationNodeToClassChange_AddDeclaration=Add Declaration to Class {0}.
|
||||||
CreateFileChange_CreateFile=Create file: {0}
|
CreateFileChange_CreateFile=Create file: {0}
|
||||||
CreateFileChange_UnknownLoc=Unknown Location: {0}
|
CreateFileChange_UnknownLoc=Unknown Location: {0}
|
||||||
CreateFileChange_FileExists=File already exists: {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_SelectionNotValid=Selection is not valid.
|
||||||
Refactoring_CantLoadTU=Can not load translation unit.
|
Refactoring_CantLoadTU=Can not load translation unit.
|
||||||
Refactoring_Ambiguity=Translation unit is ambiguous.
|
Refactoring_Ambiguity=Translation unit is ambiguous.
|
||||||
|
|
Loading…
Add table
Reference in a new issue