List of usage examples for org.eclipse.jdt.internal.compiler.ast AbstractMethodDeclaration tagAsHavingErrors
@Override public void tagAsHavingErrors()
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.CalloutMappingDeclaration.java
License:Open Source License
@Override protected void checkModifiers(boolean haveBaseMethods, ReferenceBinding baseType) { boolean roleHasImplementation = false; MethodBinding roleMethod = this.roleMethodSpec.resolvedMethod; if (!roleMethod.isValidBinding()) return;/* w ww. j ava 2 s .c o m*/ // update modifiers after tsuper has generated callout methods (perhaps giving implementation to abstract decl) if (roleMethod.isAbstract() && roleMethod.copyInheritanceSrc != null && !roleMethod.copyInheritanceSrc.isAbstract()) roleMethod.modifiers &= ~ClassFileConstants.AccAbstract; roleHasImplementation = !roleMethod.isAbstract() && !roleMethod.isDefaultMethod(); if (roleHasImplementation != isCalloutOverride()) { if (roleHasImplementation) { if (isCalloutMethod(roleMethod)) { if (TypeBinding.notEquals(roleMethod.declaringClass, this.scope.enclosingSourceType()) || roleMethod.copyInheritanceSrc != null) // "local" callouts (not copied) are treated in { // MethodMappingResolver.checkForDuplicateMethodMappings() this.scope.problemReporter().regularCalloutOverridesCallout(this, roleMethod); } } else { this.scope.problemReporter().regularCalloutOverrides(this); } } else // isCalloutOverride() but not really overriding { this.scope.problemReporter().abstractMethodBoundAsOverrideCallout(this); AbstractMethodDeclaration roleMethodDeclaration = roleMethod.sourceMethod(); if (roleMethodDeclaration != null) { roleMethodDeclaration.ignoreFurtherInvestigation = true; this.ignoreFurtherInvestigation = true; } } } if (roleMethod.isCallin()) { this.scope.problemReporter().calloutBindingCallin(this.roleMethodSpec); } if (hasErrors()) { // unsuccessful attempt to implement role method as callout, // mark the method as erroneous: if (this.roleMethodSpec.resolvedMethod != null && this.roleMethodSpec.resolvedMethod.isAbstract()) { AbstractMethodDeclaration methodDecl = this.roleMethodSpec.resolvedMethod.sourceMethod(); if (methodDecl != null) methodDecl.tagAsHavingErrors(); // prevent abstract-error } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java
License:Open Source License
/** * For a given role method adjust its signature according to the * tsuper-role version which is provided by its binding. * For each argument type:/*from www .ja v a 2 s . c o m*/ * <ul> * <li> if it is a role type, make it refer explicitly to the type in the super team * <li> for each parameter whose type is adjusted insert a new local with the desired * type and cast the provided argument value to this local. * <li> replace arguments in super calls of a constructor by the renamed and * and casted argument. * </ul> * E.g., the constructor * <pre> Role (Role2 r) { * super(r); * print(r); * }</pre> * becomes: * <pre> Role (SuperTeam.Role2 __OT__r) { * super((Role2)__OT__r); * Role2 r = (Role2)__OT__r; * print(r); * </pre> * @param method method to adjust * @param template the tsuper version which should be taken as master for adjustment. * @return has weakening been performed? */ public static boolean weakenSignature(AbstractMethodDeclaration method, MethodBinding template) { MethodBinding binding = method.binding; // no weakening for constructors: if (method.isConstructor()) return false; // do not touch broken methods: if (binding == null || method.hasErrors()) return false; if (MethodModel.hasProblem(template)) { method.tagAsHavingErrors(); // propagate error return false; } MethodScope scope = method.scope; boolean changed = false; // true weakening (with weakened type binding) avoids bridge methods if (TypeBinding.notEquals(method.binding.returnType, template.returnType) && method.binding.returnType instanceof DependentTypeBinding) method.binding.returnType = WeakenedTypeBinding.makeWeakenedTypeBinding( (DependentTypeBinding) method.binding.returnType.leafComponentType(), (ReferenceBinding) template.returnType.leafComponentType(), template.returnType.dimensions()); // liftTo methods have no role arguments if (Lifting.isLiftToMethod(method.binding)) return changed; // Method parameters int paramLen = binding.parameters.length; assert (paramLen == template.parameters.length); if (paramLen == 0) return changed; if (method.isConstructor() && binding.declaringClass.isTeam()) return changed; // already processed by Lifting.prepareArgLifting() (includes a cast). // selectively share type bindings, but not the array: for (int i = 0; i < paramLen; i++) { TypeBinding param = binding.parameters[i]; TypeBinding tmplParam = template.parameters[i]; if (param.isRole()) { binding.parameters[i] = template.parameters[i]; if (param.isParameterizedType() && tmplParam.isParameterizedType()) { // keep old type arguments, just replace the type itself TypeBinding[] args = ((ParameterizedTypeBinding) param).arguments; ReferenceBinding tmplType = ((ParameterizedTypeBinding) tmplParam).genericType(); try { LookupEnvironment env = Config.getLookupEnvironment(); binding.parameters[i] = new ParameterizedTypeBinding(tmplType, args, tmplType.enclosingType(), env); } catch (NotConfiguredException e) { e.logWarning("Cannot create parameterized type"); //$NON-NLS-1$ } } } } // below: treat statements. if (method.isAbstract()) return changed; if (method.isCopied) return changed; // no statements ArrayList<Statement> newLocalStats = new ArrayList<Statement>(); for (int i = 0; i < method.arguments.length; i++) { final Argument argument = method.arguments[i]; char[] oldName = argument.name; if (RoleTypeBinding.isRoleWithExplicitAnchor(argument.type.resolvedType)) continue; TypeReference newType = TypeAnalyzer.weakenTypeReferenceFromBinding(scope, argument.type, argument.binding.type, binding.parameters[i]); if (newType != argument.type) { changed = true; newType.setBaseclassDecapsulation(argument.type.getBaseclassDecapsulation()); // local variable: newLocalStats.add(generateCastedLocal(argument, newType)); // replace arguments in super-constructor call: if (method instanceof ConstructorDeclaration) { ConstructorDeclaration ctor = (ConstructorDeclaration) method; ReplaceSingleNameVisitor.IExpressionProvider provider = new ReplaceSingleNameVisitor.IExpressionProvider() { public Expression newExpression() { return new SingleNameReference(argument.name, argument.sourceStart); } }; if (ctor.constructorCall != null) ctor.constructorCall.traverse(new ReplaceSingleNameVisitor(oldName, provider), null); // no scope } } } if (!binding.declaringClass.isDirectRole() && CharOperation.equals(binding.selector, IOTConstants.INIT_METHOD_NAME)) return changed; // no statements, not casted locals. if (!newLocalStats.isEmpty()) { if (StateHelper.hasState(binding.declaringClass, ITranslationStates.STATE_RESOLVED)) for (Statement localDeclaration : newLocalStats) localDeclaration.resolve(method.scope); // add the local variable declaration statements: MethodModel.prependStatements(method, newLocalStats); } return changed; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.SerializationGenerator.java
License:Open Source License
/** * Fill in the statement of a previously generated restoreRole() method. * @param teamType type declaration assumeably holding an empty restoreRole method. * @param caches all declarations of role caches of this team type. *//*from w w w . j av a2 s. c o m*/ public static void fillRestoreRole(TypeDeclaration teamType, FieldDeclaration[] caches) { AbstractMethodDeclaration restoreMethod = TypeAnalyzer.findMethodDecl(teamType, RESTORE_ROLE, 2); if (restoreMethod == null) { return; } boolean superIsTeam = teamType.binding.superclass.isTeam(); AstGenerator gen = new AstGenerator(restoreMethod); // re-use position Statement[] statements = new Statement[caches.length + (superIsTeam ? 1 : 0)]; // find the matching cache for argument Class clazz: for (int i = 0; i < caches.length; i++) { // FIXME(SH): unclear if needed after allowing generated qualified role type referneces: TypeReference cacheTypeRef = caches[i].type; // robustness, but with wrong source position if (!cacheTypeRef.resolvedType.isParameterizedType() || ((ParameterizedTypeBinding) cacheTypeRef.resolvedType).arguments.length != 2) { if (teamType.scope.environment().globalOptions.complianceLevel < ClassFileConstants.JDK1_5) { restoreMethod.statements = new Statement[] { gen.emptyStatement() }; restoreMethod.tagAsHavingErrors(); return; // incompatible compliance level, assume errors have been reported. } throw new InternalCompilerError("Unexpected resolved cache type " + cacheTypeRef.resolvedType); //$NON-NLS-1$ } // reconstruct a type reference from the resolved cache type ParameterizedTypeBinding oldBinding = (ParameterizedTypeBinding) cacheTypeRef.resolvedType; ReferenceBinding roleBinding = (ReferenceBinding) oldBinding.arguments[1]; // respect different status for base/role types (scope, decapsulation). cacheTypeRef = gen.getCacheTypeReference(teamType.scope, roleBinding.roleModel); statements[i] = gen.ifStatement( // if (Role.class.isAssignableFrom(clazz)) { ... gen.messageSend(gen.classLiteralAccess(gen.typeReference(roleBinding)), IS_ASSIGNABLE_FROM, new Expression[] { gen.singleNameReference(CLASS_ARG_NAME) }), gen.block(new Statement[] { // Role castedRole = (Role) role; gen.localVariable(CASTED_ROLE, roleBinding, gen.castExpression(gen.singleNameReference(ROLE_ARG_NAME), gen.typeReference(roleBinding), CastExpression.RAW)), // Base base = role._OT$getBase(); gen.localVariable(IOTConstants.BASE, gen.baseclassReference(roleBinding.baseclass(), true /*erase*/), gen.messageSend(gen.singleNameReference(CASTED_ROLE), IOTConstants._OT_GETBASE, null/*arguments*/)), // <roleCache[i]>.put(base, castedRole); gen.messageSend(gen.singleNameReference(caches[i].name), PUT, new Expression[] { gen.baseNameReference(IOTConstants.BASE), gen.singleNameReference(CASTED_ROLE) }), // ((IBoundBase)base)._OT$addRole(castedRole); // OTDYN: Slightly different methods depending on the weaving strategy: teamType.scope.compilerOptions().weavingScheme == WeavingScheme.OTDRE ? gen.messageSend( gen.castExpression(gen.singleNameReference(IOTConstants.BASE), gen.qualifiedTypeReference( IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE2), CastExpression.RAW), IOTConstants.ADD_REMOVE_ROLE, new Expression[] { gen.singleNameReference(CASTED_ROLE), gen.booleanLiteral(true) }) : gen.messageSend( gen.castExpression(gen.singleNameReference(IOTConstants.BASE), gen.qualifiedTypeReference( IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE), CastExpression.RAW), IOTConstants.ADD_ROLE, new Expression[] { gen.singleNameReference(CASTED_ROLE) }), // return; // don't consult further caches gen.returnStatement(null) })); } if (superIsTeam) { // if no suitable cache found so far: // super.restoreRole(clazz, role); statements[caches.length] = gen.messageSend(gen.superReference(), RESTORE_ROLE, new Expression[] { gen.singleNameReference(CLASS_ARG_NAME), gen.singleNameReference(ROLE_ARG_NAME) }); } restoreMethod.setStatements(statements); if (StateMemento.hasMethodResolveStarted(teamType.binding)) restoreMethod.resolve(teamType.scope); }