List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding fields
public FieldBinding[] fields()
From source file:com.android.tools.lint.psi.EcjPsiBinaryClass.java
License:Apache License
private PsiField[] getFields(boolean includeInherited) { if (mBinding instanceof ReferenceBinding) { ReferenceBinding cls = (ReferenceBinding) mBinding; if (includeInherited) { List<EcjPsiBinaryField> result = null; while (cls != null) { FieldBinding[] fields = cls.fields(); if (fields != null) { int count = fields.length; if (count > 0) { if (result == null) { result = Lists.newArrayListWithExpectedSize(count); }/*from w w w . j a v a 2 s .c o m*/ for (FieldBinding field : fields) { if ((field.modifiers & Modifier.PRIVATE) != 0 && cls != mBinding) { // Ignore parent fields that are private continue; } // See if this field looks like it's masked boolean masked = false; for (EcjPsiBinaryField f : result) { FieldBinding mb = f.getBinding(); if (Arrays.equals(mb.readableName(), field.readableName())) { masked = true; break; } } if (masked) { continue; } result.add(new EcjPsiBinaryField(mManager, field)); } } } cls = cls.superclass(); } return result != null ? result.toArray(PsiField.EMPTY_ARRAY) : PsiField.EMPTY_ARRAY; } else { FieldBinding[] fields = cls.fields(); if (fields != null) { int count = fields.length; List<EcjPsiBinaryField> result = Lists.newArrayListWithExpectedSize(count); for (FieldBinding field : fields) { result.add(new EcjPsiBinaryField(mManager, field)); } return result.toArray(PsiField.EMPTY_ARRAY); } } } return PsiField.EMPTY_ARRAY; }
From source file:com.android.tools.lint.psi.EcjPsiBinaryClass.java
License:Apache License
@Nullable @Override//from w w w. j a va 2 s . c o m public PsiField findFieldByName(String name, boolean checkBases) { if (mBinding instanceof ReferenceBinding) { ReferenceBinding cls = (ReferenceBinding) mBinding; while (cls != null) { FieldBinding[] fields = cls.fields(); if (fields != null) { for (FieldBinding field : fields) { if ((field.modifiers & Modifier.PRIVATE) != 0 && cls != mBinding) { // Ignore parent methods that are private continue; } if (EcjParser.sameChars(name, field.name)) { return new EcjPsiBinaryField(mManager, field); } } } if (checkBases) { cls = cls.superclass(); } else { break; } } } return null; }
From source file:com.google.gwt.dev.jjs.impl.BuildTypeMap.java
License:Apache License
private void resolve(JDeclaredType type, ReferenceBinding binding) { process(binding);/* w w w . j av a 2 s .c o m*/ for (FieldBinding fieldBinding : binding.fields()) { if (fieldBinding.isPrivate() || (type.getName().startsWith("java.") && !fieldBinding.isPublic() && !fieldBinding.isProtected())) { continue; } createField(type.getSourceInfo(), fieldBinding, type); } for (MethodBinding methodBinding : binding.methods()) { processExternalMethod(methodBinding, type); } if (binding instanceof BinaryTypeBinding) { // Unlike SourceTypeBindings, we have to explicitly ask for bridge methods // for BinaryTypeBindings. try { // TODO(tobyr) Fix so we don't have to use reflection. Method m = BinaryTypeBinding.class.getDeclaredMethod("bridgeMethods"); MethodBinding[] bridgeMethods = (MethodBinding[]) m.invoke(binding); for (MethodBinding methodBinding : bridgeMethods) { processExternalMethod(methodBinding, type); } } catch (Exception e) { throw new InternalCompilerException("Unexpected failure", e); } } }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.UnknownClassMirror.java
License:Open Source License
@Override public List<FieldMirror> getDirectFields() { if (fields == null) { doWithBindings(new ActionOnClassBinding() { @Override/* w ww .ja v a 2 s . co m*/ public void doWithBinding(IType classModel, ReferenceBinding klass) { FieldBinding[] directFields = klass.fields(); fields = new ArrayList<FieldMirror>(directFields.length); for (FieldBinding field : directFields) { if (!field.isSynthetic() && !field.isPrivate()) { fields.add(new JDTField(field)); } } } }); } return fields; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java
License:Open Source License
/** * Copy all fields and methods from tsuperRoleBinding to role * * @param role/*from w w w . ja va2 s .c o m*/ * @param tsuperRoleBinding */ public static void copyFeatures(RoleModel role, ReferenceBinding tsuperRoleBinding) { TypeDeclaration rt = role.getAst(); // fields first (may be needed by synthetic methods below). FieldBinding[] fields = tsuperRoleBinding.fields(); if (fields != null) for (int j = 0; j < fields.length; j++) copyField(fields[j], rt); // regular methods. MethodBinding[] methods = tsuperRoleBinding.methods(); if (methods != null) for (int j = 0; j < methods.length; j++) copyMethod(methods[j], rt); }
From source file:org.eclipse.recommenders.internal.chain.rcp.TypeBindingAnalyzer.java
License:Open Source License
private static Collection<Binding> findFieldsAndMethods(final TypeBinding type, final InvocationSite invocationSite, final Scope scope, final Predicate<FieldBinding> fieldFilter, final Predicate<MethodBinding> methodFilter) { final Map<String, Binding> tmp = Maps.newLinkedHashMap(); final TypeBinding receiverType = scope.classScope().referenceContext.binding; for (final ReferenceBinding cur : findAllSupertypesIncludeingArgument(type)) { for (final MethodBinding method : cur.methods()) { if (methodFilter.apply(method) || !method.canBeSeenBy(invocationSite, scope)) { continue; }//from w w w. j a v a 2 s . c om final String key = createMethodKey(method); if (!tmp.containsKey(key)) { tmp.put(key, method); } } for (final FieldBinding field : cur.fields()) { if (fieldFilter.apply(field) || !field.canBeSeenBy(receiverType, invocationSite, scope)) { continue; } final String key = createFieldKey(field); if (!tmp.containsKey(key)) { tmp.put(key, field); } } } return tmp.values(); }
From source file:spoon.support.compiler.jdt.ContextBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") private <T, U extends CtVariable<T>> U getVariableDeclaration(final String name, final Class<U> clazz) { final CoreFactory coreFactory = jdtTreeBuilder.getFactory().Core(); final TypeFactory typeFactory = jdtTreeBuilder.getFactory().Type(); final ClassFactory classFactory = jdtTreeBuilder.getFactory().Class(); final InterfaceFactory interfaceFactory = jdtTreeBuilder.getFactory().Interface(); final FieldFactory fieldFactory = jdtTreeBuilder.getFactory().Field(); final ReferenceBuilder referenceBuilder = jdtTreeBuilder.getReferencesBuilder(); final Environment environment = jdtTreeBuilder.getFactory().getEnvironment(); // there is some extra work to do if we are looking for CtFields (and subclasses) final boolean lookingForFields = clazz == null || coreFactory.createField().getClass().isAssignableFrom(clazz); // try to find the variable on stack beginning with the most recent element for (final ASTPair astPair : stack) { // the variable may have been declared directly by one of these elements final ScopeRespectingVariableScanner<U> scanner = new ScopeRespectingVariableScanner(name, clazz); astPair.element.accept(scanner); if (scanner.getResult() != null) { return scanner.getResult(); }// w w w. jav a2s. co m // the variable may have been declared in a super class/interface if (lookingForFields && astPair.node instanceof TypeDeclaration) { final TypeDeclaration nodeDeclaration = (TypeDeclaration) astPair.node; final Deque<ReferenceBinding> referenceBindings = new ArrayDeque<>(); // add super class if any if (nodeDeclaration.superclass != null && nodeDeclaration.superclass.resolvedType instanceof ReferenceBinding) { referenceBindings.push((ReferenceBinding) nodeDeclaration.superclass.resolvedType); } // add interfaces if any if (nodeDeclaration.superInterfaces != null) { for (final TypeReference tr : nodeDeclaration.superInterfaces) { if (tr.resolvedType instanceof ReferenceBinding) { referenceBindings.push((ReferenceBinding) tr.resolvedType); } } } while (!referenceBindings.isEmpty()) { final ReferenceBinding referenceBinding = referenceBindings.pop(); for (final FieldBinding fieldBinding : referenceBinding.fields()) { if (name.equals(new String(fieldBinding.readableName()))) { final String qualifiedNameOfParent = getNormalQualifiedName(referenceBinding); final CtType parentOfField = referenceBinding.isClass() ? classFactory.create(qualifiedNameOfParent) : interfaceFactory.create(qualifiedNameOfParent); U field = (U) fieldFactory.create(parentOfField, EnumSet.noneOf(ModifierKind.class), referenceBuilder.getTypeReference(fieldBinding.type), name); return field.setExtendedModifiers( JDTTreeBuilderQuery.getModifiers(fieldBinding.modifiers, true, false)); } } // add super class if any final ReferenceBinding superclass = referenceBinding.superclass(); if (superclass != null) { referenceBindings.push(superclass); } // add interfaces if any final ReferenceBinding[] interfaces = referenceBinding.superInterfaces(); if (interfaces != null) { for (ReferenceBinding rb : interfaces) { referenceBindings.push(rb); } } } } } // the variable may have been imported statically from another class/interface if (lookingForFields) { final CtReference potentialReferenceToField = referenceBuilder .getDeclaringReferenceFromImports(name.toCharArray()); if (potentialReferenceToField instanceof CtTypeReference) { final CtTypeReference typeReference = (CtTypeReference) potentialReferenceToField; try { final Class classOfType = typeReference.getActualClass(); if (classOfType != null) { final CtType declaringTypeOfField = typeReference.isInterface() ? interfaceFactory.get(classOfType) : classFactory.get(classOfType); final CtField field = declaringTypeOfField.getField(name); if (field != null) { return (U) field; } } } catch (final SpoonClassNotFoundException scnfe) { // in noclasspath mode we do some heuristics to determine if `name` could be a // field that has been imported statically from another class (or interface). if (environment.getNoClasspath()) { // if `potentialReferenceToField` is a `CtTypeReference` then `name` must // have been imported statically. Otherwise, `potentialReferenceToField` // would be a CtPackageReference! // if `name` consists only of upper case characters separated by '_', we // assume a constant value according to JLS. if (name.toUpperCase().equals(name)) { final CtType parentOfField = classFactory.create(typeReference.getQualifiedName()); // it is the best thing we can do final CtField field = coreFactory.createField(); field.setParent(parentOfField); field.setSimpleName(name); // it is the best thing we can do field.setType(typeFactory.nullType()); return (U) field; } } } } } return null; }