mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 20:35:38 +02:00
Cosmetics.
This commit is contained in:
parent
d1ee0b132a
commit
45f057367a
8 changed files with 244 additions and 269 deletions
|
@ -1,15 +1,15 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Intel Corporation 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:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.settings.model;
|
||||
|
||||
public interface ICFileDescription extends ICResourceDescription{
|
||||
ICLanguageSetting getLanguageSetting();
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Intel Corporation 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:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.settings.model;
|
||||
|
||||
public interface ICFileDescription extends ICResourceDescription {
|
||||
ICLanguageSetting getLanguageSetting();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* condition checking, change generating, selection handling and translation unit loading.
|
||||
*
|
||||
*/
|
||||
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 IFile file;
|
||||
protected Region region;
|
||||
protected RefactoringStatus initStatus;
|
||||
protected IASTTranslationUnit unit;
|
||||
private IIndex fIndex;
|
||||
|
||||
protected ICProject project;
|
||||
private IIndex fIndex;
|
||||
|
||||
public CRefactoring(IFile file, ISelection selection, ICElement element, ICProject proj) {
|
||||
project = proj;
|
||||
if (element instanceof ISourceReference) {
|
||||
ISourceReference sourceRef= (ISourceReference) element;
|
||||
ITranslationUnit tu= sourceRef.getTranslationUnit();
|
||||
ITranslationUnit tu = sourceRef.getTranslationUnit();
|
||||
IResource res= tu.getResource();
|
||||
if (res instanceof IFile)
|
||||
this.file= (IFile) res;
|
||||
|
@ -91,7 +90,7 @@ public abstract class CRefactoring extends Refactoring {
|
|||
this.region = SelectionHelper.getRegion(selection);
|
||||
}
|
||||
|
||||
this.initStatus=new RefactoringStatus();
|
||||
this.initStatus= new RefactoringStatus();
|
||||
if (this.file == null || region == null) {
|
||||
initStatus.addFatalError(Messages.Refactoring_SelectionNotValid);
|
||||
}
|
||||
|
@ -196,10 +195,9 @@ public abstract class CRefactoring extends Refactoring {
|
|||
return initStatus;
|
||||
}
|
||||
|
||||
protected boolean isProgressMonitorCanceld(IProgressMonitor sm,
|
||||
RefactoringStatus initStatus2) {
|
||||
protected static boolean isProgressMonitorCanceld(IProgressMonitor sm, RefactoringStatus status) {
|
||||
if (sm.isCanceled()) {
|
||||
initStatus2.addFatalError(Messages.Refactoring_CanceledByUser);
|
||||
status.addFatalError(Messages.Refactoring_CanceledByUser);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -217,15 +215,14 @@ public abstract class CRefactoring extends Refactoring {
|
|||
abstract protected RefactoringDescriptor getRefactoringDescriptor();
|
||||
|
||||
abstract protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
|
||||
throws CoreException, OperationCanceledException;
|
||||
throws CoreException, OperationCanceledException;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
protected boolean loadTranslationUnit(RefactoringStatus status,
|
||||
IProgressMonitor mon) {
|
||||
protected boolean loadTranslationUnit(RefactoringStatus status, IProgressMonitor mon) {
|
||||
SubMonitor subMonitor = SubMonitor.convert(mon, 10);
|
||||
if (file != null) {
|
||||
try {
|
||||
|
@ -247,7 +244,6 @@ public abstract class CRefactoring extends Refactoring {
|
|||
subMonitor.done();
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
status.addFatalError(Messages.NO_FILE);
|
||||
subMonitor.done();
|
||||
|
|
|
@ -53,7 +53,7 @@ public abstract class CRefactoringDescription extends RefactoringDescriptor {
|
|||
if (selectStrings.length >= 2) {
|
||||
int offset = Integer.parseInt(selectStrings[0]);
|
||||
int length = Integer.parseInt(selectStrings[1]);
|
||||
selection = new TextSelection(offset,length);
|
||||
selection = new TextSelection(offset, length);
|
||||
} else {
|
||||
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, "Illegal Selection")); //$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -1,45 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.window.IShellProvider;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
||||
/**
|
||||
* Base class for all refactoring runners.
|
||||
*
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public abstract class RefactoringRunner {
|
||||
|
||||
protected IFile file;
|
||||
protected ISelection selection;
|
||||
protected ICElement celement;
|
||||
protected IShellProvider shellProvider;
|
||||
protected ICProject project;
|
||||
|
||||
public RefactoringRunner(IFile file, ISelection selection, ICElement element, IShellProvider shellProvider, ICProject cProject) {
|
||||
this.file = file;
|
||||
this.selection = selection;
|
||||
this.celement= element;
|
||||
this.shellProvider= shellProvider;
|
||||
this.project = cProject;
|
||||
}
|
||||
|
||||
public abstract void run();
|
||||
|
||||
}
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.window.IShellProvider;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
||||
/**
|
||||
* Base class for all refactoring runners.
|
||||
*
|
||||
* @author Emanuel Graf
|
||||
*/
|
||||
public abstract class RefactoringRunner {
|
||||
protected IFile file;
|
||||
protected ISelection selection;
|
||||
protected ICElement celement;
|
||||
protected IShellProvider shellProvider;
|
||||
protected ICProject project;
|
||||
|
||||
public RefactoringRunner(IFile file, ISelection selection, ICElement element,
|
||||
IShellProvider shellProvider, ICProject cProject) {
|
||||
this.file = file;
|
||||
this.selection = selection;
|
||||
this.celement= element;
|
||||
this.shellProvider= shellProvider;
|
||||
this.project = cProject;
|
||||
}
|
||||
|
||||
public abstract void run();
|
||||
}
|
||||
|
|
|
@ -74,15 +74,15 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
|
|||
* @author Tom Ball
|
||||
*/
|
||||
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 = null;
|
||||
private IASTExpression target;
|
||||
private final NameNVisibilityInformation info;
|
||||
private NodeContainer container;
|
||||
|
||||
public ExtractLocalVariableRefactoring(IFile file, ISelection selection,
|
||||
NameNVisibilityInformation info, ICProject project) {
|
||||
public ExtractLocalVariableRefactoring(IFile file, ISelection selection, NameNVisibilityInformation info,
|
||||
ICProject project) {
|
||||
super(file, selection, null, project);
|
||||
this.info = info;
|
||||
name = Messages.ExtractLocalVariable;
|
||||
|
@ -90,13 +90,13 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
|
||||
@Override
|
||||
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
|
||||
throws CoreException, OperationCanceledException {
|
||||
throws CoreException, OperationCanceledException {
|
||||
SubMonitor sm = SubMonitor.convert(pm, 9);
|
||||
try {
|
||||
lockIndex();
|
||||
try {
|
||||
RefactoringStatus status = super.checkInitialConditions(sm.newChild(6));
|
||||
if(status.hasError()) {
|
||||
if (status.hasError()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -110,8 +110,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
if (isProgressMonitorCanceld(sm, initStatus))
|
||||
return initStatus;
|
||||
|
||||
boolean oneMarked = region != null
|
||||
&& isOneMarked(container.getNodesToWrite(), region);
|
||||
boolean oneMarked = region != null && isOneMarked(container.getNodesToWrite(), region);
|
||||
if (!oneMarked) {
|
||||
if (target == null) {
|
||||
initStatus.addFatalError(Messages.NoExpressionSelected);
|
||||
|
@ -132,13 +131,12 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
info.addNamesToUsedNames(findAllDeclaredNames());
|
||||
sm.worked(1);
|
||||
|
||||
NodeHelper.findMethodContext(container.getNodesToWrite().get(0),
|
||||
getIndex());
|
||||
NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex());
|
||||
sm.worked(1);
|
||||
|
||||
info.setName(guessTempName());
|
||||
sm.done();
|
||||
}finally {
|
||||
} finally {
|
||||
unlockIndex();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -149,10 +147,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
|
||||
private ArrayList<String> findAllDeclaredNames() {
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
IASTFunctionDefinition funcDef = NodeHelper
|
||||
.findFunctionDefinitionInAncestors(target);
|
||||
ICPPASTCompositeTypeSpecifier comTypeSpec =
|
||||
getCompositeTypeSpecifier(funcDef);
|
||||
IASTFunctionDefinition funcDef = NodeHelper.findFunctionDefinitionInAncestors(target);
|
||||
ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef);
|
||||
if (comTypeSpec != null) {
|
||||
for (IASTDeclaration dec : comTypeSpec.getMembers()) {
|
||||
if (dec instanceof IASTSimpleDeclaration) {
|
||||
|
@ -166,21 +162,16 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
return names;
|
||||
}
|
||||
|
||||
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(
|
||||
IASTFunctionDefinition funcDef) {
|
||||
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTFunctionDefinition funcDef) {
|
||||
if (funcDef != null) {
|
||||
IBinding binding = funcDef.getDeclarator().getName()
|
||||
.resolveBinding();
|
||||
IBinding binding = funcDef.getDeclarator().getName().resolveBinding();
|
||||
if (binding instanceof CPPFunction) {
|
||||
|
||||
CPPFunction function = (CPPFunction) binding;
|
||||
IASTNode[] decls = function.getDeclarations();
|
||||
if (decls != null && decls.length > 0) {
|
||||
IASTNode spec = decls[0].getParent().getParent();
|
||||
if (spec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
ICPPASTCompositeTypeSpecifier compTypeSpec =
|
||||
(ICPPASTCompositeTypeSpecifier) spec;
|
||||
return compTypeSpec;
|
||||
return (ICPPASTCompositeTypeSpecifier) spec;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -188,16 +179,14 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
return null;
|
||||
}
|
||||
|
||||
private boolean isOneMarked(List<IASTNode> selectedNodes,
|
||||
Region textSelection) {
|
||||
private boolean isOneMarked(List<IASTNode> selectedNodes, Region textSelection) {
|
||||
boolean oneMarked = false;
|
||||
for (IASTNode node : selectedNodes) {
|
||||
if (node instanceof IASTExpression) {
|
||||
IASTExpression expression = (IASTExpression) node;
|
||||
boolean isInSameFileSelection = SelectionHelper
|
||||
.isInSameFileSelection(textSelection, expression, file);
|
||||
if (isInSameFileSelection
|
||||
&& isExpressionInSelection(expression, textSelection)) {
|
||||
boolean isInSameFileSelection =
|
||||
SelectionHelper.isInSameFileSelection(textSelection, expression, file);
|
||||
if (isInSameFileSelection && isExpressionInSelection(expression, textSelection)) {
|
||||
if (target == null) {
|
||||
target = expression;
|
||||
oneMarked = true;
|
||||
|
@ -210,8 +199,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
return oneMarked;
|
||||
}
|
||||
|
||||
private boolean isExpressionInSelection(IASTExpression expression,
|
||||
Region selection) {
|
||||
private boolean isExpressionInSelection(IASTExpression expression, Region selection) {
|
||||
IASTFileLocation location = expression.getFileLocation();
|
||||
int e1 = location.getNodeOffset();
|
||||
int e2 = location.getNodeOffset() + location.getNodeLength();
|
||||
|
@ -255,29 +243,26 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void collectModifications(IProgressMonitor pm,
|
||||
ModificationCollector collector) throws CoreException,
|
||||
OperationCanceledException {
|
||||
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
|
||||
throws CoreException, OperationCanceledException {
|
||||
try {
|
||||
lockIndex();
|
||||
try {
|
||||
String variableName = info.getName();
|
||||
TextEditGroup editGroup = new TextEditGroup(
|
||||
Messages.CreateLocalVariable);
|
||||
TextEditGroup editGroup = new TextEditGroup(Messages.CreateLocalVariable);
|
||||
|
||||
// Define temporary variable declaration and insert it
|
||||
IASTStatement declInsertPoint = getParentStatement(target);
|
||||
IASTDeclarationStatement declaration = getVariableNodes(variableName);
|
||||
declaration.setParent(declInsertPoint.getParent());
|
||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit);
|
||||
rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint,
|
||||
declaration, editGroup);
|
||||
rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, declaration, editGroup);
|
||||
|
||||
// Replace target with reference to temporary variable
|
||||
CPPASTIdExpression idExpression = new CPPASTIdExpression(
|
||||
new CPPASTName(variableName.toCharArray()));
|
||||
CPPASTIdExpression idExpression =
|
||||
new CPPASTIdExpression(new CPPASTName(variableName.toCharArray()));
|
||||
rewriter.replace(target, idExpression, editGroup);
|
||||
}finally {
|
||||
} finally {
|
||||
unlockIndex();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -295,7 +280,6 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
private IASTDeclarationStatement getVariableNodes(String newName) {
|
||||
|
||||
INodeFactory factory = this.unit.getASTNodeFactory();
|
||||
|
||||
IASTSimpleDeclaration simple = factory.newSimpleDeclaration(null);
|
||||
|
@ -306,7 +290,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
declSpec.setStorageClass(IASTDeclSpecifier.sc_unspecified);
|
||||
simple.setDeclSpecifier(declSpec);
|
||||
|
||||
IASTDeclarator decl = generator.createDeclaratorFromType(target.getExpressionType(), newName.toCharArray());
|
||||
IASTDeclarator decl = generator.createDeclaratorFromType(target.getExpressionType(),
|
||||
newName.toCharArray());
|
||||
|
||||
IASTEqualsInitializer init = new CPPASTEqualsInitializer();
|
||||
init.setInitializerClause(deblock(target.copy()));
|
||||
|
@ -345,11 +330,9 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
public String[] guessTempNames() {
|
||||
final List<String> guessedTempNames = new ArrayList<String>();
|
||||
final List<String> usedNames = new ArrayList<String>();
|
||||
IASTFunctionDefinition funcDef = NodeHelper
|
||||
.findFunctionDefinitionInAncestors(target);
|
||||
IASTFunctionDefinition funcDef = NodeHelper.findFunctionDefinitionInAncestors(target);
|
||||
final IScope scope;
|
||||
if (funcDef != null &&
|
||||
funcDef.getBody() instanceof IASTCompoundStatement) {
|
||||
if (funcDef != null && funcDef.getBody() instanceof IASTCompoundStatement) {
|
||||
IASTCompoundStatement body = (IASTCompoundStatement)funcDef.getBody();
|
||||
scope = body.getScope();
|
||||
} else {
|
||||
|
@ -432,8 +415,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
private boolean nameAvailable(String name, List<String> guessedNames, IScope scope) {
|
||||
if (guessedNames.contains(name) ||
|
||||
info.getUsedNames().contains(name)) {
|
||||
if (guessedNames.contains(name) || info.getUsedNames().contains(name)) {
|
||||
return false;
|
||||
}
|
||||
if (scope != null) {
|
||||
|
@ -459,7 +441,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
@Override
|
||||
protected RefactoringDescriptor getRefactoringDescriptor() {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,36 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 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
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software (IFS)- initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContribution;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf IFS
|
||||
*
|
||||
*/
|
||||
public class ExtractLocalVariableRefactoringContribution extends CRefactoringContribution {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public RefactoringDescriptor createDescriptor(String id, String project, String description,
|
||||
String comment, Map arguments, int flags) throws IllegalArgumentException {
|
||||
if(id.equals(ExtractLocalVariableRefactoring.ID)) {
|
||||
return new ExtractLocalVariableRefactoringDescription(project, description, comment, arguments);
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 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
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software (IFS)- initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContribution;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf IFS
|
||||
*/
|
||||
public class ExtractLocalVariableRefactoringContribution extends CRefactoringContribution {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public RefactoringDescriptor createDescriptor(String id, String project, String description,
|
||||
String comment, Map arguments, int flags) throws IllegalArgumentException {
|
||||
if (id.equals(ExtractLocalVariableRefactoring.ID)) {
|
||||
return new ExtractLocalVariableRefactoringDescription(project, description, comment, arguments);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +1,56 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 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
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software (IFS)- initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf IFS
|
||||
*
|
||||
*/
|
||||
public class ExtractLocalVariableRefactoringDescription extends CRefactoringDescription {
|
||||
|
||||
static protected final String NAME = "name"; //$NON-NLS-1$
|
||||
|
||||
public ExtractLocalVariableRefactoringDescription(String project, String description,
|
||||
String comment, Map<String, String> arguments) {
|
||||
super(ExtractLocalVariableRefactoring.ID, project, description, comment, CRefactoringDescription.MULTI_CHANGE, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Refactoring createRefactoring(RefactoringStatus status) throws CoreException {
|
||||
IFile file;
|
||||
NameNVisibilityInformation info = new NameNVisibilityInformation();
|
||||
ICProject proj;
|
||||
|
||||
info.setName(arguments.get(NAME));
|
||||
|
||||
proj = getCProject();
|
||||
|
||||
file = getFile();
|
||||
|
||||
ISelection selection = getSelection();
|
||||
return new ExtractLocalVariableRefactoring(file, selection, info, proj);
|
||||
}
|
||||
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 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
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software (IFS)- initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ltk.core.refactoring.Refactoring;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf IFS
|
||||
*
|
||||
*/
|
||||
public class ExtractLocalVariableRefactoringDescription extends CRefactoringDescription {
|
||||
|
||||
static protected final String NAME = "name"; //$NON-NLS-1$
|
||||
|
||||
public ExtractLocalVariableRefactoringDescription(String project, String description,
|
||||
String comment, Map<String, String> arguments) {
|
||||
super(ExtractLocalVariableRefactoring.ID, project, description, comment,
|
||||
CRefactoringDescription.MULTI_CHANGE, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Refactoring createRefactoring(RefactoringStatus status) throws CoreException {
|
||||
IFile file;
|
||||
NameNVisibilityInformation info = new NameNVisibilityInformation();
|
||||
ICProject proj;
|
||||
|
||||
info.setName(arguments.get(NAME));
|
||||
|
||||
proj = getCProject();
|
||||
|
||||
file = getFile();
|
||||
|
||||
ISelection selection = getSelection();
|
||||
return new ExtractLocalVariableRefactoring(file, selection, info, proj);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,52 +1,51 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.window.IShellProvider;
|
||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
||||
|
||||
/**
|
||||
* Extract Local Variable refactoring runner.
|
||||
*
|
||||
* @author Tom Ball
|
||||
*/
|
||||
public class ExtractLocalVariableRefactoringRunner extends RefactoringRunner {
|
||||
|
||||
public ExtractLocalVariableRefactoringRunner(IFile file,
|
||||
ISelection selection, IShellProvider shellProvider, ICProject cProject) {
|
||||
super(file, selection, null, shellProvider, cProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
NameNVisibilityInformation info = new NameNVisibilityInformation();
|
||||
CRefactoring refactoring = new ExtractLocalVariableRefactoring(file,
|
||||
selection, info, project);
|
||||
ExtractLocalVariableRefactoringWizard wizard = new ExtractLocalVariableRefactoringWizard(
|
||||
refactoring, info);
|
||||
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
||||
|
||||
try {
|
||||
operator.run(shellProvider.getShell(), refactoring.getName());
|
||||
} catch (InterruptedException e) {
|
||||
// initial condition checking got canceled by the user.
|
||||
}
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.window.IShellProvider;
|
||||
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
|
||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringRunner;
|
||||
|
||||
/**
|
||||
* Extract Local Variable refactoring runner.
|
||||
*
|
||||
* @author Tom Ball
|
||||
*/
|
||||
public class ExtractLocalVariableRefactoringRunner extends RefactoringRunner {
|
||||
|
||||
public ExtractLocalVariableRefactoringRunner(IFile file, ISelection selection,
|
||||
IShellProvider shellProvider, ICProject cProject) {
|
||||
super(file, selection, null, shellProvider, cProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
NameNVisibilityInformation info = new NameNVisibilityInformation();
|
||||
CRefactoring refactoring = new ExtractLocalVariableRefactoring(file, selection, info, project);
|
||||
ExtractLocalVariableRefactoringWizard wizard = new ExtractLocalVariableRefactoringWizard(
|
||||
refactoring, info);
|
||||
RefactoringWizardOpenOperation operator = new RefactoringWizardOpenOperation(wizard);
|
||||
|
||||
try {
|
||||
operator.run(shellProvider.getShell(), refactoring.getName());
|
||||
} catch (InterruptedException e) {
|
||||
// initial condition checking got canceled by the user.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue