1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2010-09-21 01:45:17 +00:00
parent d1ee0b132a
commit 45f057367a
8 changed files with 244 additions and 269 deletions

View file

@ -1,15 +1,15 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others. * Copyright (c) 2007 Intel Corporation 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
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Intel Corporation - Initial API and implementation * Intel Corporation - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.settings.model; package org.eclipse.cdt.core.settings.model;
public interface ICFileDescription extends ICResourceDescription{ public interface ICFileDescription extends ICResourceDescription {
ICLanguageSetting getLanguageSetting(); ICLanguageSetting getLanguageSetting();
} }

View file

@ -57,25 +57,24 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
/** /**
* The base class for all other refactorings, provides some common implementations for * The base class for all other refactorings, provides some common implementations for
* condition checking, change generating, selection handling and translation unit loading. * condition checking, change generating, selection handling and translation unit loading.
*
*/ */
public abstract class CRefactoring extends Refactoring { public abstract class CRefactoring extends Refactoring {
private static final int AST_STYLE = ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit.AST_SKIP_INDEXED_HEADERS; private static final int AST_STYLE =
ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
protected String name = Messages.Refactoring_name; protected String name = Messages.Refactoring_name;
protected IFile file; protected IFile file;
protected Region region; protected Region region;
protected RefactoringStatus initStatus; protected RefactoringStatus initStatus;
protected IASTTranslationUnit unit; protected IASTTranslationUnit unit;
private IIndex fIndex;
protected ICProject project; protected ICProject project;
private IIndex fIndex;
public CRefactoring(IFile file, ISelection selection, ICElement element, ICProject proj) { public CRefactoring(IFile file, ISelection selection, ICElement element, ICProject proj) {
project = proj; project = proj;
if (element instanceof ISourceReference) { if (element instanceof ISourceReference) {
ISourceReference sourceRef= (ISourceReference) element; ISourceReference sourceRef= (ISourceReference) element;
ITranslationUnit tu= sourceRef.getTranslationUnit(); ITranslationUnit tu = sourceRef.getTranslationUnit();
IResource res= tu.getResource(); IResource res= tu.getResource();
if (res instanceof IFile) if (res instanceof IFile)
this.file= (IFile) res; this.file= (IFile) res;
@ -91,7 +90,7 @@ public abstract class CRefactoring extends Refactoring {
this.region = SelectionHelper.getRegion(selection); this.region = SelectionHelper.getRegion(selection);
} }
this.initStatus=new RefactoringStatus(); this.initStatus= new RefactoringStatus();
if (this.file == null || region == null) { if (this.file == null || region == null) {
initStatus.addFatalError(Messages.Refactoring_SelectionNotValid); initStatus.addFatalError(Messages.Refactoring_SelectionNotValid);
} }
@ -196,10 +195,9 @@ public abstract class CRefactoring extends Refactoring {
return initStatus; return initStatus;
} }
protected boolean isProgressMonitorCanceld(IProgressMonitor sm, protected static boolean isProgressMonitorCanceld(IProgressMonitor sm, RefactoringStatus status) {
RefactoringStatus initStatus2) {
if (sm.isCanceled()) { if (sm.isCanceled()) {
initStatus2.addFatalError(Messages.Refactoring_CanceledByUser); status.addFatalError(Messages.Refactoring_CanceledByUser);
return true; return true;
} }
return false; return false;
@ -217,15 +215,14 @@ public abstract class CRefactoring extends Refactoring {
abstract protected RefactoringDescriptor getRefactoringDescriptor(); abstract protected RefactoringDescriptor getRefactoringDescriptor();
abstract protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) abstract protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
throws CoreException, OperationCanceledException; throws CoreException, OperationCanceledException;
@Override @Override
public String getName() { public String getName() {
return name; return name;
} }
protected boolean loadTranslationUnit(RefactoringStatus status, protected boolean loadTranslationUnit(RefactoringStatus status, IProgressMonitor mon) {
IProgressMonitor mon) {
SubMonitor subMonitor = SubMonitor.convert(mon, 10); SubMonitor subMonitor = SubMonitor.convert(mon, 10);
if (file != null) { if (file != null) {
try { try {
@ -247,7 +244,6 @@ public abstract class CRefactoring extends Refactoring {
subMonitor.done(); subMonitor.done();
return false; return false;
} }
} else { } else {
status.addFatalError(Messages.NO_FILE); status.addFatalError(Messages.NO_FILE);
subMonitor.done(); subMonitor.done();

View file

@ -53,7 +53,7 @@ public abstract class CRefactoringDescription extends RefactoringDescriptor {
if (selectStrings.length >= 2) { if (selectStrings.length >= 2) {
int offset = Integer.parseInt(selectStrings[0]); int offset = Integer.parseInt(selectStrings[0]);
int length = Integer.parseInt(selectStrings[1]); int length = Integer.parseInt(selectStrings[1]);
selection = new TextSelection(offset,length); selection = new TextSelection(offset, length);
} else { } else {
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Illegal Selection")); //$NON-NLS-1$ throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Illegal Selection")); //$NON-NLS-1$
} }

View file

@ -1,45 +1,43 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2009 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
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring; package org.eclipse.cdt.internal.ui.refactoring;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider; import org.eclipse.jface.window.IShellProvider;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
/** /**
* Base class for all refactoring runners. * Base class for all refactoring runners.
* *
* @author Emanuel Graf * @author Emanuel Graf
* */
*/ public abstract class RefactoringRunner {
public abstract class RefactoringRunner { protected IFile file;
protected ISelection selection;
protected IFile file; protected ICElement celement;
protected ISelection selection; protected IShellProvider shellProvider;
protected ICElement celement; protected ICProject project;
protected IShellProvider shellProvider;
protected ICProject project; public RefactoringRunner(IFile file, ISelection selection, ICElement element,
IShellProvider shellProvider, ICProject cProject) {
public RefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider, ICProject cProject) { this.file = file;
this.file = file; this.selection = selection;
this.selection = selection; this.celement= element;
this.celement= element; this.shellProvider= shellProvider;
this.shellProvider= shellProvider; this.project = cProject;
this.project = cProject; }
}
public abstract void run();
public abstract void run(); }
}

View file

@ -74,15 +74,15 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
* @author Tom Ball * @author Tom Ball
*/ */
public class ExtractLocalVariableRefactoring extends CRefactoring { public class ExtractLocalVariableRefactoring extends CRefactoring {
public static final String ID =
"org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"; //$NON-NLS-1$
public static final String ID = "org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"; //$NON-NLS-1$ private IASTExpression target;
private IASTExpression target = null;
private final NameNVisibilityInformation info; private final NameNVisibilityInformation info;
private NodeContainer container; private NodeContainer container;
public ExtractLocalVariableRefactoring(IFile file, ISelection selection, public ExtractLocalVariableRefactoring(IFile file, ISelection selection, NameNVisibilityInformation info,
NameNVisibilityInformation info, ICProject project) { ICProject project) {
super(file, selection, null, project); super(file, selection, null, project);
this.info = info; this.info = info;
name = Messages.ExtractLocalVariable; name = Messages.ExtractLocalVariable;
@ -90,13 +90,13 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
@Override @Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
throws CoreException, OperationCanceledException { throws CoreException, OperationCanceledException {
SubMonitor sm = SubMonitor.convert(pm, 9); SubMonitor sm = SubMonitor.convert(pm, 9);
try { try {
lockIndex(); lockIndex();
try { try {
RefactoringStatus status = super.checkInitialConditions(sm.newChild(6)); RefactoringStatus status = super.checkInitialConditions(sm.newChild(6));
if(status.hasError()) { if (status.hasError()) {
return status; return status;
} }
@ -110,8 +110,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
if (isProgressMonitorCanceld(sm, initStatus)) if (isProgressMonitorCanceld(sm, initStatus))
return initStatus; return initStatus;
boolean oneMarked = region != null boolean oneMarked = region != null && isOneMarked(container.getNodesToWrite(), region);
&& isOneMarked(container.getNodesToWrite(), region);
if (!oneMarked) { if (!oneMarked) {
if (target == null) { if (target == null) {
initStatus.addFatalError(Messages.NoExpressionSelected); initStatus.addFatalError(Messages.NoExpressionSelected);
@ -132,13 +131,12 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
info.addNamesToUsedNames(findAllDeclaredNames()); info.addNamesToUsedNames(findAllDeclaredNames());
sm.worked(1); sm.worked(1);
NodeHelper.findMethodContext(container.getNodesToWrite().get(0), NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex());
getIndex());
sm.worked(1); sm.worked(1);
info.setName(guessTempName()); info.setName(guessTempName());
sm.done(); sm.done();
}finally { } finally {
unlockIndex(); unlockIndex();
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -149,10 +147,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
private ArrayList<String> findAllDeclaredNames() { private ArrayList<String> findAllDeclaredNames() {
ArrayList<String> names = new ArrayList<String>(); ArrayList<String> names = new ArrayList<String>();
IASTFunctionDefinition funcDef = NodeHelper IASTFunctionDefinition funcDef = NodeHelper.findFunctionDefinitionInAncestors(target);
.findFunctionDefinitionInAncestors(target); ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef);
ICPPASTCompositeTypeSpecifier comTypeSpec =
getCompositeTypeSpecifier(funcDef);
if (comTypeSpec != null) { if (comTypeSpec != null) {
for (IASTDeclaration dec : comTypeSpec.getMembers()) { for (IASTDeclaration dec : comTypeSpec.getMembers()) {
if (dec instanceof IASTSimpleDeclaration) { if (dec instanceof IASTSimpleDeclaration) {
@ -166,21 +162,16 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
return names; return names;
} }
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier( private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTFunctionDefinition funcDef) {
IASTFunctionDefinition funcDef) {
if (funcDef != null) { if (funcDef != null) {
IBinding binding = funcDef.getDeclarator().getName() IBinding binding = funcDef.getDeclarator().getName().resolveBinding();
.resolveBinding();
if (binding instanceof CPPFunction) { if (binding instanceof CPPFunction) {
CPPFunction function = (CPPFunction) binding; CPPFunction function = (CPPFunction) binding;
IASTNode[] decls = function.getDeclarations(); IASTNode[] decls = function.getDeclarations();
if (decls != null && decls.length > 0) { if (decls != null && decls.length > 0) {
IASTNode spec = decls[0].getParent().getParent(); IASTNode spec = decls[0].getParent().getParent();
if (spec instanceof ICPPASTCompositeTypeSpecifier) { if (spec instanceof ICPPASTCompositeTypeSpecifier) {
ICPPASTCompositeTypeSpecifier compTypeSpec = return (ICPPASTCompositeTypeSpecifier) spec;
(ICPPASTCompositeTypeSpecifier) spec;
return compTypeSpec;
} }
} }
} }
@ -188,16 +179,14 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
return null; return null;
} }
private boolean isOneMarked(List<IASTNode> selectedNodes, private boolean isOneMarked(List<IASTNode> selectedNodes, Region textSelection) {
Region textSelection) {
boolean oneMarked = false; boolean oneMarked = false;
for (IASTNode node : selectedNodes) { for (IASTNode node : selectedNodes) {
if (node instanceof IASTExpression) { if (node instanceof IASTExpression) {
IASTExpression expression = (IASTExpression) node; IASTExpression expression = (IASTExpression) node;
boolean isInSameFileSelection = SelectionHelper boolean isInSameFileSelection =
.isInSameFileSelection(textSelection, expression, file); SelectionHelper.isInSameFileSelection(textSelection, expression, file);
if (isInSameFileSelection if (isInSameFileSelection && isExpressionInSelection(expression, textSelection)) {
&& isExpressionInSelection(expression, textSelection)) {
if (target == null) { if (target == null) {
target = expression; target = expression;
oneMarked = true; oneMarked = true;
@ -210,8 +199,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
return oneMarked; return oneMarked;
} }
private boolean isExpressionInSelection(IASTExpression expression, private boolean isExpressionInSelection(IASTExpression expression, Region selection) {
Region selection) {
IASTFileLocation location = expression.getFileLocation(); IASTFileLocation location = expression.getFileLocation();
int e1 = location.getNodeOffset(); int e1 = location.getNodeOffset();
int e2 = location.getNodeOffset() + location.getNodeLength(); int e2 = location.getNodeOffset() + location.getNodeLength();
@ -255,29 +243,26 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
} }
@Override @Override
protected void collectModifications(IProgressMonitor pm, protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
ModificationCollector collector) throws CoreException, throws CoreException, OperationCanceledException {
OperationCanceledException {
try { try {
lockIndex(); lockIndex();
try { try {
String variableName = info.getName(); String variableName = info.getName();
TextEditGroup editGroup = new TextEditGroup( TextEditGroup editGroup = new TextEditGroup(Messages.CreateLocalVariable);
Messages.CreateLocalVariable);
// Define temporary variable declaration and insert it // Define temporary variable declaration and insert it
IASTStatement declInsertPoint = getParentStatement(target); IASTStatement declInsertPoint = getParentStatement(target);
IASTDeclarationStatement declaration = getVariableNodes(variableName); IASTDeclarationStatement declaration = getVariableNodes(variableName);
declaration.setParent(declInsertPoint.getParent()); declaration.setParent(declInsertPoint.getParent());
ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit); ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit);
rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, declaration, editGroup);
declaration, editGroup);
// Replace target with reference to temporary variable // Replace target with reference to temporary variable
CPPASTIdExpression idExpression = new CPPASTIdExpression( CPPASTIdExpression idExpression =
new CPPASTName(variableName.toCharArray())); new CPPASTIdExpression(new CPPASTName(variableName.toCharArray()));
rewriter.replace(target, idExpression, editGroup); rewriter.replace(target, idExpression, editGroup);
}finally { } finally {
unlockIndex(); unlockIndex();
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -295,7 +280,6 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
} }
private IASTDeclarationStatement getVariableNodes(String newName) { private IASTDeclarationStatement getVariableNodes(String newName) {
INodeFactory factory = this.unit.getASTNodeFactory(); INodeFactory factory = this.unit.getASTNodeFactory();
IASTSimpleDeclaration simple = factory.newSimpleDeclaration(null); IASTSimpleDeclaration simple = factory.newSimpleDeclaration(null);
@ -306,7 +290,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
declSpec.setStorageClass(IASTDeclSpecifier.sc_unspecified); declSpec.setStorageClass(IASTDeclSpecifier.sc_unspecified);
simple.setDeclSpecifier(declSpec); simple.setDeclSpecifier(declSpec);
IASTDeclarator decl = generator.createDeclaratorFromType(target.getExpressionType(), newName.toCharArray()); IASTDeclarator decl = generator.createDeclaratorFromType(target.getExpressionType(),
newName.toCharArray());
IASTEqualsInitializer init = new CPPASTEqualsInitializer(); IASTEqualsInitializer init = new CPPASTEqualsInitializer();
init.setInitializerClause(deblock(target.copy())); init.setInitializerClause(deblock(target.copy()));
@ -345,11 +330,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
public String[] guessTempNames() { public String[] guessTempNames() {
final List<String> guessedTempNames = new ArrayList<String>(); final List<String> guessedTempNames = new ArrayList<String>();
final List<String> usedNames = new ArrayList<String>(); final List<String> usedNames = new ArrayList<String>();
IASTFunctionDefinition funcDef = NodeHelper IASTFunctionDefinition funcDef = NodeHelper.findFunctionDefinitionInAncestors(target);
.findFunctionDefinitionInAncestors(target);
final IScope scope; final IScope scope;
if (funcDef != null && if (funcDef != null && funcDef.getBody() instanceof IASTCompoundStatement) {
funcDef.getBody() instanceof IASTCompoundStatement) {
IASTCompoundStatement body = (IASTCompoundStatement)funcDef.getBody(); IASTCompoundStatement body = (IASTCompoundStatement)funcDef.getBody();
scope = body.getScope(); scope = body.getScope();
} else { } else {
@ -432,8 +415,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
} }
private boolean nameAvailable(String name, List<String> guessedNames, IScope scope) { private boolean nameAvailable(String name, List<String> guessedNames, IScope scope) {
if (guessedNames.contains(name) || if (guessedNames.contains(name) || info.getUsedNames().contains(name)) {
info.getUsedNames().contains(name)) {
return false; return false;
} }
if (scope != null) { if (scope != null) {
@ -459,7 +441,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
@Override @Override
protected RefactoringDescriptor getRefactoringDescriptor() { protected RefactoringDescriptor getRefactoringDescriptor() {
Map<String, String> arguments = getArgumentMap(); Map<String, String> arguments = getArgumentMap();
RefactoringDescriptor desc = new ExtractLocalVariableRefactoringDescription(project.getProject().getName(), "Extract Local Variable Refactoring", "Extract " + target.getRawSignature(), arguments); //$NON-NLS-1$//$NON-NLS-2$ RefactoringDescriptor desc = new ExtractLocalVariableRefactoringDescription(project.getProject().getName(),
"Extract Local Variable Refactoring", "Extract " + target.getRawSignature(), arguments); //$NON-NLS-1$//$NON-NLS-2$
return desc; return desc;
} }

View file

@ -1,36 +1,35 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 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
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software (IFS)- initial API and implementation * Institute for Software (IFS)- initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
import java.util.Map; import java.util.Map;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContribution; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContribution;
/** /**
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
* */
*/ public class ExtractLocalVariableRefactoringContribution extends CRefactoringContribution {
public class ExtractLocalVariableRefactoringContribution extends CRefactoringContribution {
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override
@Override public RefactoringDescriptor createDescriptor(String id, String project, String description,
public RefactoringDescriptor createDescriptor(String id, String project, String description, String comment, Map arguments, int flags) throws IllegalArgumentException {
String comment, Map arguments, int flags) throws IllegalArgumentException { if (id.equals(ExtractLocalVariableRefactoring.ID)) {
if(id.equals(ExtractLocalVariableRefactoring.ID)) { return new ExtractLocalVariableRefactoringDescription(project, description, comment, arguments);
return new ExtractLocalVariableRefactoringDescription(project, description, comment, arguments); } else {
}else { return null;
return null; }
} }
} }
}

View file

@ -1,56 +1,56 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 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
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software (IFS)- initial API and implementation * Institute for Software (IFS)- initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
import java.util.Map; import java.util.Map;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ltk.core.refactoring.Refactoring; import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
/** /**
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
* *
*/ */
public class ExtractLocalVariableRefactoringDescription extends CRefactoringDescription { public class ExtractLocalVariableRefactoringDescription extends CRefactoringDescription {
static protected final String NAME = "name"; //$NON-NLS-1$ static protected final String NAME = "name"; //$NON-NLS-1$
public ExtractLocalVariableRefactoringDescription(String project, String description, public ExtractLocalVariableRefactoringDescription(String project, String description,
String comment, Map<String, String> arguments) { String comment, Map<String, String> arguments) {
super(ExtractLocalVariableRefactoring.ID, project, description, comment, CRefactoringDescription.MULTI_CHANGE, arguments); super(ExtractLocalVariableRefactoring.ID, project, description, comment,
} CRefactoringDescription.MULTI_CHANGE, arguments);
}
@Override
public Refactoring createRefactoring(RefactoringStatus status) throws CoreException { @Override
IFile file; public Refactoring createRefactoring(RefactoringStatus status) throws CoreException {
NameNVisibilityInformation info = new NameNVisibilityInformation(); IFile file;
ICProject proj; NameNVisibilityInformation info = new NameNVisibilityInformation();
ICProject proj;
info.setName(arguments.get(NAME));
info.setName(arguments.get(NAME));
proj = getCProject();
proj = getCProject();
file = getFile();
file = getFile();
ISelection selection = getSelection();
return new ExtractLocalVariableRefactoring(file, selection, info, proj); ISelection selection = getSelection();
} return new ExtractLocalVariableRefactoring(file, selection, info, proj);
}
} }

View file

@ -1,52 +1,51 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2009 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
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable; package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.IShellProvider; import org.eclipse.jface.window.IShellProvider;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring; import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation; import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner; import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
/** /**
* Extract Local Variable refactoring runner. * Extract Local Variable refactoring runner.
* *
* @author Tom Ball * @author Tom Ball
*/ */
public class ExtractLocalVariableRefactoringRunner extends RefactoringRunner { public class ExtractLocalVariableRefactoringRunner extends RefactoringRunner {
public ExtractLocalVariableRefactoringRunner(IFile file, public ExtractLocalVariableRefactoringRunner(IFile file, ISelection selection,
ISelection selection, IShellProvider shellProvider, ICProject cProject) { IShellProvider shellProvider, ICProject cProject) {
super(file, selection, null, shellProvider, cProject); super(file, selection, null, shellProvider, cProject);
} }
@Override @Override
public void run() { public void run() {
NameNVisibilityInformation info = new NameNVisibilityInformation(); NameNVisibilityInformation info = new NameNVisibilityInformation();
CRefactoring refactoring = new ExtractLocalVariableRefactoring(file, CRefactoring refactoring = new ExtractLocalVariableRefactoring(file, selection, info, project);
selection, info, project); ExtractLocalVariableRefactoringWizard wizard = new ExtractLocalVariableRefactoringWizard(
ExtractLocalVariableRefactoringWizard wizard = new ExtractLocalVariableRefactoringWizard( refactoring, info);
refactoring, info); RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
try {
try { operator.run(shellProvider.getShell(), refactoring.getName());
operator.run(shellProvider.getShell(), refactoring.getName()); } catch (InterruptedException e) {
} catch (InterruptedException e) { // initial condition checking got canceled by the user.
// initial condition checking got canceled by the user. }
} }
} }
}