use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class ImportRemover method applyRemoves.
public void applyRemoves(ImportRewrite importRewrite) {
IBinding[] bindings = getImportsToRemove();
for (int i = 0; i < bindings.length; i++) {
if (bindings[i] instanceof ITypeBinding) {
ITypeBinding typeBinding = (ITypeBinding) bindings[i];
importRewrite.removeImport(typeBinding.getTypeDeclaration().getQualifiedName());
} else if (bindings[i] instanceof IMethodBinding) {
IMethodBinding binding = (IMethodBinding) bindings[i];
importRewrite.removeStaticImport(binding.getDeclaringClass().getQualifiedName() + '.' + binding.getName());
} else if (bindings[i] instanceof IVariableBinding) {
IVariableBinding binding = (IVariableBinding) bindings[i];
importRewrite.removeStaticImport(binding.getDeclaringClass().getQualifiedName() + '.' + binding.getName());
}
}
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class RemoveDeclarationCorrectionProposal method getName.
@Override
public String getName() {
IBinding binding = fName.resolveBinding();
String name = BasicElementLabels.getJavaElementName(fName.getIdentifier());
switch(binding.getKind()) {
case IBinding.TYPE:
return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedtype_description, name);
case IBinding.METHOD:
if (((IMethodBinding) binding).isConstructor()) {
return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedconstructor_description, name);
} else {
return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedmethod_description, name);
}
case IBinding.VARIABLE:
if (((IVariableBinding) binding).isField()) {
return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedfield_description, name);
} else {
return Messages.format(CorrectionMessages.RemoveDeclarationCorrectionProposal_removeunusedvar_description, name);
}
default:
return super.getDisplayString();
}
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class BindingLabelProvider method getAdornmentFlags.
/*extends LabelProvider */
private static int getAdornmentFlags(IBinding binding) {
int adornments = 0;
final int modifiers = binding.getModifiers();
if (Modifier.isAbstract(modifiers))
adornments |= JavaElementImageDescriptor.ABSTRACT;
if (Modifier.isFinal(modifiers))
adornments |= JavaElementImageDescriptor.FINAL;
if (Modifier.isStatic(modifiers))
adornments |= JavaElementImageDescriptor.STATIC;
if (binding.isDeprecated())
adornments |= JavaElementImageDescriptor.DEPRECATED;
if (binding instanceof IMethodBinding) {
if (((IMethodBinding) binding).isConstructor())
adornments |= JavaElementImageDescriptor.CONSTRUCTOR;
if (Modifier.isSynchronized(modifiers))
adornments |= JavaElementImageDescriptor.SYNCHRONIZED;
if (Modifier.isNative(modifiers))
adornments |= JavaElementImageDescriptor.NATIVE;
ITypeBinding type = ((IMethodBinding) binding).getDeclaringClass();
if (type.isInterface() && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers))
adornments |= JavaElementImageDescriptor.DEFAULT_METHOD;
if (((IMethodBinding) binding).getDefaultValue() != null)
adornments |= JavaElementImageDescriptor.ANNOTATION_DEFAULT;
}
if (binding instanceof IVariableBinding && ((IVariableBinding) binding).isField()) {
if (Modifier.isTransient(modifiers))
adornments |= JavaElementImageDescriptor.TRANSIENT;
if (Modifier.isVolatile(modifiers))
adornments |= JavaElementImageDescriptor.VOLATILE;
}
return adornments;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class ExtractMethodRefactoring method replaceBranches.
private void replaceBranches(final CompilationUnitChange result) {
ASTNode[] selectedNodes = fAnalyzer.getSelectedNodes();
for (int i = 0; i < selectedNodes.length; i++) {
ASTNode astNode = selectedNodes[i];
astNode.accept(new ASTVisitor() {
private LinkedList<String> fOpenLoopLabels = new LinkedList<String>();
private void registerLoopLabel(Statement node) {
String identifier;
if (node.getParent() instanceof LabeledStatement) {
LabeledStatement labeledStatement = (LabeledStatement) node.getParent();
identifier = labeledStatement.getLabel().getIdentifier();
} else {
identifier = null;
}
fOpenLoopLabels.add(identifier);
}
@Override
public boolean visit(ForStatement node) {
registerLoopLabel(node);
return super.visit(node);
}
@Override
public void endVisit(ForStatement node) {
fOpenLoopLabels.removeLast();
}
@Override
public boolean visit(WhileStatement node) {
registerLoopLabel(node);
return super.visit(node);
}
@Override
public void endVisit(WhileStatement node) {
fOpenLoopLabels.removeLast();
}
@Override
public boolean visit(EnhancedForStatement node) {
registerLoopLabel(node);
return super.visit(node);
}
@Override
public void endVisit(EnhancedForStatement node) {
fOpenLoopLabels.removeLast();
}
@Override
public boolean visit(DoStatement node) {
registerLoopLabel(node);
return super.visit(node);
}
@Override
public void endVisit(DoStatement node) {
fOpenLoopLabels.removeLast();
}
@Override
public void endVisit(ContinueStatement node) {
final SimpleName label = node.getLabel();
if (fOpenLoopLabels.isEmpty() || (label != null && !fOpenLoopLabels.contains(label.getIdentifier()))) {
TextEditGroup description = new TextEditGroup(RefactoringCoreMessages.ExtractMethodRefactoring_replace_continue);
result.addTextEditGroup(description);
ReturnStatement rs = fAST.newReturnStatement();
IVariableBinding returnValue = fAnalyzer.getReturnValue();
if (returnValue != null) {
rs.setExpression(fAST.newSimpleName(getName(returnValue)));
}
fRewriter.replace(node, rs, description);
}
}
});
}
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class ExtractMethodRefactoring method createCallNodes.
//---- Code generation -----------------------------------------------------------------------
private ASTNode[] createCallNodes(SnippetFinder.Match duplicate, int modifiers) {
List<ASTNode> result = new ArrayList<ASTNode>(2);
IVariableBinding[] locals = fAnalyzer.getCallerLocals();
for (int i = 0; i < locals.length; i++) {
result.add(createDeclaration(locals[i], null));
}
MethodInvocation invocation = fAST.newMethodInvocation();
invocation.setName(fAST.newSimpleName(fMethodName));
ASTNode typeNode = ASTResolving.findParentType(fAnalyzer.getEnclosingBodyDeclaration());
RefactoringStatus status = new RefactoringStatus();
while (fDestination != typeNode) {
fAnalyzer.checkInput(status, fMethodName, typeNode);
if (!status.isOK()) {
SimpleName destinationTypeName = fAST.newSimpleName(ASTNodes.getEnclosingType(fDestination).getName());
if ((modifiers & Modifier.STATIC) == 0) {
ThisExpression thisExpression = fAST.newThisExpression();
thisExpression.setQualifier(destinationTypeName);
invocation.setExpression(thisExpression);
} else {
invocation.setExpression(destinationTypeName);
}
break;
}
typeNode = typeNode.getParent();
}
List<Expression> arguments = invocation.arguments();
for (int i = 0; i < fParameterInfos.size(); i++) {
ParameterInfo parameter = fParameterInfos.get(i);
arguments.add(ASTNodeFactory.newName(fAST, getMappedName(duplicate, parameter)));
}
if (fLinkedProposalModel != null) {
LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
nameGroup.addPosition(fRewriter.track(invocation.getName()), false);
}
ASTNode call;
int returnKind = fAnalyzer.getReturnKind();
switch(returnKind) {
case ExtractMethodAnalyzer.ACCESS_TO_LOCAL:
IVariableBinding binding = fAnalyzer.getReturnLocal();
if (binding != null) {
VariableDeclarationStatement decl = createDeclaration(getMappedBinding(duplicate, binding), invocation);
call = decl;
} else {
Assignment assignment = fAST.newAssignment();
assignment.setLeftHandSide(ASTNodeFactory.newName(fAST, getMappedBinding(duplicate, fAnalyzer.getReturnValue()).getName()));
assignment.setRightHandSide(invocation);
call = assignment;
}
break;
case ExtractMethodAnalyzer.RETURN_STATEMENT_VALUE:
ReturnStatement rs = fAST.newReturnStatement();
rs.setExpression(invocation);
call = rs;
break;
default:
call = invocation;
}
if (call instanceof Expression && !fAnalyzer.isExpressionSelected()) {
call = fAST.newExpressionStatement((Expression) call);
}
result.add(call);
// return;
if (returnKind == ExtractMethodAnalyzer.RETURN_STATEMENT_VOID && !fAnalyzer.isLastStatementSelected()) {
result.add(fAST.newReturnStatement());
}
return result.toArray(new ASTNode[result.size()]);
}
Aggregations