use of org.eclipse.jdt.core.dom.IMethodBinding in project xtext-xtend by eclipse.
the class ASTFlattenerUtils method findOverride.
public IMethodBinding findOverride(final IMethodBinding method, final ITypeBinding type, final boolean onlyPrimarylevel) {
final ITypeBinding superclass = type.getSuperclass();
IMethodBinding overridden = null;
if ((superclass != null)) {
overridden = this.internalFindOverride(method, superclass, onlyPrimarylevel);
}
if ((overridden == null)) {
ITypeBinding[] _interfaces = type.getInterfaces();
for (final ITypeBinding interfaze : _interfaces) {
{
overridden = this.internalFindOverride(method, interfaze, onlyPrimarylevel);
if ((overridden != null)) {
return overridden;
}
}
}
}
return overridden;
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project xtext-xtend by eclipse.
the class ASTFlattenerUtils method isOverrideMethod.
public boolean isOverrideMethod(final MethodDeclaration declaration) {
final Function1<Annotation, Boolean> _function = (Annotation it) -> {
String _string = it.getTypeName().toString();
return Boolean.valueOf(Objects.equal("Override", _string));
};
boolean _exists = IterableExtensions.<Annotation>exists(Iterables.<Annotation>filter(declaration.modifiers(), Annotation.class), _function);
if (_exists) {
return true;
}
final IMethodBinding iMethodBinding = declaration.resolveBinding();
if ((iMethodBinding != null)) {
IMethodBinding _findOverride = this.findOverride(iMethodBinding, iMethodBinding.getDeclaringClass());
return (_findOverride != null);
}
return false;
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project AutoRefactor by JnRouvignac.
the class ReplaceQualifiedNamesBySimpleNamesRefactoring method visit.
@Override
public boolean visit(MethodInvocation node) {
final Expression expr = node.getExpression();
final IMethodBinding methodBinding = node.resolveMethodBinding();
if (methodBinding != null && expr instanceof Name && hasKind((Name) expr, TYPE) && node.typeArguments().isEmpty()) {
final ITypeBinding declaringClass = methodBinding.getDeclaringClass();
final QName qname = QName.valueOf(declaringClass.getErasure().getQualifiedName(), methodBinding.getName());
if (methods.canReplaceFqnWithSimpleName(node, qname, FqnType.METHOD)) {
ctx.getRefactorings().remove(expr);
return DO_NOT_VISIT_SUBTREE;
}
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project AutoRefactor by JnRouvignac.
the class CFGBuilder method addVariableAccess.
/**
* @return whether the current variable access can throw an exception.
*/
@SuppressWarnings("unchecked")
private boolean addVariableAccess(CFGBasicBlock basicBlock, Expression node, int flags, ThrowerBlocks throwers) {
if (node == null) {
return false;
}
switch(node.getNodeType()) {
case ARRAY_ACCESS:
ArrayAccess aa = (ArrayAccess) node;
addVariableAccess(basicBlock, aa.getArray(), flags, throwers);
addVariableAccess(basicBlock, aa.getIndex(), flags, throwers);
throwers.addThrow(aa, newException(node, "java.lang.ArrayIndexOutOfBoundsException"));
return true;
case ARRAY_CREATION:
ArrayCreation ac = (ArrayCreation) node;
boolean acMightThrow1 = addVariableAccess(basicBlock, ac.getInitializer(), flags, throwers);
boolean acMightThrow2 = addVariableAccesses(basicBlock, ac.dimensions(), flags, throwers);
return acMightThrow1 || acMightThrow2;
case ARRAY_INITIALIZER:
ArrayInitializer ai = (ArrayInitializer) node;
return addVariableAccesses(basicBlock, ai.expressions(), flags, throwers);
case ASSIGNMENT:
Assignment a = (Assignment) node;
boolean aMightThrow1 = addVariableAccess(basicBlock, a.getLeftHandSide(), WRITE, throwers);
boolean aMightThrow2 = addVariableAccess(basicBlock, a.getRightHandSide(), READ, throwers);
return aMightThrow1 || aMightThrow2;
case BOOLEAN_LITERAL:
case CHARACTER_LITERAL:
case NULL_LITERAL:
case NUMBER_LITERAL:
case STRING_LITERAL:
case TYPE_LITERAL:
// nothing to do
return false;
case CAST_EXPRESSION:
CastExpression cae = (CastExpression) node;
return addVariableAccess(basicBlock, cae.getExpression(), flags, throwers);
case CLASS_INSTANCE_CREATION:
ClassInstanceCreation cic = (ClassInstanceCreation) node;
addVariableAccess(basicBlock, cic.getExpression(), flags, throwers);
addVariableAccesses(basicBlock, cic.arguments(), flags, throwers);
IMethodBinding cicBinding = cic.resolveConstructorBinding();
if (cicBinding != null) {
ITypeBinding[] declaredThrows = cicBinding.getExceptionTypes();
throwers.addThrow(cic, declaredThrows);
return declaredThrows.length > 0;
}
return false;
case CONDITIONAL_EXPRESSION:
ConditionalExpression coe = (ConditionalExpression) node;
boolean mightThrow1 = addVariableAccess(basicBlock, coe.getExpression(), flags, throwers);
boolean mightThrow2 = addVariableAccess(basicBlock, coe.getThenExpression(), flags, throwers);
boolean mightThrow3 = addVariableAccess(basicBlock, coe.getElseExpression(), flags, throwers);
return mightThrow1 || mightThrow2 || mightThrow3;
case FIELD_ACCESS:
FieldAccess fa = (FieldAccess) node;
boolean mightThrow = addVariableAccess(basicBlock, fa.getExpression(), flags, throwers);
basicBlock.addVariableAccess(new VariableAccess(fa, flags));
if (is(flags, READ)) {
throwers.addThrow(fa, newException(node, "java.lang.NullPointerException"));
mightThrow = true;
}
return mightThrow;
case INFIX_EXPRESSION:
InfixExpression ie = (InfixExpression) node;
boolean ieMightThrow1 = addVariableAccess(basicBlock, ie.getLeftOperand(), flags, throwers);
boolean ieMightThrow2 = addVariableAccess(basicBlock, ie.getRightOperand(), flags, throwers);
return ieMightThrow1 || ieMightThrow2;
case INSTANCEOF_EXPRESSION:
InstanceofExpression ioe = (InstanceofExpression) node;
return addVariableAccess(basicBlock, ioe.getLeftOperand(), flags, throwers);
case METHOD_INVOCATION:
MethodInvocation mi = (MethodInvocation) node;
addVariableAccess(basicBlock, mi.getExpression(), flags, throwers);
addVariableAccesses(basicBlock, mi.arguments(), flags, throwers);
IMethodBinding methodBinding = mi.resolveMethodBinding();
if (methodBinding != null) {
ITypeBinding[] declaredThrows = methodBinding.getExceptionTypes();
throwers.addThrow(mi, declaredThrows);
return declaredThrows.length > 0;
}
return false;
case SIMPLE_NAME:
SimpleName sn = (SimpleName) node;
basicBlock.addVariableAccess(new VariableAccess(sn, flags));
if (is(flags, READ)) {
throwers.addThrow(sn, newException(node, "java.lang.NullPointerException"));
return true;
}
return false;
case QUALIFIED_NAME:
QualifiedName qn = (QualifiedName) node;
basicBlock.addVariableAccess(new VariableAccess(qn, flags));
throwers.addThrow(qn, newException(node, "java.lang.NullPointerException"));
return true;
case PARENTHESIZED_EXPRESSION:
ParenthesizedExpression pe = (ParenthesizedExpression) node;
return addVariableAccess(basicBlock, pe.getExpression(), flags, throwers);
case POSTFIX_EXPRESSION:
PostfixExpression poe = (PostfixExpression) node;
return addVariableAccess(basicBlock, poe.getOperand(), flags, throwers);
case PREFIX_EXPRESSION:
PrefixExpression pre = (PrefixExpression) node;
return addVariableAccess(basicBlock, pre.getOperand(), flags, throwers);
case SUPER_FIELD_ACCESS:
SuperFieldAccess sfa = (SuperFieldAccess) node;
boolean sfaMightThrow1 = addVariableAccess(basicBlock, sfa.getQualifier(), flags, throwers);
boolean sfaMightThrow2 = addVariableAccess(basicBlock, sfa.getName(), flags, throwers);
return sfaMightThrow1 || sfaMightThrow2;
case SUPER_METHOD_INVOCATION:
SuperMethodInvocation smi = (SuperMethodInvocation) node;
addVariableAccess(basicBlock, smi.getQualifier(), flags, throwers);
addVariableAccess(basicBlock, smi.getName(), flags, throwers);
IMethodBinding sMethodBinding = smi.resolveMethodBinding();
if (sMethodBinding != null) {
ITypeBinding[] declaredThrows = sMethodBinding.getExceptionTypes();
throwers.addThrow(smi, declaredThrows);
return declaredThrows.length > 0;
}
return false;
case THIS_EXPRESSION:
ThisExpression te = (ThisExpression) node;
// TODO JNR remember use of "this" here
return addVariableAccess(basicBlock, te.getQualifier(), flags, throwers);
case VARIABLE_DECLARATION_EXPRESSION:
return addDeclarations(basicBlock, (VariableDeclarationExpression) node, throwers);
default:
throw new NotImplementedException(node);
}
}
use of org.eclipse.jdt.core.dom.IMethodBinding in project AutoRefactor by JnRouvignac.
the class ASTHelper method parameterizedTypesMatch.
private static boolean parameterizedTypesMatch(final ITypeBinding clazz, final ITypeBinding clazzErasure, IMethodBinding methodBinding) {
if (clazz.isParameterizedType() && !clazz.equals(clazzErasure)) {
final Map<ITypeBinding, ITypeBinding> genericToConcreteTypeParamsFromClass = getGenericToConcreteTypeParamsMap(clazz, clazzErasure);
for (IMethodBinding declaredMethod : clazzErasure.getDeclaredMethods()) {
if (declaredMethod.getName().equals(methodBinding.getName())) {
final Map<ITypeBinding, ITypeBinding> genericToConcreteTypeParams = getGenericToConcreteTypeParamsMap(methodBinding, declaredMethod);
genericToConcreteTypeParams.putAll(genericToConcreteTypeParamsFromClass);
if (parameterizedTypesMatch2(genericToConcreteTypeParams, methodBinding, declaredMethod)) {
return true;
}
}
}
}
return false;
}
Aggregations