List of usage examples for org.eclipse.jdt.internal.compiler.ast AbstractMethodDeclaration hasErrors
@Override
public boolean hasErrors()
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseCallMessageSend.java
License:Open Source License
private void resolveSyntheticBaseCallSurrogate(MethodDeclaration outerCallinMethod, BlockScope scope, WeavingScheme weavingScheme) {//from w w w . ja v a 2 s .co m // find the method: AbstractMethodDeclaration callinMethodDecl = outerCallinMethod; if (callinMethodDecl == null) { if (checkContext(scope)) { callinMethodDecl = scope.methodScope().referenceMethod(); } else { return; // error reported by checkContext } } MethodBinding callinMethod = callinMethodDecl.binding; if (callinMethod == null) { if (callinMethodDecl.ignoreFurtherInvestigation) return; throw new InternalCompilerError("Unresolved method without an error"); //$NON-NLS-1$ } // check name match: if (!CharOperation.equals(this._sendOrig.selector, callinMethod.selector)) scope.problemReporter().baseCallNotSameMethod(callinMethodDecl, this._sendOrig); // find the receiver type: this._receiver.resolve(scope); int depth = 0; while (this._receiver.resolvedType.isLocalType()) { this._receiver.resolvedType = this._receiver.resolvedType.enclosingType(); depth++; } this._receiver.bits |= depth << DepthSHIFT; if (this._receiver.resolvedType instanceof ReferenceBinding) { ReferenceBinding receiverType = (ReferenceBinding) this._receiver.resolvedType; this._receiver.resolvedType = receiverType.getRealClass(); } // resolve arguments: TypeBinding[] sendparams = new TypeBinding[this._sendOrig.arguments.length]; for (int i = 0; i < sendparams.length; i++) sendparams[i] = this._sendOrig.arguments[i].resolveType(scope); // check arguments: int sourceArgsLen = 0; if (this.sourceArgs != null) sourceArgsLen = this.sourceArgs.length; TypeBinding[] methodParams = callinMethod.getSourceParameters(); if (sourceArgsLen != methodParams.length) { scope.problemReporter().baseCallDoesntMatchRoleMethodSignature(this); } else { for (int i = 0; i < sourceArgsLen; i++) { TypeBinding srcArgType = this.sourceArgs[i].resolvedType; if (srcArgType == null) { if (!callinMethodDecl.hasErrors()) throw new InternalCompilerError( "Unexpected: srcArgType should only ever be missing in declarations with reported errors"); //$NON-NLS-1$ continue; } if (!srcArgType.isCompatibleWith(methodParams[i])) { if (isBoxingCompatible(srcArgType, methodParams[i], this.sourceArgs[i], scope)) { int enhancedArgIdx = i + MethodSignatureEnhancer.getEnhancingArgLen(weavingScheme) + 1; // normal enhancement plus isSuperAccess flag this._sendOrig.arguments[enhancedArgIdx].computeConversion(scope, methodParams[i], srcArgType); } else { scope.problemReporter().baseCallDoesntMatchRoleMethodSignature(this); break; } } } } // create and link the synthetic method binding: MethodBinding surrogate = null; MethodModel model = callinMethod.model; if (model != null) surrogate = model.getBaseCallSurrogate(); if (surrogate == null) { SourceTypeBinding receiverClass = ((SourceTypeBinding) ((ReferenceBinding) this._receiver.resolvedType) .getRealClass()); if (SyntheticBaseCallSurrogate.isBindingForCallinMethodInherited(callinMethod)) { ReferenceBinding currentRole = callinMethod.declaringClass; while (surrogate == null && ((currentRole = currentRole.superclass()) != null)) { surrogate = receiverClass .getExactMethod(SyntheticBaseCallSurrogate.genSurrogateName(this.sourceSelector, currentRole.sourceName(), callinMethod.isStatic()), sendparams, null); } } else { surrogate = receiverClass.addSyntheticBaseCallSurrogate(callinMethod); } } this._sendOrig.binding = surrogate; this._sendOrig.actualReceiverType = this._receiver.resolvedType; this._sendOrig.constant = Constant.NotAConstant; this.resolvedType = this._sendOrig.resolvedType = MethodModel.getReturnType(this._sendOrig.binding); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java
License:Open Source License
/** * This method should ensure, that an interface does not provide the same * method as an implicitly inherited method but with a more specific signature * Since role interfaces are created by the RoleSplitter, at that time nothing * was known about method signatures of tsuper roles. * Also check whether all methods of roleType are compatible with implicitly * inherited versions from tsuperRole (visibility, exceptions etc.). * Perform these checks on the interface parts only, since class versions have * their visibilities twisted./*from w ww . j a v a2 s. co m*/ * @param superRoleIfc lookup methods here, to match ours against. * @param subTeam * @param subRoleIfcDecl this type declaration is edited. */ public static void weakenInterfaceSignatures(ReferenceBinding superRoleIfc, ReferenceBinding subTeam, TypeDeclaration subRoleIfcDecl) { ReferenceBinding superTeam = superRoleIfc.enclosingType(); MethodBinding[] superMethods = superRoleIfc.methods(); checkPrivateMethods(superTeam, superMethods, subTeam, subRoleIfcDecl); AbstractMethodDeclaration[] oldMethods = subRoleIfcDecl.methods; if (oldMethods == null) return; MethodVerifier verifier = subRoleIfcDecl.scope.environment().methodVerifier(); // collect methods that match an implicitly inherited method HashSet<AbstractMethodDeclaration> foundMethodDecls = new HashSet<AbstractMethodDeclaration>(); HashSet<MethodBinding> foundMethodBinds = new HashSet<MethodBinding>(); for (int i = 0; i < superMethods.length; i++) { MethodBinding inheritedMethod = superMethods[i]; AbstractMethodDeclaration methodFound = findMethod(superTeam, superMethods[i], subTeam, subRoleIfcDecl); if ((methodFound != null) && (methodFound.binding != null)) // do not touch broken methods { // check compatibility before removing: if (inheritedMethod.isValidBinding()) { verifier.checkAgainstImplicitlyInherited(subRoleIfcDecl.binding, subTeam, methodFound.binding, superTeam, inheritedMethod); } if ((!methodFound.isGenerated // don't remove generated methods || methodFound.hasErrors()) // unless erroneous && !methodFound.isDefaultMethod()) { foundMethodDecls.add(methodFound); foundMethodBinds.add(methodFound.binding); } } } int declarationLen = oldMethods.length - foundMethodDecls.size(); // remove matching declarations: subRoleIfcDecl.methods = new AbstractMethodDeclaration[declarationLen]; reduceArray(oldMethods, subRoleIfcDecl.methods, foundMethodDecls); //invalid method-bindings has been removed from methods-binding-array in faultInTypes int bindingLen = subRoleIfcDecl.binding.methods().length - foundMethodBinds.size(); // remove matching bindings SourceTypeBinding subRoleBind = subRoleIfcDecl.binding; subRoleBind.reduceMethods(foundMethodBinds, bindingLen); // recurse to interfaces (including tsuper): ReferenceBinding[] superInterfaces = superRoleIfc.superInterfaces(); for (int i = 0; i < superInterfaces.length; i++) { ReferenceBinding superIfc = superInterfaces[i]; if (superIfc.isSynthInterface()) weakenInterfaceSignatures(superIfc, subTeam, subRoleIfcDecl); } }
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 w ww . ja va 2s.com*/ * <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; }