List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding MethodBinding
public MethodBinding(MethodBinding initialMethodBinding, ReferenceBinding declaringClass)
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectMapper.java
License:Open Source License
/** * This method realizes the logic of the mapping for methods. * @param srcMethod where to copy from * @param refMethodBinding what to copy/remap * @param dstTeam where to copy to * @param addMarkerArgAllowed whether copying is allowed to add a marker arg * @return destination method//w w w . j a v a2 s .c om */ public static MethodBinding mapMethod(MethodBinding srcMethod, MethodBinding refMethodBinding, MethodBinding dstMethod, ReferenceBinding dstTeam, boolean addMarkerArgAllowed) { if (dstMethod != null) { if (dstMethod.model != null) { if (dstMethod.model.oldSelfcall == refMethodBinding) return dstMethod.model.adjustedSelfcall; } if (isConfinedSuperCtor(srcMethod, refMethodBinding)) return getConfinedSuperCtor(dstMethod); } // if Binding points at Role-Method of Superteamclass, then mapping must be done if (isMappableMethod(refMethodBinding)) { if (refMethodBinding.isSynthetic()) { RoleModel role = ((ReferenceBinding) mapClass(srcMethod, refMethodBinding.declaringClass, dstTeam)).roleModel; if (role != null) { MethodBinding foundMethod = role.mapSyntheticMethod(refMethodBinding); if (foundMethod != null) return foundMethod; } } boolean isDecapsAccessor = false; if (CharOperation.prefixEquals(IOTConstants.OT_DECAPS, refMethodBinding.selector)) { // to find a decapsulated method, first strip off the accessor's prefix, then search and ... refMethodBinding = new MethodBinding(refMethodBinding, refMethodBinding.declaringClass); refMethodBinding.selector = CharOperation.subarray(refMethodBinding.selector, IOTConstants.OT_DECAPS.length, -1); isDecapsAccessor = true; } MethodBinding foundMethod = doMapMethod(srcMethod, refMethodBinding, dstMethod, dstTeam, addMarkerArgAllowed); if (foundMethod != null && isDecapsAccessor) { // .. append the stripped prefix after finding foundMethod = new MethodBinding(foundMethod, foundMethod.declaringClass); foundMethod.selector = CharOperation.concat(IOTConstants.OT_DECAPS, foundMethod.selector); } return foundMethod; } return refMethodBinding; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectMapper.java
License:Open Source License
/** * searches for a matching Method in the destination Team * For this the method will compare all roles from destination Team with * the role of the referenced Method. if one matching role ist found, * search inside this role for the referenced Method. * The Method exists in this Role, because we have copied it before. * @param dstTeam the destination Team/* w ww.j ava 2 s . c om*/ * @param refMethod the referenced MethodBinding which must be a Role-Method of the dstTeamBinding-Superclass * @return the found MethodBinding or null if no matching Method is found */ private static MethodBinding searchRoleMethodInTeam(ReferenceBinding dstTeam, MethodBinding refMethod, boolean addMarkerArgAllowed) { ReferenceBinding refRoleBinding = refMethod.declaringClass; if (isMappableClass(refRoleBinding)) { //search for matching Role in dstTeamBinding ReferenceBinding dstRefRoleBinding = searchRoleClass(refRoleBinding, dstTeam); //search for matching method in destination Role MethodBinding roleMethod = searchRoleMethodInRole(dstRefRoleBinding, refMethod, addMarkerArgAllowed); if (roleMethod != null) return roleMethod; if (dstRefRoleBinding.isCompatibleWith(refRoleBinding) || ConstantPoolObjectReader.isFakedOTREMethod(refMethod.selector) != 0) { return new MethodBinding(refMethod, dstRefRoleBinding); } // System.out.println("method "+new String(refMethod.declaringClass.qualifiedSourceName())+"."+refMethod+" not found in "+new String(dstRefRoleBinding.qualifiedSourceName())); } else if (isStaticBasecallSurrogate(refMethod)) { // basecall surrogates for static role methods are team methods, but need adaptation, too. MethodBinding[] methods = dstTeam.getMethods(refMethod.selector); for (int i = 0; i < methods.length; i++) { if (methods[i].parameters.length != refMethod.parameters.length) continue; for (int j = 0; j < methods[i].parameters.length; j++) { if (TypeBinding.notEquals(methods[i].parameters[j], refMethod.parameters[j])) // non-variant continue; } return methods[i]; } // FIXME(SH): should byte code store info whether callin method is bound? return refMethod; // don't change method reference, method might be a dummy (throwing OTREInternalError). } return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectReader.java
License:Open Source License
private MethodBinding getInterfaceMethodRef(int index) { int start = getConstantPoolStartPosition(index); assert (u1At(start) == InterfaceMethodRefTag); int class_index = u2At(start + 1); int name_index = u2At(start + 3); ReferenceBinding class_rb = getClassBinding(class_index); if (class_rb == null) return null; char[][] nameandtype = getNameAndType(name_index); char[] name = nameandtype[0]; char[] type = nameandtype[1]; MethodBinding mb = findMethodBinding(class_rb, name, type); assert (mb != null); if (TypeBinding.notEquals(mb.declaringClass, class_rb)) { mb = new MethodBinding(mb, class_rb); }//from w w w .j a v a2 s. c o m return mb; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectReader.java
License:Open Source License
public MethodBinding findMethodBinding(ReferenceBinding class_rb, char[] name, char[] descriptor) { boolean isDecapsWrapper = false; if (CharOperation.prefixEquals(IOTConstants.OT_DECAPS, name)) { // accessors for decapsulation: strip prefix and prepend it after we have found the method: isDecapsWrapper = true;//from w ww . j ava2s . c om name = CharOperation.subarray(name, IOTConstants.OT_DECAPS.length, -1); } MethodBinding foundMethod = doFindMethodBinding(class_rb, name, descriptor); if (foundMethod != null && isDecapsWrapper) { foundMethod = new MethodBinding(foundMethod, class_rb); // OTRE adds the accessor to the exact base class, even if method is inherited foundMethod.selector = CharOperation.concat(IOTConstants.OT_DECAPS, name); } return foundMethod; }
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; }//from w w w . j a v a 2s . 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.RoleTypeBinding.java
License:Open Source License
public void addMethod(MethodBinding method) { if (this._staticallyKnownRoleClass != null) { this._staticallyKnownRoleClass.addMethod(method); }/*from w ww . j a v a2s . c om*/ MethodBinding ifcPart = new MethodBinding(method, this._staticallyKnownRoleType); ifcPart.modifiers |= ClassFileConstants.AccAbstract; this._staticallyKnownRoleType.addMethod(ifcPart); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementor.java
License:Open Source License
/** This method drives the creation of a callout implementation for one callout mapping. */ private MethodDeclaration createCallout(CalloutMappingDeclaration calloutMappingDeclaration, boolean needBody, boolean isInferred) { CallinCalloutScope calloutScope = calloutMappingDeclaration.scope; calloutMappingDeclaration.updateTSuperMethods(); // This binding is part of the interface part of a role: MethodBinding roleMethodBinding = calloutMappingDeclaration.getRoleMethod(); if (roleMethodBinding == null) // CLOVER: never true in jacks suite {/*from w ww .j a v a 2s . com*/ // problemreporting already done in find-Base/Role-MethodBinding assert (calloutMappingDeclaration.ignoreFurtherInvestigation); return null; } if (!roleMethodBinding.isValidBinding()) { if (roleMethodBinding.problemId() != ProblemReasons.NotFound) { // CLOVER: never true in jacks suite calloutMappingDeclaration.tagAsHavingErrors(); // hopefully error has been reported! return null; } else { // shorthand style callout // help sourceMethod() below to find another callout method MethodBinding existingMethod = calloutScope.enclosingSourceType().getExactMethod( roleMethodBinding.selector, roleMethodBinding.parameters, calloutScope.compilationUnitScope()); if (existingMethod != null) roleMethodBinding = existingMethod; } } MethodDeclaration roleMethodDeclaration = null; if (TypeBinding.equalsEquals(roleMethodBinding.declaringClass, calloutScope.enclosingSourceType())) roleMethodDeclaration = (MethodDeclaration) roleMethodBinding.sourceMethod(); // have a binding but no declaration for method? -> requires creation of declaration boolean foundRoleDecl = roleMethodDeclaration != null; MethodBinding overriddenTSuper = null; // The following code allows to use tsuper in parameter mappings // (see 3.2.32-otjld-tsuper-access-1) if (foundRoleDecl && roleMethodDeclaration.isCopied // foundRoleDecl => (roleMethodDeclaration != null) && (roleMethodDeclaration.modifiers & AccAbstract) == 0 && !TSuperHelper.isTSuper(roleMethodDeclaration.binding)) { // mapping conflicts with an implicitly inherited method. // make the latter a tsuper version, now. overriddenTSuper = roleMethodBinding; // save a clone of the method binding before adding the marker arg, for use below. roleMethodBinding = new MethodBinding(roleMethodBinding, roleMethodBinding.declaringClass); // clone TSuperHelper.addMarkerArg(roleMethodDeclaration, roleMethodDeclaration.binding.copyInheritanceSrc.declaringClass.enclosingType()); foundRoleDecl = false; // re-create the method; } if (!foundRoleDecl) { roleMethodDeclaration = createAbstractRoleMethodDeclaration(roleMethodBinding, calloutMappingDeclaration); if (overriddenTSuper != null) roleMethodDeclaration.binding.addOverriddenTSuper(overriddenTSuper); } else { roleMethodDeclaration.isReusingSourceMethod = true; // foundRoleDecl => (roleMethodDeclaration != null) // mark existing method as generated by the callout mapping: roleMethodDeclaration.isMappingWrapper = WrapperKind.CALLOUT; // match locator may want to know this for the interface part, too: // (SH: unsure, if this is really needed, but it doesn't hurt either ;-) if (roleMethodDeclaration.interfacePartMethod != null) { roleMethodDeclaration.interfacePartMethod.isReusingSourceMethod = true; roleMethodDeclaration.interfacePartMethod.isMappingWrapper = WrapperKind.CALLOUT; } } if (calloutMappingDeclaration.hasSignature) { // Adjust arguments: Argument[] args = calloutMappingDeclaration.roleMethodSpec.arguments; if (args != null) { for (int i = 0; i < args.length; i++) { // if we already have a declaration and if we have signatures // in the mapping declaration, use the argument names from the // method mapping rather than those from the original declaration // (needed for parameter mapping!). if (foundRoleDecl) roleMethodDeclaration.arguments[i].updateName(args[i].name); // also link best names of arguments of roleMethodSpec and actual wrapper // ( requires wrapper argument to be bound, do this first. // Note that all args must be bound in order!). roleMethodDeclaration.arguments[i].bind(roleMethodDeclaration.scope, args[i].binding.type, false); args[i].binding.setBestNameFromStat(roleMethodDeclaration.arguments[i]); } } } if (roleMethodDeclaration != null) // try again { // Note: do not query the binding (as isAbstract() would do). // Binding may have corrected modifiers, but take the raw modifiers. if (!roleMethodDeclaration.isCopied && !roleMethodDeclaration.isGenerated && (roleMethodDeclaration.modifiers & AccAbstract) == 0) { // bad overriding of existing / non-existant methods is handled in MethodMappingResolver already roleMethodDeclaration.ignoreFurtherInvestigation = true; // don't throw "abstract method.. can only be defined by abstract class" error calloutScope.problemReporter().calloutOverridesLocal(this._role.getAst(), calloutMappingDeclaration, roleMethodDeclaration.binding); return null; } // fix flags (even if not needing body): roleMethodDeclaration.isCopied = false; int flagsToRemove = AccAbstract | ExtraCompilerModifiers.AccSemicolonBody | AccNative; roleMethodDeclaration.modifiers &= ~flagsToRemove; roleMethodDeclaration.binding.modifiers &= ~flagsToRemove; roleMethodDeclaration.isGenerated = true; // even if not generated via AstGenerator. if (needBody && calloutMappingDeclaration.binding.isValidBinding()) { // defer generation of statements: final CalloutMappingDeclaration mappingDeclaration = calloutMappingDeclaration; MethodModel methodModel = MethodModel.getModel(roleMethodDeclaration); if (isInferred) methodModel._inferredCallout = mappingDeclaration; methodModel.setStatementsGenerator(new AbstractStatementsGenerator() { public boolean generateStatements(AbstractMethodDeclaration methodDecl) { createCalloutMethodBody((MethodDeclaration) methodDecl, mappingDeclaration); return true; } }); } else if (calloutMappingDeclaration.ignoreFurtherInvestigation) { roleMethodDeclaration.binding.bytecodeMissing = true; // will not be generated, so don't complain later. } } else // roleMethodDeclaration still null { // CLOVER: never reached in jacks suite ;-) throw new InternalCompilerError("OT-Compiler Error: couldn't create method declaration for callout! " //$NON-NLS-1$ + calloutMappingDeclaration.toString()); } return roleMethodDeclaration; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementor.java
License:Open Source License
/** In order to resolve static role methods via the interface create a method * binding without a declaration. */ private void createInterfaceFakeStatic(MethodBinding template, CalloutMappingDeclaration calloutDecl) { MethodBinding newMethod = new MethodBinding(template, this._role.getInterfacePartBinding()); this._role.getInterfacePartBinding().addMethod(newMethod); }