use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class ASTNodes method getDimensions.
public static int getDimensions(VariableDeclaration declaration) {
int dim = declaration.getExtraDimensions();
if (declaration instanceof VariableDeclarationFragment && declaration.getParent() instanceof LambdaExpression) {
LambdaExpression lambda = (LambdaExpression) declaration.getParent();
IMethodBinding methodBinding = lambda.resolveMethodBinding();
if (methodBinding != null) {
ITypeBinding[] parameterTypes = methodBinding.getParameterTypes();
int index = lambda.parameters().indexOf(declaration);
ITypeBinding typeBinding = parameterTypes[index];
return typeBinding.getDimensions();
}
} else {
Type type = getType(declaration);
if (type instanceof ArrayType) {
dim += ((ArrayType) type).getDimensions();
}
}
return dim;
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class ScopeAnalyzer method isVisible.
/**
* Evaluates if the declaration is visible in a certain context.
* @param binding The binding of the declaration to examine
* @param context The context to test in
* @return Returns
*/
public static boolean isVisible(IBinding binding, ITypeBinding context) {
if (binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) {
// all local variables found are visible
return true;
}
ITypeBinding declaring = getDeclaringType(binding);
if (declaring == null) {
return false;
}
declaring = declaring.getTypeDeclaration();
int modifiers = binding.getModifiers();
if (Modifier.isPublic(modifiers) || declaring.isInterface()) {
return true;
} else if (Modifier.isProtected(modifiers) || !Modifier.isPrivate(modifiers)) {
if (declaring.getPackage() == context.getPackage()) {
return true;
}
return isTypeInScope(declaring, context, Modifier.isProtected(modifiers));
}
// private visibility
return isTypeInScope(declaring, context, false);
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class JdtFlags method isDefaultMethod.
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);
}
return false;
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class NecessaryParenthesesChecker method needsParenthesesInInfixExpression.
private static boolean needsParenthesesInInfixExpression(Expression expression, InfixExpression parentInfix, StructuralPropertyDescriptor locationInParent, ITypeBinding leftOperandType) {
InfixExpression.Operator parentInfixOperator = parentInfix.getOperator();
ITypeBinding rightOperandType;
ITypeBinding parentInfixExprType;
if (leftOperandType == null) {
// parentInfix has bindings
leftOperandType = parentInfix.getLeftOperand().resolveTypeBinding();
rightOperandType = parentInfix.getRightOperand().resolveTypeBinding();
parentInfixExprType = parentInfix.resolveTypeBinding();
} else {
rightOperandType = expression.resolveTypeBinding();
parentInfixExprType = getInfixExpressionType(parentInfixOperator, leftOperandType, rightOperandType);
}
boolean isAllOperandsHaveSameType = isAllOperandsHaveSameType(parentInfix, leftOperandType, rightOperandType);
if (locationInParent == InfixExpression.LEFT_OPERAND_PROPERTY) {
//infix expressions are evaluated from left to right -> parentheses not needed
return false;
} else if (isAssociative(parentInfixOperator, parentInfixExprType, isAllOperandsHaveSameType)) {
//left op (right) == (right) op left == right op left
if (expression instanceof InfixExpression) {
InfixExpression infixExpression = (InfixExpression) expression;
Operator operator = infixExpression.getOperator();
if (isStringType(parentInfixExprType)) {
if (parentInfixOperator == InfixExpression.Operator.PLUS && operator == InfixExpression.Operator.PLUS && isStringType(infixExpression.resolveTypeBinding())) {
// "" + (2 + "") == "" + 2 + ""
return !isStringType(infixExpression.getLeftOperand().resolveTypeBinding()) && !isStringType(leftOperandType);
}
//"" + (1 + 2), "" + (1 - 2) etc
return true;
}
if (parentInfixOperator != InfixExpression.Operator.TIMES)
return false;
if (operator == InfixExpression.Operator.TIMES)
// x * (y * z) == x * y * z
return false;
if (operator == InfixExpression.Operator.REMAINDER || operator == InfixExpression.Operator.DIVIDE)
// x * (y % z) != x * y % z , x * (y / z) == x * y / z rounding involved
return true;
return false;
}
return false;
} else {
return true;
}
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class NecessaryParenthesesChecker method isAllOperandsHaveSameType.
/*
* Do all operands in expression have same type
*/
private static boolean isAllOperandsHaveSameType(InfixExpression expression, ITypeBinding leftOperandType, ITypeBinding rightOperandType) {
ITypeBinding binding = leftOperandType;
if (binding == null)
return false;
ITypeBinding current = rightOperandType;
if (binding != current)
return false;
for (Iterator<Expression> iterator = expression.extendedOperands().iterator(); iterator.hasNext(); ) {
Expression operand = iterator.next();
current = operand.resolveTypeBinding();
if (binding != current)
return false;
}
return true;
}
Aggregations