use of org.eclipse.jdt.core.dom.VariableDeclarationStatement in project che by eclipse.
the class InlineTempRefactoring method removeTemp.
private void removeTemp(CompilationUnitRewrite cuRewrite) {
VariableDeclaration variableDeclaration = getVariableDeclaration();
TextEditGroup groupDesc = cuRewrite.createGroupDescription(RefactoringCoreMessages.InlineTempRefactoring_remove_edit_name);
ASTNode parent = variableDeclaration.getParent();
ASTRewrite rewrite = cuRewrite.getASTRewrite();
TightSourceRangeComputer sourceRangeComputer = new TightSourceRangeComputer();
rewrite.setTargetSourceRangeComputer(sourceRangeComputer);
if (parent instanceof VariableDeclarationStatement && ((VariableDeclarationStatement) parent).fragments().size() == 1) {
sourceRangeComputer.addTightSourceNode(parent);
rewrite.remove(parent, groupDesc);
} else {
sourceRangeComputer.addTightSourceNode(variableDeclaration);
rewrite.remove(variableDeclaration, groupDesc);
}
}
use of org.eclipse.jdt.core.dom.VariableDeclarationStatement in project che by eclipse.
the class ExtractTempRefactoring method createAndInsertTempDeclaration.
private void createAndInsertTempDeclaration() throws CoreException {
Expression initializer = getSelectedExpression().createCopyTarget(fCURewrite.getASTRewrite(), true);
VariableDeclarationStatement vds = createTempDeclaration(initializer);
if ((!fReplaceAllOccurrences) || (retainOnlyReplacableMatches(getMatchingFragments()).length <= 1)) {
insertAt(getSelectedExpression().getAssociatedNode(), vds);
return;
}
ASTNode[] firstReplaceNodeParents = getParents(getFirstReplacedExpression().getAssociatedNode());
ASTNode[] commonPath = findDeepestCommonSuperNodePathForReplacedNodes();
Assert.isTrue(commonPath.length <= firstReplaceNodeParents.length);
ASTNode deepestCommonParent = firstReplaceNodeParents[commonPath.length - 1];
if (deepestCommonParent instanceof Block)
insertAt(firstReplaceNodeParents[commonPath.length], vds);
else
insertAt(deepestCommonParent, vds);
}
use of org.eclipse.jdt.core.dom.VariableDeclarationStatement in project che by eclipse.
the class ExtractTempRefactoring method createTempDeclaration.
private VariableDeclarationStatement createTempDeclaration(Expression initializer) throws CoreException {
AST ast = fCURewrite.getAST();
VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
vdf.setName(ast.newSimpleName(fTempName));
vdf.setInitializer(initializer);
VariableDeclarationStatement vds = ast.newVariableDeclarationStatement(vdf);
if (fDeclareFinal) {
vds.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
}
vds.setType(createTempType());
if (fLinkedProposalModel != null) {
ASTRewrite rewrite = fCURewrite.getASTRewrite();
LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
nameGroup.addPosition(rewrite.track(vdf.getName()), true);
String[] nameSuggestions = guessTempNames();
if (nameSuggestions.length > 0 && !nameSuggestions[0].equals(fTempName)) {
nameGroup.addProposal(fTempName, null, nameSuggestions.length + 1);
}
for (int i = 0; i < nameSuggestions.length; i++) {
nameGroup.addProposal(nameSuggestions[i], null, nameSuggestions.length - i);
}
}
return vds;
}
use of org.eclipse.jdt.core.dom.VariableDeclarationStatement in project che by eclipse.
the class CallInliner method addNewLocals.
private void addNewLocals(TextEditGroup textEditGroup) {
if (fLocals.isEmpty())
return;
for (Iterator<VariableDeclarationStatement> iter = fLocals.iterator(); iter.hasNext(); ) {
ASTNode element = iter.next();
fListRewrite.insertAt(element, fInsertionIndex++, textEditGroup);
}
}
use of org.eclipse.jdt.core.dom.VariableDeclarationStatement in project che by eclipse.
the class TempDeclarationFinder method findTempDeclaration.
/**
* @return <code>null</code> if the selection is invalid or does not cover a temp
* declaration or reference.
*/
public static VariableDeclaration findTempDeclaration(CompilationUnit cu, int selectionOffset, int selectionLength) {
TempSelectionAnalyzer analyzer = new TempSelectionAnalyzer(selectionOffset, selectionLength);
cu.accept(analyzer);
ASTNode[] selected = analyzer.getSelectedNodes();
if (selected == null || selected.length != 1)
return null;
ASTNode selectedNode = selected[0];
if (selectedNode instanceof VariableDeclaration)
return (VariableDeclaration) selectedNode;
if (selectedNode instanceof Name) {
Name reference = (Name) selectedNode;
IBinding binding = reference.resolveBinding();
if (binding == null)
return null;
ASTNode declaringNode = cu.findDeclaringNode(binding);
if (declaringNode instanceof VariableDeclaration)
return (VariableDeclaration) declaringNode;
else
return null;
} else if (selectedNode instanceof VariableDeclarationStatement) {
VariableDeclarationStatement vds = (VariableDeclarationStatement) selectedNode;
if (vds.fragments().size() != 1)
return null;
return (VariableDeclaration) vds.fragments().get(0);
}
return null;
}
Aggregations