List of usage examples for org.eclipse.jdt.core.dom SimpleName resolveBinding
public final IBinding resolveBinding()
From source file:br.uff.ic.mergeguider.javaparser.DepVisitor.java
@Override public boolean visit(SimpleName node) { IBinding binding = node.resolveBinding(); if (binding instanceof IVariableBinding) { simpleNamesList.get(simpleNamesList.size() - 1).add(node); }// w ww. j a v a 2 s. c o m // else if (binding instanceof IAnnotationBinding) { // System.out.println("Not trated yet!"); // } else if (binding instanceof IMemberValuePairBinding) { // System.out.println("Not trated yet!"); // } else if (binding instanceof IMethodBinding) { // System.out.println("Not trated yet!"); // } else if (binding instanceof IPackageBinding) { // System.out.println("Not trated yet!"); // } else if (binding instanceof ITypeBinding) { // simpleNamesList.get(simpleNamesList.size() - 1).add(node); // } return true; }
From source file:br.uff.ic.mergeguider.javaparser.DepVisitor.java
public void treatingSimpleName(SimpleName node) { IBinding simpleNameBinding = node.resolveBinding(); if (simpleNameBinding == null) { return;/* w w w. j a v a2 s. c o m*/ } //Treating Variable or Attribute if (simpleNameBinding instanceof IVariableBinding || simpleNameBinding instanceof ITypeBinding) { //Treating Attribute for (MyAttributeDeclaration attribute : classLanguageConstructsList .get(classLanguageConstructsList.size() - 1).getAttributes()) { IVariableBinding attributeBinding = attribute.getFieldDeclaration().resolveBinding(); if (attributeBinding == null) { continue; } if (simpleNameBinding.equals(attributeBinding)) { int elementLineBegin = cu.getLineNumber(node.getStartPosition()); int elementLineEnd = cu.getLineNumber(node.getStartPosition() + node.getLength()); int elementColumnBegin = cu.getColumnNumber(node.getStartPosition()); int elementColumnEnd = cu.getColumnNumber(node.getStartPosition() + node.getLength()); Location location = new Location(elementLineBegin, elementLineEnd, elementColumnBegin, elementColumnEnd); if (!attribute.getLocation().contains(location)) { MyAttributeCall myAttributeCall = new MyAttributeCall(node, location); if (!classLanguageConstructsList.isEmpty()) { classLanguageConstructsList.get(classLanguageConstructsList.size() - 1) .getAttributeCalls().add(myAttributeCall); } } } } //Treating variables for (MyVariableDeclaration variableDeclaration : classLanguageConstructsList .get(classLanguageConstructsList.size() - 1).getVariableDeclarations()) { IVariableBinding attributeBinding = variableDeclaration.resolveBinding(); if (attributeBinding == null) { continue; } if (simpleNameBinding.equals(attributeBinding)) { int elementLineBegin = cu.getLineNumber(node.getStartPosition()); int elementLineEnd = cu.getLineNumber(node.getStartPosition() + node.getLength()); int elementColumnBegin = cu.getColumnNumber(node.getStartPosition()); int elementColumnEnd = cu.getColumnNumber(node.getStartPosition() + node.getLength()); Location location = new Location(elementLineBegin, elementLineEnd, elementColumnBegin, elementColumnEnd); if (!variableDeclaration.getLocation().contains(location)) { MyVariableCall myVariableCall = new MyVariableCall(node, location); classLanguageConstructsList.get(classLanguageConstructsList.size() - 1).getVariableCalls() .add(myVariableCall); } } } } }
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;/* ww w. j a va 2 s . co m*/ }
From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java
License:Open Source License
@Override public boolean visit(final SimpleName pNode) { final IBinding lBinding = pNode.resolveBinding(); if (lBinding == null) // Occurs for all labels (e.g., loop labels) // log( "Null binding 4 for " + pNode ); return false; if (lBinding.getKind() == IBinding.VARIABLE) if (((IVariableBinding) lBinding).isField()) { this.addAccessRelation((IVariableBinding) lBinding); final Assignment assignment = ASTCrawler.getAssignment(pNode); if (assignment != null) { this.addSetsRelation((IVariableBinding) lBinding); if (!(assignment.getOperator() == Assignment.Operator.ASSIGN)) this.addGetsRelation((IVariableBinding) lBinding); } else this.addGetsRelation((IVariableBinding) lBinding); }//from w w w . j a va2 s.c om return false; }
From source file:ca.mcgill.cs.swevo.ppa.inference.FieldInferenceStrategy.java
License:Open Source License
public boolean isSafe(ASTNode node) { boolean isSafe = hasDeclaration(node); if (!isSafe) { SimpleName sName = (SimpleName) node; IVariableBinding varBinding = (IVariableBinding) sName.resolveBinding(); ITypeBinding container = varBinding.getDeclaringClass(); isSafe = container == null/* w w w . ja v a 2 s . c om*/ || (!PPABindingsUtil.isMissingType(container) && !PPABindingsUtil.isUnknownType(container)); } return isSafe; }
From source file:ca.mcgill.cs.swevo.ppa.inference.FieldInferenceStrategy.java
License:Open Source License
public void makeSafe(ASTNode node, TypeFact typeFact) { SimpleName sName = (SimpleName) node; PPATypeRegistry typeRegistry = ppaEngine.getRegistry(); PPADefaultBindingResolver resolver = getResolver(sName); // The field's type changed. if (typeFact.getIndex().equals(getMainIndex(node))) { IVariableBinding varBinding = (IVariableBinding) sName.resolveBinding(); ITypeBinding newType = typeFact.getNewType(); IVariableBinding newBinding = typeRegistry.getFieldBindingWithType(varBinding.getName(), varBinding.getDeclaringClass(), newType, resolver); resolver.fixFieldBinding(sName, newBinding); }/*from ww w.j a va 2 s . c o m*/ // The field's container changed. // else { // // // // // } }
From source file:ca.mcgill.cs.swevo.ppa.inference.FieldInferenceStrategy.java
License:Open Source License
public void makeSafeSecondary(ASTNode node, TypeFact typeFact) { SimpleName sName = (SimpleName) node; PPATypeRegistry typeRegistry = ppaEngine.getRegistry(); PPADefaultBindingResolver resolver = getResolver(sName); ASTNode newContainerNode = PPAASTUtil.getFieldContainer(node, true, false); ITypeBinding newContainer = PPABindingsUtil.getTypeBinding(newContainerNode); if (newContainer == null) { return;/*from w ww. j a v a 2s .c om*/ } IVariableBinding varBinding = (IVariableBinding) sName.resolveBinding(); IVariableBinding newFieldBinding = null; if (PPABindingsUtil.isMissingType(newContainer)) { newFieldBinding = typeRegistry.getFieldBinding(varBinding.getName(), newContainer, varBinding.getType(), resolver); } else { // Maybe we can find the field declaration newFieldBinding = PPABindingsUtil.findFieldHierarchy(newContainer, sName.getFullyQualifiedName()); if (newFieldBinding == null) { // We did not find the field in the container, try to find a suitable container (missing type) ITypeBinding tempContainer = PPABindingsUtil.getFirstMissingSuperType(newContainer); if (tempContainer != null) { newContainer = tempContainer; newFieldBinding = typeRegistry.getFieldBinding(varBinding.getName(), newContainer, varBinding.getType(), resolver); } else { newFieldBinding = typeRegistry.getFieldBinding(varBinding.getName(), newContainer, varBinding.getType(), resolver); } } else { // In case we found the field in a super type of the container. newContainer = newFieldBinding.getDeclaringClass(); } } // Check field type ITypeBinding newFieldType = newFieldBinding.getType(); ITypeBinding oldFieldType = varBinding.getType(); if (!newFieldType.isEqualTo(oldFieldType)) { if (PPABindingsUtil.isSafer(newFieldType, oldFieldType)) { resolver.fixFieldBinding(sName, newFieldBinding); TypeFact tFact = new TypeFact(indexer.getMainIndex(sName), oldFieldType, TypeFact.UNKNOWN, newFieldType, TypeFact.EQUALS, TypeFact.FIELD_STRATEGY); ppaEngine.reportTypeFact(tFact); } else if (!PPABindingsUtil.isMissingType(newContainer)) { resolver.fixFieldBinding(sName, newFieldBinding); // This is the case where we found the field declaration and the field is "less" safe than the previous type. // XXX The oldType = Unknown is to ensure that the new type will be pushed. TypeFact tFact = new TypeFact(indexer.getMainIndex(sName), typeRegistry.getUnknownBinding(resolver), TypeFact.UNKNOWN, newFieldType, TypeFact.EQUALS, TypeFact.FIELD_STRATEGY); ppaEngine.reportTypeFact(tFact); } else { // This is an odd case: we found a ppa generated field, but the type we got before was safer. newFieldBinding = typeRegistry.getFieldBindingWithType(varBinding.getName(), newContainer, varBinding.getType(), resolver); resolver.fixFieldBinding(sName, newFieldBinding); } } else { resolver.fixFieldBinding(sName, newFieldBinding); } }
From source file:ca.mcgill.cs.swevo.ppa.inference.FieldInferenceStrategy.java
License:Open Source License
@Override public PPAIndex getMainIndex(ASTNode node) { SimpleName sName = (SimpleName) node; IVariableBinding vBinding = (IVariableBinding) sName.resolveBinding(); return new PPAIndex(vBinding); }
From source file:ca.mcgill.cs.swevo.ppa.PPAIndexer.java
License:Open Source License
public int getNodeType(ASTNode node) { int type = node.getNodeType(); if (type == ASTNode.SIMPLE_NAME) { SimpleName sName = (SimpleName) node; IBinding binding = sName.resolveBinding(); if (binding != null) { if (binding instanceof IVariableBinding) { IVariableBinding varBinding = (IVariableBinding) binding; if (varBinding.isField()) { type = FIELD_TYPE;/*from w w w . j a v a 2 s . co m*/ } else { type = LOCAL_TYPE; } } else if (binding instanceof IMethodBinding) { type = METHOD_TYPE; } else if (binding instanceof ITypeBinding) { type = TYPE_TYPE; } } } return type; }
From source file:ca.mcgill.cs.swevo.ppa.ui.NameMapVisitor.java
License:Open Source License
@Override public void postVisit(ASTNode node) { super.postVisit(node); if (node instanceof Expression) { Expression exp = (Expression) node; // XXX Unfortunately, looking for both name and mi and ci will // result in duplicate. // This is not a problem since we use a set, but for a true // estimation of the number of // types used, // Another strategy should be used... IBinding binding = null;//from ww w .j av a2s. co m if (exp instanceof SimpleName) { SimpleName name = (SimpleName) exp; binding = name.resolveBinding(); addBindingText(binding, name, isDeclaration(name)); } else { return; } } }