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;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project j2objc by google.
the class JdtTypeElement method getEnclosedElements.
@Override
public List<? extends Element> getEnclosedElements() {
ITypeBinding decl = (ITypeBinding) binding;
List<Element> toReturn = new ArrayList<>();
for (IVariableBinding i : decl.getDeclaredFields()) {
toReturn.add(BindingConverter.getElement(i));
}
for (IMethodBinding i : decl.getDeclaredMethods()) {
toReturn.add(BindingConverter.getElement(i));
}
for (ITypeBinding i : decl.getDeclaredTypes()) {
toReturn.add(BindingConverter.getElement(i));
}
return toReturn;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project XobotOS by xamarin.
the class StructHelperClass method resolve.
@Override
public boolean resolve(IMarshalContext context) {
if (BindingManager.DEBUG)
Sharpen.Debug("RESOLVE STRUCT: %s", getName());
if (_resolved)
return !_resolveFailed;
final List<MemberInfo> members = _template.getMembers();
_fieldInfo = new ElementInfo[members.size()];
for (int i = 0; i < members.size(); i++) {
final MemberInfo member = members.get(i);
IVariableBinding field = findField(getType(), member.getName());
if (field == null) {
Sharpen.Log(Level.SEVERE, "No such field '%s' in type '%s'", member.getName(), BindingUtils.qualifiedName(getType()));
_resolveFailed = true;
continue;
}
if (member.getValue() != null)
continue;
MarshalInfo marshal;
if (member.getMarshalInfo() != null)
marshal = member.getMarshalInfo().resolve(field.getType());
else
marshal = context.getMarshalInfo(field.getType());
if (marshal == null) {
Sharpen.Log(Level.SEVERE, "Missing marshal info for type '%s' of field '%s'", BindingUtils.qualifiedName(field.getType()), member.getName());
_resolveFailed = true;
continue;
}
_fieldInfo[i] = new ElementInfo(field.getType(), marshal, null, Flags.ELEMENT);
if (BindingManager.DEBUG)
Sharpen.Debug("STRUCT MEMBER: %s - %s", member.getName(), BindingUtils.qualifiedName(field.getType()));
if (!marshal.resolve(context, field.getType())) {
Sharpen.Log(Level.SEVERE, "Failed to resolve field '%s' in '%s'", member.getName(), BindingUtils.qualifiedName(getType()));
_resolveFailed = true;
continue;
}
if (!marshal.isPrimitiveType()) {
Sharpen.Log(Level.SEVERE, "Field '%s' in '%s' is not a primitive type", member.getName(), BindingUtils.qualifiedName(getType()));
_resolveFailed = true;
continue;
}
if (BindingManager.DEBUG)
Sharpen.Debug("STRUCT MEMBER DONE: %s - %s", member.getName(), BindingUtils.qualifiedName(field.getType()));
}
if (BindingManager.DEBUG)
Sharpen.Debug("RESOLVE STRUCT DONE: %s%s", getName(), _resolveFailed ? " - ERROR" : "");
_resolved = true;
return true;
}
Aggregations