use of org.eclipse.jdt.core.dom.IVariableBinding in project che 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.IVariableBinding in project che by eclipse.
the class GetterSetterCorrectionSubProcessor method addGetterSetterProposal.
private static boolean addGetterSetterProposal(IInvocationContext context, ASTNode coveringNode, Collection<ICommandAccess> proposals, int relevance) {
if (!(coveringNode instanceof SimpleName)) {
return false;
}
SimpleName sn = (SimpleName) coveringNode;
IBinding binding = sn.resolveBinding();
if (!(binding instanceof IVariableBinding))
return false;
IVariableBinding variableBinding = (IVariableBinding) binding;
if (!variableBinding.isField())
return false;
if (proposals == null)
return true;
ChangeCorrectionProposal proposal = getProposal(context.getCompilationUnit(), sn, variableBinding, relevance);
if (proposal != null)
proposals.add(proposal);
return true;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project flux by eclipse.
the class StubUtility method getBaseNameFromExpression.
private static String getBaseNameFromExpression(IJavaProject project, Expression assignedExpression, int variableKind) {
String name = null;
if (assignedExpression instanceof CastExpression) {
assignedExpression = ((CastExpression) assignedExpression).getExpression();
}
if (assignedExpression instanceof Name) {
Name simpleNode = (Name) assignedExpression;
IBinding binding = simpleNode.resolveBinding();
if (binding instanceof IVariableBinding)
return getBaseName((IVariableBinding) binding, project);
return ASTNodes.getSimpleNameIdentifier(simpleNode);
} else if (assignedExpression instanceof MethodInvocation) {
name = ((MethodInvocation) assignedExpression).getName().getIdentifier();
} else if (assignedExpression instanceof SuperMethodInvocation) {
name = ((SuperMethodInvocation) assignedExpression).getName().getIdentifier();
} else if (assignedExpression instanceof FieldAccess) {
return ((FieldAccess) assignedExpression).getName().getIdentifier();
} else if (variableKind == NamingConventions.VK_STATIC_FINAL_FIELD && (assignedExpression instanceof StringLiteral || assignedExpression instanceof NumberLiteral)) {
String string = assignedExpression instanceof StringLiteral ? ((StringLiteral) assignedExpression).getLiteralValue() : ((NumberLiteral) assignedExpression).getToken();
StringBuffer res = new StringBuffer();
boolean needsUnderscore = false;
for (int i = 0; i < string.length(); i++) {
char ch = string.charAt(i);
if (Character.isJavaIdentifierPart(ch)) {
if (res.length() == 0 && !Character.isJavaIdentifierStart(ch) || needsUnderscore) {
res.append('_');
}
res.append(ch);
needsUnderscore = false;
} else {
needsUnderscore = res.length() > 0;
}
}
if (res.length() > 0) {
return res.toString();
}
}
if (name != null) {
for (int i = 0; i < KNOWN_METHOD_NAME_PREFIXES.length; i++) {
String curr = KNOWN_METHOD_NAME_PREFIXES[i];
if (name.startsWith(curr)) {
if (name.equals(curr)) {
// don't suggest 'get' as variable name
return null;
} else if (Character.isUpperCase(name.charAt(curr.length()))) {
return name.substring(curr.length());
}
}
}
}
return name;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project flux by eclipse.
the class ImportReferencesCollector method possibleStaticImportFound.
private void possibleStaticImportFound(Name name) {
if (fStaticImports == null || fASTRoot == null) {
return;
}
while (name.isQualifiedName()) {
name = ((QualifiedName) name).getQualifier();
}
if (!isAffected(name)) {
return;
}
IBinding binding = name.resolveBinding();
SimpleName simpleName = (SimpleName) name;
if (binding == null || binding instanceof ITypeBinding || !Modifier.isStatic(binding.getModifiers()) || simpleName.isDeclaration()) {
return;
}
if (binding instanceof IVariableBinding) {
IVariableBinding varBinding = (IVariableBinding) binding;
if (varBinding.isField()) {
varBinding = varBinding.getVariableDeclaration();
ITypeBinding declaringClass = varBinding.getDeclaringClass();
if (declaringClass != null && !declaringClass.isLocal()) {
if (new ScopeAnalyzer(fASTRoot).isDeclaredInScope(varBinding, simpleName, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY))
return;
fStaticImports.add(simpleName);
}
}
} else if (binding instanceof IMethodBinding) {
IMethodBinding methodBinding = ((IMethodBinding) binding).getMethodDeclaration();
ITypeBinding declaringClass = methodBinding.getDeclaringClass();
if (declaringClass != null && !declaringClass.isLocal()) {
if (new ScopeAnalyzer(fASTRoot).isDeclaredInScope(methodBinding, simpleName, ScopeAnalyzer.METHODS | ScopeAnalyzer.CHECK_VISIBILITY))
return;
fStaticImports.add(simpleName);
}
}
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project flux by eclipse.
the class Bindings method findFieldInHierarchy.
/**
* Finds the field specified by <code>fieldName</code> in
* the type hierarchy denoted by the given type. Returns <code>null</code> if no such field
* exists. If the field is defined in more than one super type only the first match is
* returned. First the super class is examined and then the implemented interfaces.
* @param type The type to search the field in
* @param fieldName The name of the field to find
* @return the variable binding representing the field
*/
public static IVariableBinding findFieldInHierarchy(ITypeBinding type, String fieldName) {
IVariableBinding field = findFieldInType(type, fieldName);
if (field != null)
return field;
ITypeBinding superClass = type.getSuperclass();
if (superClass != null) {
field = findFieldInHierarchy(superClass, fieldName);
if (field != null)
return field;
}
ITypeBinding[] interfaces = type.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
field = findFieldInHierarchy(interfaces[i], fieldName);
if (// no private fields in interfaces
field != null)
return field;
}
return null;
}
Aggregations