List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding isPublic
public final boolean isPublic()
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java
License:Open Source License
/** * Copy a given method to the tsub-role. * Adds the new method to AST and performs initial creation of bindings. * @param method method to copy//from w w w .j ava 2 s . c o m * @param targetRoleDecl target role class */ private static void copyMethod(MethodBinding method, TypeDeclaration targetRoleDecl) { boolean wasSynthetic = false; ReferenceBinding site = null; if ((method.modifiers & AccSynthetic) != 0) { wasSynthetic = true; // some, but not all, synthetics shall be generated with strong signatures as indicated by 'site': if (!SyntheticBaseCallSurrogate.isBaseCallSurrogateName(method.selector)) site = targetRoleDecl.binding; if (SyntheticRoleBridgeMethodBinding.isPrivateBridgeSelector(method.selector)) return; // will be generated anew } if (TypeContainerMethod.isTypeContainer(method)) return; // don't copy these dummy methods if (isCreator(method) || CharOperation.equals(IOTConstants._OT_GETBASE, method.selector) || CharOperation.prefixEquals(IOTConstants.CAST_PREFIX, method.selector) || CharOperation.prefixEquals(IOTConstants.GET_CLASS_PREFIX, method.selector)) return; // create/getBase/cast/getClass-methods are generated anew in each team. // (can only happen in a team that is a role of an outer team.) // Note: we don't use AccSynthetic on creators, because // Synthetic methods are not read from byte code. // FIXME(SH): this last note is not true any more. if (targetRoleDecl.isTeam() && (ReflectionGenerator.isReflectionMethod(method) || SerializationGenerator.isSerializationMethod(method))) return; if (MethodModel.isFakedMethod(method)) return; // will be generated anew (basecall-surrogate, rolefield-bridge) if (CharOperation.equals(IOTConstants.MIGRATE_TO_TEAM, method.selector)) return; // can only be used from the exact team // avoid copying twice (see copyGeneratedFeatures()): targetRoleDecl.getRoleModel().recordCopiedFeature(method); // some useful objects: ReferenceBinding srcRole = method.declaringClass; TypeDeclaration targetTeamDecl = targetRoleDecl.enclosingType; ReferenceBinding srcTeam = TeamModel.getEnclosingTeam(srcRole); ReferenceBinding tgtTeam = targetTeamDecl.binding; MethodBinding origin = (method.copyInheritanceSrc != null) ? method.copyInheritanceSrc : method; AbstractMethodDeclaration methodFound = findMethod(srcTeam, method, tgtTeam, targetRoleDecl); if (method.isConstructor()) { if (CharOperation.equals(srcRole.compoundName, IOTConstants.ORG_OBJECTTEAMS_TEAM_OTCONFINED)) { // must add default constructor explicitly, // since if we would copy the one from Team.__OT__Confined, // it would invoke the wrong super(). ConstructorDeclaration ctor = targetRoleDecl.createDefaultConstructor(true, true); targetRoleDecl.binding.resolveGeneratedMethod(ctor, false, origin); return; } else if (targetRoleDecl.getRoleModel()._refinesExtends) { // even if we can't copy the ctor, we need to mark // the current ctor as overriding the tsuper version. if (methodFound != null) methodFound.binding.addOverriddenTSuper(method); return; // extends is covariantly redefined, don't copy ctor! // attempts to invoke this tsuper ctor are caught in ExplicitConstructorCall.resolve(). } } // If method already exists in subteam, // + adjust method in subteam to the more general signature (here) // + extend copy with marker arg (below). // else give an exact copy. boolean reuseFoundMethod = false; if (methodFound != null) { // do not touch broken methods: // (methodFound might have no binding, // e.g., due to a missing import of return-type) if (methodFound.binding == null) return; if (methodFound.binding.copyInheritanceSrc == origin) return; // diamond inheritance: copying the same method from two different sources // tsuper method trumps previously inferred callout: if (methodFound.isMappingWrapper == WrapperKind.CALLOUT) { MethodModel model = methodFound.model; if (model != null && model._inferredCallout != null) { // reset callout related stuff: methodFound.isMappingWrapper = WrapperKind.NONE; model._inferredCallout = null; methodFound.statements = null; // setup as a copied method: methodFound.isCopied = true; methodFound.binding.copyInheritanceSrc = method; methodFound.sourceMethodBinding = method; reuseFoundMethod = true; } } // do this in any case so that ConstantPoolObjectMapper won't fail: methodFound.binding.addOverriddenTSuper(method); // abstract methods have no byte code to copy; // new method silently replaces abstract version: if (method.isAbstract()) { weakenSignature(methodFound, method); return; } if (method.isFinal()) { methodFound.scope.problemReporter().finalMethodCannotBeOverridden(methodFound.binding, method); return; } weakenSignature(methodFound, method); MethodBinding foundSrc = methodFound.binding.copyInheritanceSrc; if (foundSrc != null && foundSrc != origin) { // found a copied method which has a different origin, choose the more specific: // if incommensurable prefer the new copy (assuming it comes from *implicit* super team) if (!TeamModel.isMoreSpecificThan(foundSrc.declaringClass, origin.declaringClass)) { // more specific method overwrites previous linkage: methodFound.binding.setCopyInheritanceSrc(origin); methodFound.sourceMethodBinding = origin; methodFound.isTSuper = TSuperHelper.isTSuper(method); // TODO(SH): also update CopyInheritanceSrc-Attribute! if (!method.isAbstract()) { // not abstract any more, joining abstract and implemented methods: methodFound.modifiers &= ~(AccAbstract | AccSemicolonBody); methodFound.binding.modifiers &= ~(AccAbstract | AccSemicolonBody); // TODO(SH): might need multiple copyInheritanceSrc! // TODO(SH) need to adjust copiedInContext? } } return; } } AstGenerator gen = new AstGenerator(targetRoleDecl.sourceStart, targetRoleDecl.sourceEnd); gen.replaceableEnclosingClass = tgtTeam; final AbstractMethodDeclaration newMethodDecl; if (methodFound != null && reuseFoundMethod) { newMethodDecl = methodFound; } else { newMethodDecl = AstConverter.createMethod(method, site, targetRoleDecl.compilationResult, DecapsulationState.REPORTED, gen); if (methodFound != null) TSuperHelper.addMarkerArg(newMethodDecl, srcTeam); if (newMethodDecl.isConstructor()) { // comments (SH): // other phases may depend on this field (constructorCall) being set, // although it carries no real information. ConstructorDeclaration cd = (ConstructorDeclaration) newMethodDecl; cd.constructorCall = SuperReference.implicitSuperConstructorCall(); if (Lifting.isLiftingCtor(method) && method.parameters[0].isRole()) { // if baseclass is implicitely redefined use the strong type: ReferenceBinding newBase = targetRoleDecl.binding.baseclass(); if (TypeBinding.notEquals(newBase, method.parameters[0])) newMethodDecl.arguments[0].type = gen.baseclassReference(newBase); } } AstEdit.addMethod(targetRoleDecl, newMethodDecl, wasSynthetic, false/*addToFront*/, origin); } if (method.isPrivate()) { newMethodDecl.binding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // don't warn unused copied method } newMethodDecl.binding.copiedInContext = tgtTeam.enclosingType(); MethodModel newModel = MethodModel.getModel(newMethodDecl); newModel.addAttribute(CopyInheritanceSourceAttribute.copyInherSrcAttribute(origin, newModel)); if (wasSynthetic) targetRoleDecl.getRoleModel().addSyntheticMethodMapping(method, newMethodDecl.binding); if (method.isAnyCallin() && !method.isCallin()) // callin wrapper newMethodDecl.isMappingWrapper = WrapperKind.CALLIN; if (methodFound == null) { // copy down some more properties: if (TSuperHelper.isTSuper(method)) newMethodDecl.isTSuper = true; if (method.model != null && method.model.callinFlags != 0) MethodModel.addCallinFlag(newMethodDecl, method.model.callinFlags); if (method.isAnyCallin()) { TypeBinding inheritedSrcReturn = MethodModel.getReturnType(method); if (inheritedSrcReturn.isRole()) inheritedSrcReturn = RoleTypeCreator.maybeWrapUnqualifiedRoleType(inheritedSrcReturn, targetRoleDecl.binding); MethodModel.saveReturnType(newMethodDecl.binding, inheritedSrcReturn); } else { if (!method.isPublic() // non-public source-level class method? && !method.isConstructor() && !targetRoleDecl.isInterface() && !CharOperation.prefixEquals(IOTConstants.OT_DOLLAR_NAME, method.selector)) { MethodModel.getModel(newMethodDecl).storeModifiers(newMethodDecl.modifiers); } } // more checking: abstract method in non-abstract class? if (newMethodDecl.isAbstract() && (targetRoleDecl.modifiers & ClassFileConstants.AccAbstract) == 0) { targetRoleDecl.scope.problemReporter().setRechecker(new IProblemRechecker() { public boolean shouldBeReported(IrritantSet[] foundIrritants) { if (newMethodDecl.isAbstract()) // implemented by callout? return true; return false; // false alarm } }).abstractMethodMustBeImplemented(targetRoleDecl.binding, newMethodDecl.binding); } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleSplitter.java
License:Open Source License
/** * After bindings have been created the synthetic interface is setup * to mirror the extends of the role class. * This method only treats the case of regular superclasses: * + copy signatures for all methods that are directly or inderictly * inherited (not including java.lang.Object). * (role superclasses are treated in linkSuperAndBaseInIfc()). * * @param teamDecl//from w w w.ja va 2 s . c o m * @param roleClass * @param roleIfcDecl */ public static void setupInterfaceForExtends(TypeDeclaration teamDecl, TypeDeclaration roleClass, TypeDeclaration roleIfcDecl) { ReferenceBinding superClass = roleClass.binding.superclass(); if (superClass == null) return; // current must be Confined if (superClass.isDirectRole() && !CharOperation.equals(superClass.internalName(), IOTConstants.OTCONFINED)) { return; // already processed in linkSuperAndBaseInIfc() } ReferenceBinding[] tsupers = roleClass.getRoleModel().getTSuperRoleBindings(); for (ReferenceBinding tsuperRole : tsupers) if (TypeBinding.equalsEquals(tsuperRole.superclass(), superClass)) return; // already included via tsuper. // workaround for mixed binary/source roles (cause for this situation unknown): if (roleIfcDecl == null) return; ReferenceBinding ifcBinding = roleIfcDecl.binding; ReferenceBinding javaLangObject = teamDecl.scope.getJavaLangObject(); AstGenerator gen; if (roleClass.superclass != null) gen = new AstGenerator(roleClass.superclass.sourceStart, roleClass.superclass.sourceEnd); else gen = new AstGenerator(roleClass.sourceStart, roleClass.sourceEnd); while (superClass != null && TypeBinding.notEquals(superClass, javaLangObject)) { MethodBinding[] methods = superClass.methods(); methodLoop: for (int i = 0; i < methods.length; i++) { MethodBinding m = methods[i]; if (m.isConstructor()) continue; // not inherited if (m.isPrivate()) continue; // not inherited if (m.isStatic()) continue; // not applicable in roles if (!m.isPublic()) { // not visible via interface MethodBinding existingMethod = TypeAnalyzer.findMethod(roleIfcDecl.scope, ifcBinding, m.selector, m.parameters); if (existingMethod != null && existingMethod.isValidBinding()) continue; ProblemMethodBinding problemMethod = new ProblemMethodBinding(m, m.selector, m.parameters, ProblemReasons.NotVisible); problemMethod.modifiers = m.modifiers; problemMethod.modifiers |= AccAbstract | AccSemicolonBody; // don't confuse the MethodVerifier with class method in ifc problemMethod.thrownExceptions = m.thrownExceptions; problemMethod.returnType = m.returnType; MethodModel.getModel(problemMethod).problemDetail = ProblemDetail.RoleInheritsNonPublic; ifcBinding.addMethod(problemMethod); // adding binding only as to support error reporting without generating new code continue; } for (int j = 0; j < IOTConstants.OT_KEYWORDS.length; j++) { if (CharOperation.equals(m.selector, IOTConstants.OT_KEYWORDS[j])) { roleClass.scope.problemReporter().inheritedNameIsOTKeyword(m, gen.sourceStart, gen.sourceEnd); continue methodLoop; } } MethodBinding declaredMethod = TypeAnalyzer.findCompatibleMethod(ifcBinding, m); if (declaredMethod == null) { MethodDeclaration newmethod = AstConverter.genIfcMethodFromBinding(teamDecl, m, gen); // the following also creates bindings, which helps to avoid // entering the same signature twice // (next time findCompatibleMethod() above will also find the new method). boolean wasSynthetic = false; if ((newmethod.modifiers & AccSynthetic) != 0) { wasSynthetic = true; newmethod.modifiers &= ~AccSynthetic; } AstEdit.addMethod(roleIfcDecl, newmethod, wasSynthetic, false, null/*copyInheritanceSrc*/); if (newmethod.binding != null) { newmethod.binding.tagBits |= TagBits.ClearPrivateModifier; newmethod.binding.copyInheritanceSrc = m; } } else { if (!Protections.isAsVisible(declaredMethod.modifiers, m.modifiers)) roleClass.scope.problemReporter().visibilityConflict(declaredMethod, m); } } superClass = superClass.superclass(); } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
private static void checkArrayLoweringForReturn(MethodBinding method, BlockScope scope) { int dimensions = method.returnType.dimensions(); if (dimensions == 0) return; // not an array if ((method.declaringClass.isRole() && !method.isPublic()) || method.isPrivate()) return; // not visible TypeBinding leafReturn = method.returnType.leafComponentType(); if (!leafReturn.isRole()) return; // not a role type TypeBinding baseType = ((ReferenceBinding) leafReturn).baseclass(); if (baseType == null) return; // not bound baseType = scope.createArrayType(baseType, dimensions); new ArrayLowering(null).ensureTransformMethod(scope, null, method.returnType, baseType, false); }