List of usage examples for org.eclipse.jdt.core.dom Expression resolveTypeBinding
public final ITypeBinding resolveTypeBinding()
From source file:astview.ASTViewContentProvider.java
License:Open Source License
private Object[] getNodeChildren(ASTNode node) { ArrayList<Object> res = new ArrayList<>(); if (node instanceof Expression) { Expression expression = (Expression) node; ITypeBinding expressionTypeBinding = expression.resolveTypeBinding(); res.add(createExpressionTypeBinding(node, expressionTypeBinding)); // expressions: if (expression instanceof Name) { IBinding binding = ((Name) expression).resolveBinding(); if (binding != expressionTypeBinding) res.add(createBinding(expression, binding)); } else if (expression instanceof MethodInvocation) { MethodInvocation methodInvocation = (MethodInvocation) expression; IMethodBinding binding = methodInvocation.resolveMethodBinding(); res.add(createBinding(expression, binding)); String inferred = String.valueOf(methodInvocation.isResolvedTypeInferredFromExpectedType()); res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$ } else if (expression instanceof SuperMethodInvocation) { SuperMethodInvocation superMethodInvocation = (SuperMethodInvocation) expression; IMethodBinding binding = superMethodInvocation.resolveMethodBinding(); res.add(createBinding(expression, binding)); String inferred = String.valueOf(superMethodInvocation.isResolvedTypeInferredFromExpectedType()); res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$ } else if (expression instanceof ClassInstanceCreation) { ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression; IMethodBinding binding = classInstanceCreation.resolveConstructorBinding(); res.add(createBinding(expression, binding)); String inferred = String.valueOf(classInstanceCreation.isResolvedTypeInferredFromExpectedType()); res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$ } else if (expression instanceof FieldAccess) { IVariableBinding binding = ((FieldAccess) expression).resolveFieldBinding(); res.add(createBinding(expression, binding)); } else if (expression instanceof SuperFieldAccess) { IVariableBinding binding = ((SuperFieldAccess) expression).resolveFieldBinding(); res.add(createBinding(expression, binding)); } else if (expression instanceof Annotation) { IAnnotationBinding binding = ((Annotation) expression).resolveAnnotationBinding(); res.add(createBinding(expression, binding)); } else if (expression instanceof LambdaExpression) { ASTAttribute bindingAttribute; try { IMethodBinding binding = ((LambdaExpression) expression).resolveMethodBinding(); bindingAttribute = createBinding(expression, binding); } catch (RuntimeException e) { bindingAttribute = new Error(res, ">binding: Error: " + e.getMessage(), e); }// w w w. ja v a2 s . c om res.add(bindingAttribute); } else if (expression instanceof MethodReference) { IMethodBinding binding = ((MethodReference) expression).resolveMethodBinding(); res.add(createBinding(expression, binding)); } // Expression attributes: res.add(new GeneralAttribute(expression, "Boxing: " + expression.resolveBoxing() + "; Unboxing: " + expression.resolveUnboxing())); //$NON-NLS-1$ //$NON-NLS-2$ res.add(new GeneralAttribute(expression, "ConstantExpressionValue", //$NON-NLS-1$ expression.resolveConstantExpressionValue())); // references: } else if (node instanceof ConstructorInvocation) { IMethodBinding binding = ((ConstructorInvocation) node).resolveConstructorBinding(); res.add(createBinding(node, binding)); } else if (node instanceof SuperConstructorInvocation) { IMethodBinding binding = ((SuperConstructorInvocation) node).resolveConstructorBinding(); res.add(createBinding(node, binding)); } else if (node instanceof MethodRef) { IBinding binding = ((MethodRef) node).resolveBinding(); res.add(createBinding(node, binding)); } else if (node instanceof MemberRef) { IBinding binding = ((MemberRef) node).resolveBinding(); res.add(createBinding(node, binding)); } else if (node instanceof Type) { IBinding binding = ((Type) node).resolveBinding(); res.add(createBinding(node, binding)); // declarations: } else if (node instanceof AbstractTypeDeclaration) { IBinding binding = ((AbstractTypeDeclaration) node).resolveBinding(); res.add(createBinding(node, binding)); } else if (node instanceof AnnotationTypeMemberDeclaration) { IBinding binding = ((AnnotationTypeMemberDeclaration) node).resolveBinding(); res.add(createBinding(node, binding)); } else if (node instanceof EnumConstantDeclaration) { IBinding binding = ((EnumConstantDeclaration) node).resolveVariable(); res.add(createBinding(node, binding)); IBinding binding2 = ((EnumConstantDeclaration) node).resolveConstructorBinding(); res.add(createBinding(node, binding2)); } else if (node instanceof MethodDeclaration) { IBinding binding = ((MethodDeclaration) node).resolveBinding(); res.add(createBinding(node, binding)); } else if (node instanceof VariableDeclaration) { IBinding binding = ((VariableDeclaration) node).resolveBinding(); res.add(createBinding(node, binding)); } else if (node instanceof AnonymousClassDeclaration) { IBinding binding = ((AnonymousClassDeclaration) node).resolveBinding(); res.add(createBinding(node, binding)); } else if (node instanceof ImportDeclaration) { IBinding binding = ((ImportDeclaration) node).resolveBinding(); res.add(createBinding(node, binding)); } else if (node instanceof PackageDeclaration) { IBinding binding = ((PackageDeclaration) node).resolveBinding(); res.add(createBinding(node, binding)); } else if (node instanceof TypeParameter) { IBinding binding = ((TypeParameter) node).resolveBinding(); res.add(createBinding(node, binding)); } else if (node instanceof MemberValuePair) { IBinding binding = ((MemberValuePair) node).resolveMemberValuePairBinding(); res.add(createBinding(node, binding)); } @SuppressWarnings("unchecked") List<StructuralPropertyDescriptor> list = node.structuralPropertiesForType(); for (int i = 0; i < list.size(); i++) { StructuralPropertyDescriptor curr = list.get(i); res.add(new NodeProperty(node, curr)); } return res.toArray(); }
From source file:ca.mcgill.cs.swevo.ppa.inference.ArrayAccessInferenceStrategy.java
License:Open Source License
public void inferTypes(ASTNode node) { ArrayAccess aAccess = (ArrayAccess) node; // Expression exp1 = aAccess.getArray(); Expression exp2 = aAccess.getIndex(); if (!indexer.isSafe(exp2)) { ITypeBinding oldBinding = exp2.resolveTypeBinding(); ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("int", exp2); TypeFact tFact = new TypeFact(indexer.getMainIndex(exp2), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.ARRAY_STRATEGY); ppaEngine.reportTypeFact(tFact); }//from w w w . ja v a 2s . c o m }
From source file:ca.mcgill.cs.swevo.ppa.inference.ArrayAccessInferenceStrategy.java
License:Open Source License
public void makeSafe(ASTNode node, TypeFact typeFact) { ArrayAccess aAccess = (ArrayAccess) node; Expression exp1 = aAccess.getArray(); boolean isSafe = !PPABindingsUtil.isUnknownType(exp1.resolveTypeBinding()) && (indexer.isSafe(exp1)); ITypeBinding factType = typeFact != null ? typeFact.getNewType() : null; if (!isSafe && factType != null) { ITypeBinding newBinding = ppaEngine.getRegistry().getArrayTypeBinding(factType, exp1); ITypeBinding oldBinding = exp1.resolveTypeBinding(); TypeFact newTypeFact = new TypeFact(indexer.getMainIndex(exp1), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); ppaEngine.reportTypeFact(newTypeFact); }//from w w w. j a v a 2 s . c o m }
From source file:ca.mcgill.cs.swevo.ppa.inference.BinaryInferenceStrategy.java
License:Open Source License
private boolean isBoolean(Expression exp, boolean isSafe) { boolean isBoolean = false; if (isSafe) { ITypeBinding binding = exp.resolveTypeBinding(); if (binding != null && binding.getQualifiedName().equals("boolean")) { isBoolean = true;//from ww w .jav a2 s. co m } } return isBoolean; }
From source file:ca.mcgill.cs.swevo.ppa.inference.BinaryInferenceStrategy.java
License:Open Source License
private void processOperators(ASTNode node, TypeFact newFact) { InfixExpression infix = (InfixExpression) node; InfixExpression.Operator operator = infix.getOperator(); // if (node.toString().equals("falseTb == ShortBinding")) { // System.out.println(); // }/*from ww w . j av a 2 s .c om*/ Expression left = infix.getLeftOperand(); Expression right = infix.getRightOperand(); boolean isSecondaryIndex = newFact != null && isSecondary(node, newFact); boolean isPrimaryIndex = newFact != null && !isSecondaryIndex; boolean leftSafe = !PPABindingsUtil.isUnknownType(left.resolveTypeBinding()) && (indexer.isSafe(left) || (isSecondaryIndex && isLeftIndex(node, newFact))); boolean rightSafe = !PPABindingsUtil.isUnknownType(right.resolveTypeBinding()) && (indexer.isSafe(right) || (isSecondaryIndex && !isLeftIndex(node, newFact))); boolean leftBoolean = isBoolean(left, leftSafe); boolean rightBoolean = isBoolean(right, rightSafe); ITypeBinding newType = null; ITypeBinding factType = newFact != null ? newFact.getNewType() : null; boolean isNewType = true; // && and || if (operator == InfixExpression.Operator.CONDITIONAL_AND || operator == InfixExpression.Operator.CONDITIONAL_OR) { if (!leftSafe) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("boolean", left); ITypeBinding oldBinding = left.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(left), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); } if (!rightSafe) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("boolean", right); ITypeBinding oldBinding = right.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(right), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); } } // & and | else if (operator == InfixExpression.Operator.AND || operator == InfixExpression.Operator.CONDITIONAL_OR || operator == InfixExpression.Operator.XOR) { if (leftBoolean && !rightSafe) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("boolean", right); ITypeBinding oldBinding = right.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(right), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newType = newBinding; } else if (rightBoolean && !leftSafe) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("boolean", left); ITypeBinding oldBinding = left.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(left), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newType = newBinding; } else if (leftSafe && !rightSafe) { ITypeBinding newBinding = left.resolveTypeBinding(); ITypeBinding oldBinding = right.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(right), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newType = newBinding; } else if (rightSafe && !leftSafe) { ITypeBinding newBinding = right.resolveTypeBinding(); ITypeBinding oldBinding = left.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(left), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newType = newBinding; } else if (!rightSafe && !leftSafe && isPrimaryIndex) { ITypeBinding newBinding = factType; ITypeBinding oldBinding = left.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(left), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newBinding = factType; oldBinding = right.resolveTypeBinding(); typeFact = new TypeFact(indexer.getMainIndex(right), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newType = newBinding; } } // << >> >>> else if (operator == InfixExpression.Operator.LEFT_SHIFT || operator == InfixExpression.Operator.RIGHT_SHIFT_SIGNED || operator == InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED) { if (!leftSafe) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("int", left); ITypeBinding oldBinding = left.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(left), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); } if (!rightSafe) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("int", right); ITypeBinding oldBinding = right.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(right), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newType = newBinding; } } // - / * % < <= > >= else if (operator == InfixExpression.Operator.MINUS || operator == InfixExpression.Operator.DIVIDE || operator == InfixExpression.Operator.REMAINDER || operator == InfixExpression.Operator.TIMES || operator == InfixExpression.Operator.LESS || operator == InfixExpression.Operator.LESS_EQUALS || operator == InfixExpression.Operator.GREATER || operator == InfixExpression.Operator.GREATER_EQUALS) { if (leftSafe && !rightSafe) { ITypeBinding newBinding = left.resolveTypeBinding(); ITypeBinding oldBinding = right.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(right), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newType = newBinding; } else if (rightSafe && !leftSafe) { ITypeBinding newBinding = right.resolveTypeBinding(); ITypeBinding oldBinding = left.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(left), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newType = newBinding; } else if (!rightSafe && !leftSafe && !isPrimaryIndex) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("int", left); ITypeBinding oldBinding = left.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(left), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newBinding = ppaEngine.getRegistry().getPrimitiveBinding("int", right); oldBinding = right.resolveTypeBinding(); typeFact = new TypeFact(indexer.getMainIndex(right), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newType = newBinding; } else if (!rightSafe && !leftSafe && isPrimaryIndex) { ITypeBinding newBinding = factType; ITypeBinding oldBinding = left.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(left), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newBinding = factType; oldBinding = right.resolveTypeBinding(); typeFact = new TypeFact(indexer.getMainIndex(right), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); newType = newBinding; } } // == != else if (operator == InfixExpression.Operator.EQUALS || operator == InfixExpression.Operator.NOT_EQUALS) { if (leftSafe && !rightSafe) { ITypeBinding newBinding = left.resolveTypeBinding(); ITypeBinding oldBinding = right.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(right), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); } else if (rightSafe && !leftSafe) { ITypeBinding newBinding = right.resolveTypeBinding(); ITypeBinding oldBinding = left.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(left), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); } } // + else if (operator == InfixExpression.Operator.PLUS) { if (isPrimaryIndex && !factType.isPrimitive()) { ITypeBinding newBinding = factType; if (!leftSafe) { ITypeBinding oldBinding = left.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(left), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); } if (!rightSafe) { newBinding = factType; ITypeBinding oldBinding = right.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(right), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); isNewType = isNewType && ppaEngine.reportTypeFact(typeFact); } newType = newBinding; } } if (newType != null && !isPrimaryIndex && isNewType) { ITypeBinding oldBinding = infix.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(node), oldBinding, TypeFact.UNKNOWN, newType, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); ppaEngine.reportTypeFact(typeFact); // report new type for this expression. // fix this expression. } else if (isPrimaryIndex) { if (newType != null && isNewType) { ppaEngine.getRegistry().fixBinary(node, newType); } else if (factType != null) { ppaEngine.getRegistry().fixBinary(node, factType); } } }
From source file:ca.mcgill.cs.swevo.ppa.inference.ConditionInferenceStrategy.java
License:Open Source License
public void inferTypes(ASTNode node) { Expression exp = getExpression(node); if (!indexer.isSafe(exp)) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("boolean", exp); ITypeBinding oldBinding = exp.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(exp), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.CONDITION_STRATEGY); ppaEngine.reportTypeFact(typeFact); }/*from w ww . j ava2 s . co m*/ }
From source file:ca.mcgill.cs.swevo.ppa.inference.PostfixInferenceStrategy.java
License:Open Source License
private void processOperators(PostfixExpression node, TypeFact newFact) { ITypeBinding newType = null;/*w w w .j av a 2s. c o m*/ Expression exp = node.getOperand(); boolean isPrimary = newFact != null && indexer.getMainIndex(node).equals(newFact.getIndex()); boolean isSafe = indexer.isSafe(exp) || (newFact != null && !isPrimary); if (isPrimary && !isSafe) { ITypeBinding newBinding = newFact.getNewType(); ITypeBinding oldBinding = exp.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(exp), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.UNARY_STRATEGY); ppaEngine.reportTypeFact(typeFact); newType = newBinding; } else if (!isSafe) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("int", exp); ITypeBinding oldBinding = exp.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(exp), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.UNARY_STRATEGY); ppaEngine.reportTypeFact(typeFact); newType = newBinding; } if (newType != null && !isPrimary) { ITypeBinding oldBinding = node.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(node), oldBinding, TypeFact.UNKNOWN, newType, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); ppaEngine.reportTypeFact(typeFact); // report new type for this expression. // fix this expression. } else if (isPrimary) { if (newType != null) { ppaEngine.getRegistry().fixUnary(node, newType); } else if (newFact != null) { ppaEngine.getRegistry().fixUnary(node, newFact.getNewType()); } } }
From source file:ca.mcgill.cs.swevo.ppa.inference.PrefixInferenceStrategy.java
License:Open Source License
private void processOperators(PrefixExpression node, TypeFact newFact) { ITypeBinding newType = null;/*from ww w .j av a2 s. c o m*/ Expression exp = node.getOperand(); boolean isPrimary = newFact != null && indexer.getMainIndex(node).equals(newFact.getIndex()); boolean isSafe = indexer.isSafe(exp) || (newFact != null && !isPrimary); if (node.getOperator() != PrefixExpression.Operator.NOT) { if (isPrimary && !isSafe) { ITypeBinding newBinding = newFact.getNewType(); ITypeBinding oldBinding = exp.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(exp), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.UNARY_STRATEGY); ppaEngine.reportTypeFact(typeFact); newType = newBinding; } else if (!isSafe) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("int", exp); ITypeBinding oldBinding = exp.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(exp), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.UNARY_STRATEGY); ppaEngine.reportTypeFact(typeFact); newType = newBinding; } } else if (!isSafe) { ITypeBinding newBinding = ppaEngine.getRegistry().getPrimitiveBinding("boolean", exp); ITypeBinding oldBinding = exp.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(exp), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.UNARY_STRATEGY); ppaEngine.reportTypeFact(typeFact); newType = newBinding; } if (newType != null && !isPrimary) { ITypeBinding oldBinding = node.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(node), oldBinding, TypeFact.UNKNOWN, newType, TypeFact.SUBTYPE, TypeFact.BINARY_STRATEGY); ppaEngine.reportTypeFact(typeFact); // report new type for this expression. // fix this expression. } else if (isPrimary) { if (newType != null) { ppaEngine.getRegistry().fixUnary(node, newType); } else if (newFact != null) { ppaEngine.getRegistry().fixUnary(node, newFact.getNewType()); } } }
From source file:ca.mcgill.cs.swevo.ppa.inference.ReturnInferenceStrategy.java
License:Open Source License
public void inferTypes(ASTNode node) { ReturnStatement returnStmt = (ReturnStatement) node; Expression exp = returnStmt.getExpression(); if (exp == null || !indexer.isIndexable(exp) || indexer.isSafe(exp)) { return;/*from w ww . j ava 2 s . c o m*/ } MethodDeclaration mDeclaration = (MethodDeclaration) PPAASTUtil.getSpecificParentType(returnStmt, ASTNode.METHOD_DECLARATION); if (mDeclaration != null) { IMethodBinding methodBinding = mDeclaration.resolveBinding(); if (methodBinding != null) { ITypeBinding newBinding = methodBinding.getReturnType(); ITypeBinding oldBinding = exp.resolveTypeBinding(); TypeFact typeFact = new TypeFact(indexer.getMainIndex(exp), oldBinding, TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.RETURN_STRATEGY); ppaEngine.reportTypeFact(typeFact); } } }
From source file:ca.mcgill.cs.swevo.ppa.inference.VariableDeclarationInferenceStrategy.java
License:Open Source License
public void inferTypes(ASTNode node) { VariableDeclarationFragment fragment = (VariableDeclarationFragment) node; ITypeBinding newBinding = fragment.getName().resolveTypeBinding(); Expression exp = fragment.getInitializer(); if (!indexer.isSafe(exp)) { TypeFact tFact = new TypeFact(indexer.getMainIndex(exp), exp.resolveTypeBinding(), TypeFact.UNKNOWN, newBinding, TypeFact.SUBTYPE, TypeFact.ASSIGN_STRATEGY); ppaEngine.reportTypeFact(tFact); }/*w w w . ja v a 2s .c o m*/ }