List of usage examples for org.eclipse.jdt.core.dom IMethodBinding getModifiers
public int getModifiers();
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isDefaultMethod(IMethodBinding method) { int modifiers = method.getModifiers(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=405517#c7 ITypeBinding declaringClass = method.getDeclaringClass(); if (declaringClass.isInterface()) { return !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers); }/*from w w w .ja v a 2s. c o m*/ return false; }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isAbstract(IMethodBinding member) { return Modifier.isAbstract(member.getModifiers()); }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isStatic(IMethodBinding methodBinding) { return Modifier.isStatic(methodBinding.getModifiers()); }
From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java
License:Open Source License
private IMethodBinding findReferenceMethod(ITypeBinding componentClass, ITypeBinding serviceType, String name) { ITypeBinding testedClass = componentClass; IMethodBinding candidate = null;/* ww w . j av a 2s.c o m*/ int priority = 0; // priority: // 0: <assignment-compatible-type>, Map // 1: <exact-type>, Map // 2: <assignment-compatible-type> // 3: <exact-type> do { for (IMethodBinding declaredMethod : testedClass.getDeclaredMethods()) { if (name.equals(declaredMethod.getName()) && Void.TYPE.getName().equals(declaredMethod.getReturnType().getName()) && (testedClass.isEqualTo(componentClass) || Modifier.isPublic(declaredMethod.getModifiers()) || Modifier.isProtected(declaredMethod.getModifiers()) || (!Modifier.isPrivate(declaredMethod.getModifiers()) && testedClass.getPackage().isEqualTo(componentClass.getPackage())))) { ITypeBinding[] paramTypes = declaredMethod.getParameterTypes(); if (paramTypes.length == 1) { if (ServiceReference.class.getName().equals(paramTypes[0].getErasure().getQualifiedName())) // we have the winner return declaredMethod; if (priority < 3 && serviceType.isEqualTo(paramTypes[0])) priority = 3; else if (priority < 2 && serviceType.isAssignmentCompatible(paramTypes[0])) priority = 2; else continue; // we have a (better) candidate candidate = declaredMethod; } else if (paramTypes.length == 2) { if (priority < 1 && serviceType.isEqualTo(paramTypes[0]) && Map.class.getName().equals(paramTypes[1].getErasure().getQualifiedName())) priority = 1; else if (candidate != null || !serviceType.isAssignmentCompatible(paramTypes[0]) || !Map.class.getName().equals(paramTypes[1].getErasure().getQualifiedName())) continue; // we have a candidate candidate = declaredMethod; } } } } while ((testedClass = testedClass.getSuperclass()) != null); return candidate; }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@Override public boolean visit(final MethodInvocation pNode) { final SimpleName lName = pNode.getName(); final IBinding lBinding = lName.resolveBinding(); if (ASTCrawler.checkForNull(lBinding)) return false; final IMethodBinding lMethod = (IMethodBinding) lBinding; this.addCallRelation(pNode, lMethod, Modifier.isStatic(lMethod.getModifiers())); return true;/*from w w w .j a v a2 s. co m*/ }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
private void addCallRelation(final ASTNode pNode, final IMethodBinding pBinding, final boolean pStatic) { // assert( pBinding != null ); TODO if (this.aCurrMethod == null) // constructors calling itself. Ignore it. return;/* w w w . j a va2s.c o m*/ // lAcceptor could be a Java.util method if (pBinding == null) return; final IElement lAcceptor = ASTCrawler.convertBinding(pBinding); final IElement lCaller = this.aCurrMethod; // lCaller instanceof IClassElement // lAcceptor instanceof IMethodElement int lModifiers = pBinding.getModifiers(); if (pBinding.getDeclaringClass().isInterface() || Modifier.isAbstract(lModifiers)) lModifiers = lModifiers | ASTCrawler.ABSTRACT_FLAG; this.aDB.addElement(lAcceptor, lModifiers); if (pStatic) this.aDB.addRelationAndTranspose(lCaller, Relation.STATIC_CALLS, lAcceptor); else this.aDB.addRelationAndTranspose(lCaller, Relation.CALLS, lAcceptor); }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
private void saveMethodRelation(final IMethodBinding pMBinding) { if (this.aCurrMethod != null) this.aCurrMethodReminder.push(this.aCurrMethod); this.aCurrMethod = (MethodElement) ASTCrawler.convertBinding(pMBinding); int lModifiers = pMBinding.getModifiers(); if (pMBinding.getDeclaringClass().isInterface() || Modifier.isAbstract(lModifiers)) lModifiers = lModifiers | ASTCrawler.ABSTRACT_FLAG; this.aDB.addElement(this.aCurrMethod, lModifiers); }
From source file:ca.mcgill.cs.swevo.ppa.PPAASTUtil.java
License:Open Source License
/** * //w ww . j a v a2s .c o m * @param mi * @return True if this is a final method from Object */ private static boolean checkObjectFinalMethod(MethodInvocation mi) { boolean isObjectFinal = false; IMethodBinding mb = mi.resolveMethodBinding(); if (mb != null) { isObjectFinal = Modifier.isFinal(mb.getModifiers()) && mb.getDeclaringClass().getQualifiedName().equals(OBJECT_FQN); } return isObjectFinal; }
From source file:com.android.ide.eclipse.adt.internal.refactorings.extractstring.ReplaceStringsVisitor.java
License:Open Source License
/** * Find all method or fields that are candidates for providing a Context. * There can be various choices amongst this class or its super classes. * Sort them by rating in the results map. * * The best ever choice is to find a method with no argument that returns a Context. * The second suitable choice is to find a Context field. * The least desirable choice is to find a method with arguments. It's not really * desirable since we can't generate these arguments automatically. * * Methods and fields from supertypes are ignored if they are private. * * The rating is reversed: the lowest rating integer is used for the best candidate. * Because the superType argument is actually a recursion index, this makes the most * immediate classes more desirable.//ww w . j a va 2s. com * * @param results The map that accumulates the rating=>expression results. The lower * rating number is the best candidate. * @param clazzType The class examined. * @param superType The recursion index. * 0 for the immediate class, 1 for its super class, etc. */ private void findContextCandidates(TreeMap<Integer, Expression> results, ITypeBinding clazzType, int superType) { for (IMethodBinding mb : clazzType.getDeclaredMethods()) { // If we're looking at supertypes, we can't use private methods. if (superType != 0 && Modifier.isPrivate(mb.getModifiers())) { continue; } if (isAndroidContext(mb.getReturnType())) { // We found a method that returns something derived from Context. int argsLen = mb.getParameterTypes().length; if (argsLen == 0) { // We'll favor any method that takes no argument, // That would be the best candidate ever, so we can stop here. MethodInvocation mi = mAst.newMethodInvocation(); mi.setName(mAst.newSimpleName(mb.getName())); results.put(Integer.MIN_VALUE, mi); return; } else { // A method with arguments isn't as interesting since we wouldn't // know how to populate such arguments. We'll use it if there are // no other alternatives. We'll favor the one with the less arguments. Integer rating = Integer.valueOf(10000 + 1000 * superType + argsLen); if (!results.containsKey(rating)) { MethodInvocation mi = mAst.newMethodInvocation(); mi.setName(mAst.newSimpleName(mb.getName())); results.put(rating, mi); } } } } // A direct Context field would be more interesting than a method with // arguments. Try to find one. for (IVariableBinding var : clazzType.getDeclaredFields()) { // If we're looking at supertypes, we can't use private field. if (superType != 0 && Modifier.isPrivate(var.getModifiers())) { continue; } if (isAndroidContext(var.getType())) { // We found such a field. Let's use it. Integer rating = Integer.valueOf(superType); results.put(rating, mAst.newSimpleName(var.getName())); break; } } // Examine the super class to see if we can locate a better match clazzType = clazzType.getSuperclass(); if (clazzType != null) { findContextCandidates(results, clazzType, superType + 1); } }
From source file:com.dnw.plugin.ast.AstUtil.java
License:Open Source License
/** * Method nameOf.// w ww . j a v a 2 s .co m * * @author manbaum * @since Oct 10, 2014 * @param method * @return */ public final static String nameOf(IMethodBinding method) { StringBuffer sb = new StringBuffer(); sb.append(nameOf(method.getDeclaringClass())); sb.append(Modifier.isStatic(method.getModifiers()) ? '/' : '#'); sb.append(method.getName()); sb.append('('); boolean first = true; for (ITypeBinding t : method.getParameterTypes()) { if (first) { first = false; } else { sb.append(','); } sb.append(nameOf(t)); } sb.append(')'); return sb.toString(); }