mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 04:15:35 +02:00
Cosmetics.
This commit is contained in:
parent
f32b1fefd0
commit
6a4bd1e7c1
7 changed files with 192 additions and 271 deletions
|
@ -66,7 +66,7 @@ public abstract class CRefactoring extends Refactoring {
|
|||
protected IFile file;
|
||||
protected Region region;
|
||||
protected RefactoringStatus initStatus;
|
||||
protected IASTTranslationUnit unit;
|
||||
protected IASTTranslationUnit ast;
|
||||
protected ICProject project;
|
||||
private IIndex fIndex;
|
||||
|
||||
|
@ -227,8 +227,8 @@ public abstract class CRefactoring extends Refactoring {
|
|||
if (file != null) {
|
||||
try {
|
||||
subMonitor.subTask(Messages.Refactoring_PM_ParseTU);
|
||||
unit = loadTranslationUnit(file);
|
||||
if (unit == null) {
|
||||
ast = loadTranslationUnit(file);
|
||||
if (ast == null) {
|
||||
subMonitor.done();
|
||||
return false;
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ public abstract class CRefactoring extends Refactoring {
|
|||
|
||||
protected boolean translationUnitHasProblem() {
|
||||
ProblemFinder pf = new ProblemFinder(initStatus);
|
||||
unit.accept(pf);
|
||||
ast.accept(pf);
|
||||
return pf.hasProblem();
|
||||
}
|
||||
|
||||
|
@ -293,13 +293,13 @@ public abstract class CRefactoring extends Refactoring {
|
|||
}
|
||||
|
||||
public IASTTranslationUnit getUnit() {
|
||||
return unit;
|
||||
return ast;
|
||||
}
|
||||
|
||||
protected ArrayList<IASTName> findAllMarkedNames() {
|
||||
final ArrayList<IASTName> namesVector = new ArrayList<IASTName>();
|
||||
|
||||
unit.accept(new ASTVisitor() {
|
||||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
|||
import org.eclipse.text.edits.TextEditGroup;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeFactoryFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
|
@ -45,7 +46,6 @@ import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory;
|
||||
|
@ -74,10 +74,8 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper;
|
|||
* postconditions and collecting/creating the modifications to the AST.
|
||||
*
|
||||
* @author Mirko Stocker
|
||||
*
|
||||
*/
|
||||
public class ExtractConstantRefactoring extends CRefactoring {
|
||||
|
||||
public static final String ID = "org.eclipse.cdt.ui.refactoring.extractconstant.ExtractConstantRefactoring"; //$NON-NLS-1$
|
||||
|
||||
private IASTLiteralExpression target = null;
|
||||
|
@ -189,7 +187,6 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
if (funcDef != null) {
|
||||
IBinding binding = funcDef.getDeclarator().getName().resolveBinding();
|
||||
if (binding instanceof CPPMethod) {
|
||||
|
||||
CPPMethod methode = (CPPMethod) binding;
|
||||
IASTNode[] declarations = methode.getDeclarations();
|
||||
|
||||
|
@ -250,7 +247,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
private Collection<IASTLiteralExpression> findAllLiterals() {
|
||||
final Collection<IASTLiteralExpression> result = new ArrayList<IASTLiteralExpression>();
|
||||
|
||||
unit.accept(new CPPASTVisitor(){
|
||||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
@ -265,7 +262,6 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
}
|
||||
return super.visit(expression);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return result;
|
||||
|
@ -281,7 +277,6 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
Collection<IASTExpression> locLiteralsToReplace = new ArrayList<IASTExpression>();
|
||||
|
||||
if (context.getType() == MethodContext.ContextType.METHOD) {
|
||||
|
||||
for (IASTExpression expression : literalsToReplace) {
|
||||
MethodContext exprContext = NodeHelper.findMethodContext(expression, getIndex());
|
||||
if (exprContext.getType() == MethodContext.ContextType.METHOD) {
|
||||
|
@ -296,9 +291,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (IASTExpression expression : literalsToReplace) {
|
||||
IPath path = new Path(expression.getContainingFilename());
|
||||
IFile expressionFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
|
||||
|
@ -307,7 +300,6 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
locLiteralsToReplace.add(expression);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Create all Changes for literals
|
||||
|
@ -319,11 +311,10 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
AddDeclarationNodeToClassChange.createChange(classDefinition, info.getVisibility(), getConstNodesClass(constName), true, collector);
|
||||
} else {
|
||||
IASTDeclaration nodes = getConstNodesGlobal(constName);
|
||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit);
|
||||
rewriter.insertBefore(unit, TranslationUnitHelper.getFirstNode(unit), nodes, new TextEditGroup(Messages.ExtractConstantRefactoring_CreateConstant));
|
||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(ast);
|
||||
rewriter.insertBefore(ast, TranslationUnitHelper.getFirstNode(ast), nodes, new TextEditGroup(Messages.ExtractConstantRefactoring_CreateConstant));
|
||||
}
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
unlockIndex();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -334,7 +325,8 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
@Override
|
||||
protected RefactoringDescriptor getRefactoringDescriptor() {
|
||||
Map<String, String> arguments = getArgumentMap();
|
||||
RefactoringDescriptor desc = new ExtractConstantRefactoringDescription( project.getProject().getName(), "Extract Constant Refactoring", "Create constant for " + target.getRawSignature(), arguments); //$NON-NLS-1$//$NON-NLS-2$
|
||||
RefactoringDescriptor desc = new ExtractConstantRefactoringDescription(project.getProject().getName(),
|
||||
"Extract Constant Refactoring", "Create constant for " + target.getRawSignature(), arguments); //$NON-NLS-1$//$NON-NLS-2$
|
||||
return desc;
|
||||
}
|
||||
|
||||
|
@ -347,8 +339,8 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
return arguments;
|
||||
}
|
||||
|
||||
private void createLiteralToConstantChanges(String constName, Iterable<? extends IASTExpression> literals, ModificationCollector collector) {
|
||||
|
||||
private void createLiteralToConstantChanges(String constName,
|
||||
Iterable<? extends IASTExpression> literals, ModificationCollector collector) {
|
||||
for (IASTExpression each : literals) {
|
||||
ASTRewrite rewrite = collector.rewriterForTranslationUnit(each.getTranslationUnit());
|
||||
CPPASTIdExpression idExpression = new CPPASTIdExpression(new CPPASTName(constName.toCharArray()));
|
||||
|
@ -357,11 +349,9 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
private IASTSimpleDeclaration getConstNodes(String newName) {
|
||||
|
||||
ICPPNodeFactory factory = ASTNodeFactoryFactory.getDefaultCPPNodeFactory();
|
||||
DeclarationGenerator generator = DeclarationGenerator.create(factory);
|
||||
|
||||
|
||||
IType type = target.getExpressionType();
|
||||
|
||||
IASTDeclSpecifier declSpec = generator.createDeclSpecFromType(type);
|
||||
|
@ -389,7 +379,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
private IASTDeclaration getConstNodesGlobal(String newName) {
|
||||
IASTSimpleDeclaration simple = getConstNodes(newName);
|
||||
|
||||
INodeFactory factory= unit.getASTNodeFactory();
|
||||
INodeFactory factory= ast.getASTNodeFactory();
|
||||
if (factory instanceof ICPPNodeFactory) {
|
||||
ICPPASTNamespaceDefinition namespace = ((ICPPNodeFactory) factory).newNamespaceDefinition(new CPPASTName());
|
||||
namespace.addDeclaration(simple);
|
||||
|
@ -405,5 +395,4 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
simple.getDeclSpecifier().setStorageClass(IASTDeclSpecifier.sc_static);
|
||||
return simple;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -109,13 +109,11 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
|
|||
import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
|
||||
|
||||
public class ExtractFunctionRefactoring extends CRefactoring {
|
||||
|
||||
public static final String ID = "org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"; //$NON-NLS-1$
|
||||
|
||||
static final Integer NULL_INTEGER = Integer.valueOf(0);
|
||||
static final char[] ZERO= "0".toCharArray(); //$NON-NLS-1$
|
||||
|
||||
|
||||
NodeContainer container;
|
||||
final ExtractFunctionInformation info;
|
||||
|
||||
|
@ -189,8 +187,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
info.setInScopeDeclaredVariable(container.getAllDeclaredInScope().get(0));
|
||||
}
|
||||
|
||||
extractedFunctionConstructionHelper = ExtractedFunctionConstructionHelper
|
||||
.createFor(container.getNodesToWrite());
|
||||
extractedFunctionConstructionHelper =
|
||||
ExtractedFunctionConstructionHelper.createFor(container.getNodesToWrite());
|
||||
|
||||
boolean isExtractExpression = container.getNodesToWrite().get(0) instanceof IASTExpression;
|
||||
info.setExtractExpression(isExtractExpression);
|
||||
|
@ -211,8 +209,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
}
|
||||
}
|
||||
sm.done();
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
unlockIndex();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -225,18 +222,14 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
ArrayList<NameInformation> paras = container.getNames();
|
||||
|
||||
for (NameInformation name : paras) {
|
||||
int flag = CPPVariableReadWriteFlags.getReadWriteFlags(name
|
||||
.getName());
|
||||
int flag = CPPVariableReadWriteFlags.getReadWriteFlags(name.getName());
|
||||
if ((flag & PDOMName.WRITE_ACCESS) != 0) {
|
||||
name.setWriteAccess(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkForNonExtractableStatements(NodeContainer cont,
|
||||
RefactoringStatus status) {
|
||||
|
||||
private void checkForNonExtractableStatements(NodeContainer cont, RefactoringStatus status) {
|
||||
NonExtractableStmtFinder vis = new NonExtractableStmtFinder();
|
||||
for (IASTNode node : cont.getNodesToWrite()) {
|
||||
node.accept(vis);
|
||||
|
@ -257,17 +250,14 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ICPPASTFunctionDeclarator getDeclaration(IASTNode node) {
|
||||
|
||||
while (node != null && !(node instanceof IASTFunctionDefinition)) {
|
||||
node = node.getParent();
|
||||
}
|
||||
if (node != null) {
|
||||
IASTFunctionDeclarator declarator = ((IASTFunctionDefinition) node)
|
||||
.getDeclarator();
|
||||
IASTFunctionDeclarator declarator = ((IASTFunctionDefinition) node).getDeclarator();
|
||||
if (declarator instanceof ICPPASTFunctionDeclarator) {
|
||||
return (ICPPASTFunctionDeclarator) declarator;
|
||||
}
|
||||
|
@ -318,8 +308,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
try {
|
||||
lockIndex();
|
||||
try {
|
||||
final IASTName astMethodName = new CPPASTName(info.getMethodName()
|
||||
.toCharArray());
|
||||
final IASTName astMethodName = new CPPASTName(info.getMethodName().toCharArray());
|
||||
|
||||
MethodContext context = NodeHelper.findMethodContext(container.getNodesToWrite().get(0), getIndex());
|
||||
|
||||
|
@ -330,27 +319,24 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
// Create Method Definition
|
||||
IASTNode firstNode = container.getNodesToWrite().get(0);
|
||||
IPath implPath = new Path(firstNode.getContainingFilename());
|
||||
final IFile implementationFile = ResourcesPlugin.getWorkspace()
|
||||
.getRoot().getFileForLocation(implPath);
|
||||
final IFile implementationFile =
|
||||
ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(implPath);
|
||||
|
||||
createMethodDefinition(astMethodName, context, firstNode,
|
||||
implementationFile, collector);
|
||||
createMethodDefinition(astMethodName, context, firstNode, implementationFile,
|
||||
collector);
|
||||
|
||||
createMethodCalls(astMethodName, implementationFile, context, collector);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
unlockIndex();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createMethodCalls(final IASTName astMethodName,
|
||||
final IFile implementationFile, MethodContext context,
|
||||
ModificationCollector collector) throws CoreException {
|
||||
|
||||
String title;
|
||||
if (context.getType() == MethodContext.ContextType.METHOD) {
|
||||
title = Messages.ExtractFunctionRefactoring_CreateMethodCall;
|
||||
|
@ -361,9 +347,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
IASTNode methodCall = getMethodCall(astMethodName);
|
||||
|
||||
IASTNode firstNodeToWrite = container.getNodesToWrite().get(0);
|
||||
ASTRewrite rewriter = collector
|
||||
.rewriterForTranslationUnit(firstNodeToWrite
|
||||
.getTranslationUnit());
|
||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(
|
||||
firstNodeToWrite.getTranslationUnit());
|
||||
TextEditGroup editGroup = new TextEditGroup(title);
|
||||
if (methodCall instanceof IASTDeclaration){
|
||||
CPPASTDeclarationStatement declarationStatement = new CPPASTDeclarationStatement((IASTDeclaration) methodCall);
|
||||
|
@ -412,7 +397,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
private void createMethodDefinition(final IASTName astMethodName,
|
||||
MethodContext context, IASTNode firstNode,
|
||||
final IFile implementationFile, ModificationCollector collector) {
|
||||
|
||||
IASTFunctionDefinition node = NodeHelper.findFunctionDefinitionInAncestors(firstNode);
|
||||
if (node != null) {
|
||||
String title;
|
||||
|
@ -434,14 +418,12 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
|
||||
IASTSimpleDeclaration methodDeclaration = getDeclaration(collector, astMethodName);
|
||||
|
||||
AddDeclarationNodeToClassChange.createChange(classDeclaration, info
|
||||
.getVisibility(), methodDeclaration, false, collector);
|
||||
|
||||
AddDeclarationNodeToClassChange.createChange(classDeclaration, info.getVisibility(),
|
||||
methodDeclaration, false, collector);
|
||||
}
|
||||
|
||||
private void replaceSimilar(ModificationCollector collector, final IASTName astMethodName,
|
||||
final IFile implementationFile,
|
||||
final ContextType contextType) {
|
||||
final IFile implementationFile, final ContextType contextType) {
|
||||
// Find similar code
|
||||
final List<IASTNode> nodesToRewriteWithoutComments = new LinkedList<IASTNode>();
|
||||
|
||||
|
@ -460,14 +442,13 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
if (!hasNameResolvingForSimilarError) {
|
||||
unit.accept(new SimilarFinderVisitor(this, collector, initTrail, implementationFile,
|
||||
ast.accept(new SimilarFinderVisitor(this, collector, initTrail, implementationFile,
|
||||
astMethodName, nodesToRewriteWithoutComments, title));
|
||||
}
|
||||
}
|
||||
|
||||
protected Vector<IASTNode> getTrail(List<IASTNode> stmts) {
|
||||
final Vector<IASTNode> trail = new Vector<IASTNode>();
|
||||
|
||||
nameTrail = new HashMap<String, Integer>();
|
||||
final Container<Integer> trailCounter = new Container<Integer>(NULL_INTEGER);
|
||||
|
||||
|
@ -475,7 +456,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
node.accept(new CPPASTAllVisitor() {
|
||||
@Override
|
||||
public int visitAll(IASTNode node) {
|
||||
|
||||
if (node instanceof IASTComment) {
|
||||
// Visit Comment, but don't add them to the trail
|
||||
return super.visitAll(node);
|
||||
|
@ -489,7 +469,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
trail.add(node);
|
||||
return super.visitAll(node);
|
||||
} else {
|
||||
// Save Name Sequenz Number
|
||||
// Save Name Sequence Number
|
||||
IASTName name = (IASTName) node;
|
||||
TrailName trailName = new TrailName(name);
|
||||
int actCount = trailCounter.getObject().intValue();
|
||||
|
@ -530,7 +510,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
stmt.accept(new CPPASTAllVisitor() {
|
||||
@Override
|
||||
public int visitAll(IASTNode node) {
|
||||
|
||||
int pos = trailPos.getObject().intValue();
|
||||
|
||||
if (trail.size() <= 0 || pos >= trail.size()) {
|
||||
|
@ -552,7 +531,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
} else {
|
||||
return super.visitAll(node);
|
||||
}
|
||||
|
||||
} else {
|
||||
same.setObject(new Boolean(false));
|
||||
return PROCESS_ABORT;
|
||||
|
@ -563,15 +541,14 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
return same.getObject().booleanValue();
|
||||
}
|
||||
|
||||
private boolean isMethodAllreadyDefined(
|
||||
IASTSimpleDeclaration methodDeclaration,
|
||||
private boolean isMethodAllreadyDefined(IASTSimpleDeclaration methodDeclaration,
|
||||
ICPPASTCompositeTypeSpecifier classDeclaration, IIndex index) {
|
||||
TrailNodeEqualityChecker equalityChecker = new TrailNodeEqualityChecker(
|
||||
names, namesCounter, index);
|
||||
|
||||
IBinding bind = classDeclaration.getName().resolveBinding();
|
||||
IASTStandardFunctionDeclarator declarator = (IASTStandardFunctionDeclarator) methodDeclaration
|
||||
.getDeclarators()[0];
|
||||
IASTStandardFunctionDeclarator declarator =
|
||||
(IASTStandardFunctionDeclarator) methodDeclaration.getDeclarators()[0];
|
||||
String name = new String(declarator.getName().toCharArray());
|
||||
if (bind instanceof ICPPClassType) {
|
||||
ICPPClassType classBind = (ICPPClassType) bind;
|
||||
|
@ -587,23 +564,16 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
IParameter[] parameters = method.getParameters();
|
||||
if (parameters.length == declarator.getParameters().length) {
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
IASTName[] origParameterName = unit
|
||||
.getDeclarationsInAST(parameters[i]);
|
||||
|
||||
IASTParameterDeclaration origParameter = (IASTParameterDeclaration) origParameterName[0]
|
||||
.getParent().getParent();
|
||||
IASTParameterDeclaration newParameter = declarator
|
||||
.getParameters()[i];
|
||||
IASTName[] origParameterName = ast.getDeclarationsInAST(parameters[i]);
|
||||
IASTParameterDeclaration origParameter =
|
||||
(IASTParameterDeclaration) origParameterName[0].getParent().getParent();
|
||||
IASTParameterDeclaration newParameter = declarator.getParameters()[i];
|
||||
|
||||
// if not the same break;
|
||||
if (!(equalityChecker.isEquals(origParameter
|
||||
.getDeclSpecifier(), newParameter
|
||||
.getDeclSpecifier()) && ASTHelper
|
||||
.samePointers(origParameter
|
||||
.getDeclarator()
|
||||
.getPointerOperators(),
|
||||
newParameter.getDeclarator()
|
||||
.getPointerOperators(),
|
||||
if (!(equalityChecker.isEquals(origParameter.getDeclSpecifier(),
|
||||
newParameter.getDeclSpecifier()) &&
|
||||
ASTHelper.samePointers(origParameter.getDeclarator().getPointerOperators(),
|
||||
newParameter.getDeclarator().getPointerOperators(),
|
||||
equalityChecker))) {
|
||||
break;
|
||||
}
|
||||
|
@ -613,7 +583,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -623,7 +592,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
|
||||
private void addMethod(IASTName astMethodName, MethodContext context,
|
||||
ASTRewrite rewriter, IASTNode insertpoint, TextEditGroup group) {
|
||||
|
||||
ICPPASTQualifiedName qname = new CPPASTQualifiedName();
|
||||
if (context.getType() == ContextType.METHOD) {
|
||||
if (context.getMethodQName() != null) {
|
||||
|
@ -635,7 +603,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
qname.addName(astMethodName);
|
||||
|
||||
IASTFunctionDefinition func = new CPPASTFunctionDefinition();
|
||||
func.setParent(unit);
|
||||
func.setParent(ast);
|
||||
|
||||
IASTDeclSpecifier returnType = getReturnType();
|
||||
func.setDeclSpecifier(returnType);
|
||||
|
@ -643,7 +611,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
IASTStandardFunctionDeclarator createdFunctionDeclarator = extractedFunctionConstructionHelper
|
||||
.createFunctionDeclarator(qname, info.getDeclarator(), info
|
||||
.getReturnVariable(), container.getNodesToWrite(), info
|
||||
.getAllUsedNames(), unit.getASTNodeFactory());
|
||||
.getAllUsedNames(), ast.getASTNodeFactory());
|
||||
func.setDeclarator(createdFunctionDeclarator);
|
||||
|
||||
IASTCompoundStatement compound = new CPPASTCompoundStatement();
|
||||
|
@ -651,18 +619,16 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
|
||||
ASTRewrite subRW;
|
||||
if (insertpoint.getParent() instanceof ICPPASTTemplateDeclaration) {
|
||||
|
||||
CPPASTTemplateDeclaration templateDeclaration = new CPPASTTemplateDeclaration();
|
||||
templateDeclaration.setParent(unit);
|
||||
templateDeclaration.setParent(ast);
|
||||
|
||||
for (ICPPASTTemplateParameter templateParameter : ((ICPPASTTemplateDeclaration) insertpoint.getParent()).getTemplateParameters()) {
|
||||
templateDeclaration.addTemplateParameter(templateParameter.copy());
|
||||
}
|
||||
|
||||
templateDeclaration.setDeclaration(func);
|
||||
|
||||
subRW = rewriter.insertBefore(insertpoint.getParent().getParent(), insertpoint.getParent(), templateDeclaration, group);
|
||||
|
||||
subRW = rewriter.insertBefore(insertpoint.getParent().getParent(), insertpoint.getParent(),
|
||||
templateDeclaration, group);
|
||||
} else {
|
||||
|
||||
subRW = rewriter.insertBefore(insertpoint.getParent(), insertpoint, func, group);
|
||||
|
@ -690,7 +656,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
}
|
||||
subRW.insertBefore(compound, null, returnStmt, group);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private IASTName newName(IASTName declaration) {
|
||||
|
@ -698,12 +663,10 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
private IASTDeclSpecifier getReturnType() {
|
||||
|
||||
IASTNode firstNodeToWrite = container.getNodesToWrite().get(0);
|
||||
NameInformation returnVariable = info.getReturnVariable();
|
||||
|
||||
return extractedFunctionConstructionHelper.determineReturnType(
|
||||
firstNodeToWrite, returnVariable);
|
||||
return extractedFunctionConstructionHelper.determineReturnType(firstNodeToWrite, returnVariable);
|
||||
}
|
||||
|
||||
protected IASTNode getMethodCall(IASTName astMethodName,
|
||||
|
@ -721,8 +684,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
boolean theRetName = false;
|
||||
|
||||
for (NameInformation nameInfo : myContainer.getNames()) {
|
||||
Integer trailSeqNumber = trailNameTable.get(nameInfo
|
||||
.getDeclaration().getRawSignature());
|
||||
Integer trailSeqNumber = trailNameTable.get(nameInfo.getDeclaration().getRawSignature());
|
||||
String orgName = null;
|
||||
for (Entry<String, Integer> entry : similarNameTable.entrySet()) {
|
||||
if (entry.getValue().equals(trailSeqNumber)) {
|
||||
|
@ -736,8 +698,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
|
||||
if (orgName != null) {
|
||||
boolean found = false;
|
||||
for (NameInformation simNameInfo : mySimilarContainer
|
||||
.getNames()) {
|
||||
for (NameInformation simNameInfo : mySimilarContainer.getNames()) {
|
||||
if (orgName.equals(simNameInfo.getDeclaration()
|
||||
.getRawSignature())) {
|
||||
addAParameterIfPossible(args, declarations,
|
||||
|
@ -746,9 +707,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
|
||||
if (theRetName) {
|
||||
theRetName = false;
|
||||
retName = new CPPASTName(simNameInfo
|
||||
.getDeclaration().getRawSignature()
|
||||
.toCharArray());
|
||||
retName = new CPPASTName(
|
||||
simNameInfo.getDeclaration().getRawSignature().toCharArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -792,7 +752,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
}
|
||||
IASTName retname = newName(info.getReturnVariable().getName());
|
||||
return getReturnAssignment(stmt, callExpression, retname);
|
||||
|
||||
}
|
||||
|
||||
private IASTNode getReturnAssignment(IASTExpressionStatement stmt,
|
||||
|
@ -808,8 +767,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
|
||||
declarator.setName(retname);
|
||||
|
||||
for (IASTPointerOperator pointer : orgDecl.getDeclarators()[0]
|
||||
.getPointerOperators()) {
|
||||
for (IASTPointerOperator pointer : orgDecl.getDeclarators()[0].getPointerOperators()) {
|
||||
declarator.addPointerOperator(pointer.copy());
|
||||
}
|
||||
|
||||
|
@ -834,19 +792,17 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
|
||||
private IASTNode getReturnAssignment(IASTExpressionStatement stmt,
|
||||
IASTExpression callExpression) {
|
||||
|
||||
IASTNode node = container.getNodesToWrite().get(0);
|
||||
return extractedFunctionConstructionHelper.createReturnAssignment(node,
|
||||
stmt, callExpression);
|
||||
|
||||
}
|
||||
|
||||
private IASTSimpleDeclaration getDeclaration(IASTName name) {
|
||||
IASTSimpleDeclaration simpleDecl = new CPPASTSimpleDeclaration();
|
||||
IASTStandardFunctionDeclarator declarator = extractedFunctionConstructionHelper
|
||||
.createFunctionDeclarator(name, info.getDeclarator(), info
|
||||
.getReturnVariable(), container.getNodesToWrite(), info
|
||||
.getAllUsedNames(), unit.getASTNodeFactory());
|
||||
IASTStandardFunctionDeclarator declarator =
|
||||
extractedFunctionConstructionHelper.createFunctionDeclarator(name,
|
||||
info.getDeclarator(), info.getReturnVariable(),
|
||||
container.getNodesToWrite(), info.getAllUsedNames(), ast.getASTNodeFactory());
|
||||
simpleDecl.addDeclarator(declarator);
|
||||
return simpleDecl;
|
||||
}
|
||||
|
@ -857,18 +813,18 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
if (info.isVirtual() && declSpec instanceof ICPPASTDeclSpecifier) {
|
||||
((ICPPASTDeclSpecifier)declSpec).setVirtual(true);
|
||||
}
|
||||
simpleDecl.setParent(unit);
|
||||
simpleDecl.setParent(ast);
|
||||
IASTStandardFunctionDeclarator declarator = extractedFunctionConstructionHelper
|
||||
.createFunctionDeclarator(name, info.getDeclarator(), info
|
||||
.getReturnVariable(), container.getNodesToWrite(), info
|
||||
.getAllUsedNames(), unit.getASTNodeFactory());
|
||||
.getAllUsedNames(), ast.getASTNodeFactory());
|
||||
simpleDecl.addDeclarator(declarator);
|
||||
return simpleDecl;
|
||||
}
|
||||
|
||||
private NodeContainer findExtractableNodes() {
|
||||
final NodeContainer container = new NodeContainer();
|
||||
unit.accept(new ASTVisitor() {
|
||||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitStatements = true;
|
||||
shouldVisitExpressions = true;
|
||||
|
@ -933,5 +889,4 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
arguments.put(ExtractFunctionRefactoringDescription.REPLACE_DUBLICATES, Boolean.toString(info.isReplaceDuplicates()));
|
||||
return arguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
private NodeContainer findAllExpressions() {
|
||||
final NodeContainer container = new NodeContainer();
|
||||
|
||||
unit.accept(new ASTVisitor() {
|
||||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
IASTStatement declInsertPoint = getParentStatement(target);
|
||||
IASTDeclarationStatement declaration = getVariableNodes(variableName);
|
||||
declaration.setParent(declInsertPoint.getParent());
|
||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(unit);
|
||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(ast);
|
||||
rewriter.insertBefore(declInsertPoint.getParent(), declInsertPoint, declaration, editGroup);
|
||||
|
||||
// Replace target with reference to temporary variable
|
||||
|
@ -280,7 +280,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
private IASTDeclarationStatement getVariableNodes(String newName) {
|
||||
INodeFactory factory = this.unit.getASTNodeFactory();
|
||||
INodeFactory factory = this.ast.getASTNodeFactory();
|
||||
|
||||
IASTSimpleDeclaration simple = factory.newSimpleDeclaration(null);
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
|||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
||||
|
||||
|
@ -73,7 +72,6 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier declSpec) {
|
||||
|
||||
if (declSpec instanceof IASTCompositeTypeSpecifier) {
|
||||
IASTFileLocation loc = declSpec.getFileLocation();
|
||||
if (start > loc.getNodeOffset() && start < loc.getNodeOffset()+ loc.getNodeLength()) {
|
||||
|
@ -104,9 +102,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
if (!initStatus.hasFatalError()) {
|
||||
|
||||
initRefactoring(pm);
|
||||
|
||||
if (context.existingFields.size() == 0) {
|
||||
initStatus.addFatalError(Messages.GenerateGettersAndSettersRefactoring_NoFields);
|
||||
}
|
||||
|
@ -114,8 +110,6 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
return initStatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException,
|
||||
OperationCanceledException {
|
||||
|
@ -129,8 +123,8 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
finalStatus.addInfo(Messages.GenerateGettersAndSettersRefactoring_NoImplFile);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {}
|
||||
finally {
|
||||
} catch (InterruptedException e) {
|
||||
} finally {
|
||||
unlockIndex();
|
||||
}
|
||||
return finalStatus;
|
||||
|
@ -155,7 +149,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
private IASTCompositeTypeSpecifier findCurrentCompositeTypeSpecifier() {
|
||||
final int start = region.getOffset();
|
||||
Container<IASTCompositeTypeSpecifier> container = new Container<IASTCompositeTypeSpecifier>();
|
||||
unit.accept(new CompositeTypeSpecFinder(start, container));
|
||||
ast.accept(new CompositeTypeSpecFinder(start, container));
|
||||
return container.getObject();
|
||||
}
|
||||
|
||||
|
@ -176,9 +170,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
protected void findDeclarations(IASTCompositeTypeSpecifier compositeTypeSpecifier) {
|
||||
|
||||
compositeTypeSpecifier.accept(new ASTVisitor() {
|
||||
|
||||
{
|
||||
shouldVisitDeclarations = true;
|
||||
}
|
||||
|
@ -218,7 +210,8 @@ public class GenerateGettersAndSettersRefactoring 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();
|
||||
ArrayList<IASTNode> getterAndSetters = new ArrayList<IASTNode>();
|
||||
|
@ -234,15 +227,15 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
if (!context.isImplementationInHeader()) {
|
||||
addDefinition(collector, definitions);
|
||||
}
|
||||
ICPPASTCompositeTypeSpecifier classDefinition = (ICPPASTCompositeTypeSpecifier) context.existingFields.get(context.existingFields.size()-1).getParent();
|
||||
ICPPASTCompositeTypeSpecifier classDefinition =
|
||||
(ICPPASTCompositeTypeSpecifier) context.existingFields.get(context.existingFields.size() - 1).getParent();
|
||||
|
||||
AddDeclarationNodeToClassChange.createChange(classDefinition, VisibilityEnum.v_public, getterAndSetters, false, collector);
|
||||
} catch (InterruptedException e) {}
|
||||
finally {
|
||||
AddDeclarationNodeToClassChange.createChange(classDefinition, VisibilityEnum.v_public,
|
||||
getterAndSetters, false, collector);
|
||||
} catch (InterruptedException e) {
|
||||
} finally {
|
||||
unlockIndex();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void addDefinition(ModificationCollector collector, ArrayList<IASTFunctionDefinition> definitions)
|
||||
|
@ -269,8 +262,8 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
|
||||
private InsertLocation findInsertLocation() throws CoreException {
|
||||
IASTSimpleDeclaration decl = context.existingFields.get(0);
|
||||
|
||||
InsertLocation insertLocation = MethodDefinitionInsertLocationFinder.find(decl.getFileLocation(), decl.getParent(), file);
|
||||
InsertLocation insertLocation = MethodDefinitionInsertLocationFinder.find(decl.getFileLocation(),
|
||||
decl.getParent(), file);
|
||||
|
||||
if (!insertLocation.hasFile() || NodeHelper.isContainedInTemplateDeclaration(decl)) {
|
||||
insertLocation.setInsertFile(file);
|
||||
|
@ -278,7 +271,6 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
return insertLocation;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,10 +59,8 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
|||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class HideMethodRefactoring extends CRefactoring {
|
||||
|
||||
public static final String ID = "org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring"; //$NON-NLS-1$
|
||||
|
||||
private IASTName methodToHide;
|
||||
|
@ -151,8 +149,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
initStatus.addError(Messages.HideMethodRefactoring_IsAlreadyPrivate);
|
||||
}
|
||||
sm.done();
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
unlockIndex();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -163,7 +160,6 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
|
||||
private boolean checkIfPrivate(IASTCompositeTypeSpecifier classNode, IASTDeclaration decl) {
|
||||
IASTDeclaration[] members = classNode.getMembers();
|
||||
|
||||
int currentVisibility = ICPPASTVisibilityLabel.v_private;
|
||||
if (IASTCompositeTypeSpecifier.k_struct == classNode.getKey()) {
|
||||
currentVisibility = ICPPASTVisibilityLabel.v_public;
|
||||
|
@ -227,8 +223,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
return finalConditions;
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
unlockIndex();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -285,8 +280,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
AddDeclarationNodeToClassChange.createChange(classDefinition, VisibilityEnum.v_private, methodToHideDecl, false, collector);
|
||||
|
||||
rewriter.remove(methodToHideDecl, editGroup);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
unlockIndex();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
@ -60,10 +60,8 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
|
|||
* Checks conditions, finds insert location and generates the ImplementationNode.
|
||||
*
|
||||
* @author Mirko Stocker, Lukas Felber, Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class ImplementMethodRefactoring extends CRefactoring {
|
||||
|
||||
private InsertLocation insertLocation;
|
||||
private CPPASTFunctionDeclarator createdMethodDeclarator;
|
||||
private ImplementMethodData data;
|
||||
|
@ -79,11 +77,10 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
|||
super.checkInitialConditions(sm.newChild(6));
|
||||
|
||||
if (!initStatus.hasFatalError()) {
|
||||
|
||||
data.setMethodDeclarations(findUnimplementedMethodDeclarations(unit));
|
||||
data.setMethodDeclarations(findUnimplementedMethodDeclarations(ast));
|
||||
|
||||
if (region.getLength() > 0) {
|
||||
IASTSimpleDeclaration methodDeclaration = SelectionHelper.findFirstSelectedDeclaration(region, unit);
|
||||
IASTSimpleDeclaration methodDeclaration = SelectionHelper.findFirstSelectedDeclaration(region, ast);
|
||||
if (NodeHelper.isMethodDeclaration(methodDeclaration)) {
|
||||
for (MethodToImplementConfig config : data.getMethodDeclarations()) {
|
||||
if (config.getDeclaration() == methodDeclaration) {
|
||||
|
@ -97,7 +94,6 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
|||
return initStatus;
|
||||
}
|
||||
|
||||
|
||||
private List<IASTSimpleDeclaration> findUnimplementedMethodDeclarations(
|
||||
IASTTranslationUnit unit) {
|
||||
final List<IASTSimpleDeclaration> list = new ArrayList<IASTSimpleDeclaration>();
|
||||
|
@ -118,16 +114,13 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
|||
}
|
||||
return ASTVisitor.PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
|
||||
|
||||
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
|
||||
throws CoreException, OperationCanceledException {
|
||||
List<MethodToImplementConfig> methodsToImplement = data.getMethodsToImplement();
|
||||
SubMonitor sm = SubMonitor.convert(pm, 4*methodsToImplement.size());
|
||||
for (MethodToImplementConfig config : methodsToImplement) {
|
||||
|
@ -159,7 +152,6 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
|||
createNewNameInsertModification(actParameterInfo, parameterRewrite);
|
||||
createRemoveDefaultValueModification(actParameterInfo, parameterRewrite);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createRemoveDefaultValueModification(ParameterInfo parameterInfo, ASTRewrite parameterRewrite) {
|
||||
|
@ -196,7 +188,6 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
|||
|
||||
private IASTDeclaration createFunctionDefinition(IASTDeclSpecifier declSpecifier, ICPPASTFunctionDeclarator functionDeclarator,
|
||||
IASTNode declarationParent, IASTTranslationUnit unit) throws CoreException {
|
||||
|
||||
IASTFunctionDefinition func = new CPPASTFunctionDefinition();
|
||||
func.setParent(unit);
|
||||
|
||||
|
@ -241,8 +232,8 @@ public class ImplementMethodRefactoring extends CRefactoring {
|
|||
return func;
|
||||
}
|
||||
|
||||
private ICPPASTQualifiedName createQualifiedNameFor(IASTFunctionDeclarator functionDeclarator, IASTNode declarationParent)
|
||||
throws CoreException {
|
||||
private ICPPASTQualifiedName createQualifiedNameFor(IASTFunctionDeclarator functionDeclarator,
|
||||
IASTNode declarationParent) throws CoreException {
|
||||
int insertOffset = insertLocation.getInsertPosition();
|
||||
return NameHelper.createQualifiedNameFor(functionDeclarator.getName(), file, functionDeclarator.getFileLocation().getNodeOffset(), insertLocation.getInsertFile(), insertOffset);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue