List of usage examples for org.eclipse.jdt.core.dom IVariableBinding getModifiers
public int getModifiers();
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isStatic(IVariableBinding variableBinding) { if (isInterfaceOrAnnotationMember(variableBinding)) return true; return Modifier.isStatic(variableBinding.getModifiers()); }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
/** * Add an ACCESS relation and its transpose between aCurrentMethod and the * field described by pBinding. If any problem is detected the relation is * not added and the error is logged.//from w w w . j a v a 2 s. c om * * @param pBinding * The field to add a relation to. * @pre aCurrMethod is not null * @pre aCurrMethod is in the database * @pre pBinding is not null */ private void addAccessRelation(final IVariableBinding pBinding) { // assert (pBinding != null); // assert (aDB.contains(aCurrMethod)); // assert (aCurrMethod != null); if (pBinding.getDeclaringClass() == null) // This is most likely an access to the length // field of an array. return; final IElement lField = ASTCrawler.convertBinding(pBinding); this.aDB.addElement(lField, pBinding.getModifiers()); this.aDB.addRelationAndTranspose(this.aCurrMethod, Relation.ACCESSES, lField); }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
private void addGetsRelation(final IVariableBinding pBinding) { // assert (pBinding != null); // assert (aDB.contains(aCurrMethod)); // assert (aCurrMethod != null); if (pBinding.getDeclaringClass() == null) // This is most likely an access to the length // field of an array. return;/* w w w. j av a 2 s . c o m*/ final IElement lField = ASTCrawler.convertBinding(pBinding); this.aDB.addElement(lField, pBinding.getModifiers()); this.aDB.addRelationAndTranspose(this.aCurrMethod, Relation.GETS, lField); }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
private void addSetsRelation(final IVariableBinding pBinding) { // assert (pBinding != null); // assert (aDB.contains(aCurrMethod)); // assert (aCurrMethod != null); if (pBinding.getDeclaringClass() == null) // This is most likely an access to the length // field of an array. return;//from ww w .ja va2 s . c o m final IElement lField = ASTCrawler.convertBinding(pBinding); this.aDB.addElement(lField, pBinding.getModifiers()); this.aDB.addRelationAndTranspose(this.aCurrMethod, Relation.SETS, lField); }
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./*from w w w .ja v a 2 s. co m*/ * * @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.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.SimpleName node) { IBinding binding = node.resolveBinding(); SimpleIdentifier result = identifier(node.getIdentifier()); putReference(binding, result);/*w w w .j av a 2s . c o m*/ // may be statically imported field, generate PropertyAccess { org.eclipse.jdt.core.dom.StructuralPropertyDescriptor locationInParent = node.getLocationInParent(); if (binding instanceof IVariableBinding) { org.eclipse.jdt.core.dom.IVariableBinding variableBinding = (org.eclipse.jdt.core.dom.IVariableBinding) binding; org.eclipse.jdt.core.dom.ASTNode parent = node.getParent(); if (locationInParent == org.eclipse.jdt.core.dom.EnumConstantDeclaration.ARGUMENTS_PROPERTY || locationInParent == org.eclipse.jdt.core.dom.ClassInstanceCreation.ARGUMENTS_PROPERTY || locationInParent == org.eclipse.jdt.core.dom.MethodInvocation.ARGUMENTS_PROPERTY || locationInParent == org.eclipse.jdt.core.dom.ConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == org.eclipse.jdt.core.dom.SuperConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == org.eclipse.jdt.core.dom.Assignment.RIGHT_HAND_SIDE_PROPERTY || locationInParent == org.eclipse.jdt.core.dom.SwitchCase.EXPRESSION_PROPERTY || parent instanceof org.eclipse.jdt.core.dom.InfixExpression || parent instanceof org.eclipse.jdt.core.dom.ConditionalExpression || parent instanceof org.eclipse.jdt.core.dom.ReturnStatement) { ITypeBinding declaringBinding = variableBinding.getDeclaringClass(); ITypeBinding enclosingBinding = getEnclosingTypeBinding(node); if (declaringBinding != null && enclosingBinding != declaringBinding && org.eclipse.jdt.core.dom.Modifier.isStatic(variableBinding.getModifiers())) { SimpleIdentifier target = identifier(declaringBinding.getName()); putReference(declaringBinding, target); return done(propertyAccess(target, result)); } } } } // may be statically imported method, generate PrefixedIdentifier { org.eclipse.jdt.core.dom.StructuralPropertyDescriptor locationInParent = node.getLocationInParent(); if (binding instanceof IMethodBinding) { IMethodBinding methodBinding = (IMethodBinding) binding; if (locationInParent == org.eclipse.jdt.core.dom.MethodInvocation.NAME_PROPERTY && ((org.eclipse.jdt.core.dom.MethodInvocation) node.getParent()).getExpression() == null) { ITypeBinding declaringBinding = methodBinding.getDeclaringClass(); ITypeBinding enclosingBinding = getEnclosingTypeBinding(node); if (declaringBinding != null && enclosingBinding != declaringBinding && org.eclipse.jdt.core.dom.Modifier.isStatic(methodBinding.getModifiers())) { SimpleIdentifier prefix = identifier(declaringBinding.getName()); putReference(declaringBinding, prefix); return done(identifier(prefix, result)); } } } } // done return done(result); }
From source file:com.google.devtools.cyclefinder.ReferenceGraph.java
License:Apache License
private void addFieldEdges() { for (ITypeBinding type : allTypes.values()) { for (IVariableBinding field : type.getDeclaredFields()) { ITypeBinding fieldType = getElementType(field.getType()); if (!whitelist.containsField(field) && !whitelist.containsType(fieldType) && !fieldType.isPrimitive() && !Modifier.isStatic(field.getModifiers()) // Exclude self-referential fields. (likely linked DS or delegate pattern) && !type.isAssignmentCompatible(fieldType) && !BindingUtil.isWeakReference(field)) { addEdge(Edge.newFieldEdge(type, field)); }/*from w w w . ja va 2 s . c o m*/ } } }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
private boolean isProperty(SimpleName name) { IVariableBinding var = Types.getVariableBinding(name); if (!var.isField() || Modifier.isStatic(var.getModifiers())) { return false; }// w w w . j a va 2 s .c om int parentNodeType = name.getParent().getNodeType(); if (parentNodeType == ASTNode.QUALIFIED_NAME && name == ((QualifiedName) name.getParent()).getQualifier()) { // This case is for arrays, with property.length references. return true; } return parentNodeType != ASTNode.FIELD_ACCESS && parentNodeType != ASTNode.QUALIFIED_NAME; }
From source file:com.google.devtools.j2cpp.gen.HiddenFieldDetector.java
License:Open Source License
private void addFields(ITypeBinding binding, boolean includePrivate, Set<String> names) { for (IVariableBinding field : binding.getDeclaredFields()) { if (includePrivate || (field.getModifiers() & Modifier.PRIVATE) == 0) { names.add(NameTable.javaFieldToCpp(field.getName())); }/*from ww w.ja va 2 s. c o m*/ } ITypeBinding superType = binding.getSuperclass(); if (superType != null) { addFields(superType, false, names); } }
From source file:com.google.devtools.j2cpp.translate.AnonymousClassConverter.java
License:Open Source License
/** * Returns the set of read-only variables (parameters and local variables) * defined in the scope of the method enclosing a specified anonymous * class declaration.//w w w . j av a 2s. c o m */ private Set<IVariableBinding> getMethodVars(AnonymousClassDeclaration node) { final Set<IVariableBinding> methodVars = Sets.newHashSet(); MethodDeclaration method = getEnclosingMethod(node); if (method != null) { @SuppressWarnings("unchecked") List<SingleVariableDeclaration> params = method.parameters(); // safe by definition for (SingleVariableDeclaration param : params) { IVariableBinding var = Types.getVariableBinding(param); assert var != null; if (Modifier.isFinal(var.getModifiers())) { methodVars.add(var); } } ASTNode lastNode = node; do { getMethodVars(method, lastNode, methodVars); lastNode = method; method = getEnclosingMethod(lastNode); } while (method != null); } return methodVars; }