List of usage examples for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding syntheticMethods
public SyntheticMethodBinding[] syntheticMethods()
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectReader.java
License:Open Source License
private MethodBinding doFindMethodBinding(ReferenceBinding class_rb, char[] name, char[] descriptor) { MethodBinding[] mbs = class_rb.getMethods(name); if (mbs != Binding.NO_METHODS) { for (int i = 0; i < mbs.length; i++) { MethodBinding binding = mbs[i]; if (binding != null) { if (isEqual(binding, name, descriptor)) return binding; }/* w w w .ja v a 2 s . c o m*/ } // TODO(SH): currently this may happen, if a role file is not recompiled which // required e.g., a getter access$n, while a setter access$n is being generated. if (isSynthMethodName(name)) throw new InternalCompilerError( "synthetic method " + new String(name) + " has unexpected signature"); //$NON-NLS-1$ //$NON-NLS-2$ } if (isSynthMethodName(name) || SyntheticBaseCallSurrogate.isBaseCallSurrogateName(name)) { // for normal access methods class_rb should not be a BinaryTypeBinding, // because in that case the above loop should have found the method // (access$n are stored like normal methods). if (class_rb.isBinaryBinding()) { if (SyntheticBaseCallSurrogate.isBaseCallSurrogateName(name)) { // surrogate might be inherited ReferenceBinding current = class_rb; while ((current = current.superclass()) != null) { MethodBinding candidate = doFindMethodBinding(current, name, descriptor); if (candidate != null) return candidate; } } // TODO(SH): but when T has been compiled only with T.R1 while T.R2 // requires a synth.method, than this method will be missing! } else { SourceTypeBinding stb = (SourceTypeBinding) class_rb.erasure(); SyntheticMethodBinding[] accessMethods = stb.syntheticMethods(); if (accessMethods != null) { for (int i = 0; i < accessMethods.length; i++) { if (CharOperation.equals(accessMethods[i].selector, name)) return accessMethods[i]; } } } } if (SyntheticRoleFieldAccess.isRoleFieldAccess(AccSynthetic, name)) { if (class_rb.isBinaryBinding()) return null; // should have been found within methods SourceTypeBinding sourceType = (SourceTypeBinding) class_rb.erasure(); SyntheticMethodBinding[] synthetics = sourceType.syntheticMethods(); if (synthetics == null) return null; for (SyntheticMethodBinding methodBinding : synthetics) { if (CharOperation.equals(methodBinding.selector, name)) return methodBinding; } } int modifiers = isFakedOTREMethod(name); if (modifiers != 0) { // These methods will be generated by the OTRE, // may safely be faked during compilation: MethodBinding fakedMethod = createMethodFromSignature(class_rb, modifiers, name, descriptor); class_rb.addMethod(fakedMethod); return fakedMethod; } // since Eclipse 3.0 and for JDK >= 1.2 the declaring class is changed to the // declared receiver (see SourceTypeBinding.getUpdatedMethodBinding()). // need to search super class/interfaces to really find the method. ReferenceBinding currentType = class_rb.superclass(); if (currentType != null) { MethodBinding mb = findMethodBinding(currentType, name, descriptor); if (mb != null) return mb; } ReferenceBinding[] superIfcs = class_rb.superInterfaces(); if (superIfcs != null) { for (int i = 0; i < class_rb.superInterfaces().length; i++) { MethodBinding mb = findMethodBinding(superIfcs[i], name, descriptor); if (mb != null) { if (!class_rb.isInterface()) return new MethodBinding(mb, class_rb); // need a class method! return mb; } } } return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticBaseCallSurrogate.java
License:Open Source License
/** * Create a binding for a synthetic base-call surrogate. * //from w w w . j a v a2 s . c om * @param callinMethod the callin method potentially holding base-calls * @param declaringClass the class that will hold the surrogate implementation: normally the role, for static callin methods: the team. */ public SyntheticBaseCallSurrogate(MethodBinding callinMethod, SourceTypeBinding declaringClass) { super(declaringClass, ClassFileConstants.AccProtected | ClassFileConstants.AccSynthetic, callinMethod.selector, callinMethod.parameters, callinMethod.returnType); this.selector = SyntheticBaseCallSurrogate.genSurrogateName(callinMethod.selector, callinMethod.declaringClass.sourceName(), callinMethod.isStatic()); if (!callinMethod.isStatic() && callinMethod.isCallin()) { // don't change paramaters if enhancement is absent // additional arg "boolean isSuperAccess": this.parameters = addIsSuperAccessArg(this.parameters, declaringClass.scope.compilerOptions().weavingScheme); } this.purpose = MethodAccess; this.targetMethod = callinMethod; TypeBinding origReturnType = MethodModel.getReturnType(callinMethod); MethodModel.saveReturnType(this, origReturnType); // fetch type bindings while we have a scope: Scope scope = declaringClass.scope; this.errorType = scope.getType(IOTConstants.OTRE_INTERNAL_ERROR, 3); this.stringType = scope.getJavaLangString(); // the synthetic methods of a class will be sorted according to a per-class index, find the index now: SyntheticMethodBinding[] knownAccessMethods = declaringClass.syntheticMethods(); this.index = knownAccessMethods == null ? 0 : knownAccessMethods.length; this.sourceStart = declaringClass.scope.referenceContext.sourceStart; retrieveLineNumber(declaringClass); }