use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class ScopeAnalyzer method isDeclaredInScope.
public boolean isDeclaredInScope(IBinding declaration, SimpleName selector, int flags) {
try {
// special case for switch on enum
if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
ITypeBinding binding = ((SwitchStatement) selector.getParent().getParent()).getExpression().resolveTypeBinding();
if (binding != null && binding.isEnum()) {
return hasEnumContants(declaration, binding.getTypeDeclaration());
}
}
ITypeBinding parentTypeBinding = Bindings.getBindingOfParentTypeContext(selector);
if (parentTypeBinding != null) {
ITypeBinding binding = getQualifier(selector);
SearchRequestor requestor = new SearchRequestor(declaration, parentTypeBinding, flags);
if (binding == null) {
addLocalDeclarations(selector, flags, requestor);
if (requestor.found())
return requestor.isVisible();
addTypeDeclarations(parentTypeBinding, flags, requestor);
if (requestor.found())
return requestor.isVisible();
} else {
addInherited(binding, flags, requestor);
if (requestor.found())
return requestor.isVisible();
}
}
return false;
} finally {
clearLists();
}
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class ScopeAnalyzer method addInherited.
/**
* Collects all elements available in a type and its hierarchy
* @param binding The type binding
* @param flags Flags defining the elements to report
* @param requestor the requestor to which all results are reported
* @return return <code>true</code> if the requestor has reported the binding as found and no further results are required
*/
private boolean addInherited(ITypeBinding binding, int flags, IBindingRequestor requestor) {
if (!fTypesVisited.add(binding)) {
return false;
}
if (hasFlag(VARIABLES, flags)) {
IVariableBinding[] variableBindings = binding.getDeclaredFields();
for (int i = 0; i < variableBindings.length; i++) {
if (requestor.acceptBinding(variableBindings[i]))
return true;
}
}
if (hasFlag(METHODS, flags)) {
IMethodBinding[] methodBindings = binding.getDeclaredMethods();
for (int i = 0; i < methodBindings.length; i++) {
IMethodBinding curr = methodBindings[i];
if (!curr.isSynthetic() && !curr.isConstructor()) {
if (requestor.acceptBinding(curr))
return true;
}
}
}
if (hasFlag(TYPES, flags)) {
ITypeBinding[] typeBindings = binding.getDeclaredTypes();
for (int i = 0; i < typeBindings.length; i++) {
ITypeBinding curr = typeBindings[i];
if (requestor.acceptBinding(curr))
return true;
}
}
ITypeBinding superClass = binding.getSuperclass();
if (superClass != null) {
if (// recursive
addInherited(superClass, flags, requestor))
return true;
} else if (binding.isArray()) {
if (//$NON-NLS-1$
addInherited(fRoot.getAST().resolveWellKnownType("java.lang.Object"), flags, requestor))
return true;
}
// includes looking for methods: abstract, unimplemented methods
ITypeBinding[] interfaces = binding.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
if (// recursive
addInherited(interfaces[i], flags, requestor))
return true;
}
return false;
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class ScopeAnalyzer method getDeclarationsInScope.
public IBinding[] getDeclarationsInScope(SimpleName selector, int flags) {
try {
// special case for switch on enum
if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
ITypeBinding binding = ((SwitchStatement) selector.getParent().getParent()).getExpression().resolveTypeBinding();
if (binding != null && binding.isEnum()) {
return getEnumContants(binding);
}
}
ITypeBinding parentTypeBinding = Bindings.getBindingOfParentType(selector);
if (parentTypeBinding != null) {
ITypeBinding binding = getQualifier(selector);
DefaultBindingRequestor requestor = new DefaultBindingRequestor(parentTypeBinding, flags);
if (binding == null) {
addLocalDeclarations(selector, flags, requestor);
addTypeDeclarations(parentTypeBinding, flags, requestor);
} else {
addInherited(binding, flags, requestor);
}
List<IBinding> result = requestor.getResult();
return result.toArray(new IBinding[result.size()]);
}
return NO_BINDING;
} finally {
clearLists();
}
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class ASTResolving method isVariableDefinedInContext.
private static boolean isVariableDefinedInContext(IBinding binding, ITypeBinding typeVariable) {
if (binding.getKind() == IBinding.VARIABLE) {
IVariableBinding var = (IVariableBinding) binding;
binding = var.getDeclaringMethod();
if (binding == null) {
binding = var.getDeclaringClass();
}
}
if (binding instanceof IMethodBinding) {
if (binding == typeVariable.getDeclaringMethod()) {
return true;
}
binding = ((IMethodBinding) binding).getDeclaringClass();
}
while (binding instanceof ITypeBinding) {
if (binding == typeVariable.getDeclaringClass()) {
return true;
}
if (Modifier.isStatic(binding.getModifiers())) {
break;
}
binding = ((ITypeBinding) binding).getDeclaringClass();
}
return false;
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class Bindings method asString.
private static String asString(IMethodBinding method) {
StringBuffer result = new StringBuffer();
result.append(method.getDeclaringClass().getName());
result.append(':');
result.append(method.getName());
result.append('(');
ITypeBinding[] parameters = method.getParameterTypes();
int lastComma = parameters.length - 1;
for (int i = 0; i < parameters.length; i++) {
ITypeBinding parameter = parameters[i];
result.append(parameter.getName());
if (i < lastComma)
//$NON-NLS-1$
result.append(", ");
}
result.append(')');
return result.toString();
}
Aggregations