List of usage examples for org.eclipse.jdt.internal.compiler.lookup Binding NO_EXCEPTIONS
ReferenceBinding[] NO_EXCEPTIONS
To view the source code for org.eclipse.jdt.internal.compiler.lookup Binding NO_EXCEPTIONS.
Click Source Link
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public MethodBinding findExactMethod(ReferenceBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) { CompilationUnitScope unitScope = compilationUnitScope(); unitScope.recordTypeReferences(argumentTypes); MethodBinding exactMethod = receiverType.getExactMethod(selector, argumentTypes, unitScope); if (exactMethod != null && exactMethod.typeVariables == Binding.NO_TYPE_VARIABLES && !exactMethod.isBridge()) { // in >= 1.5 mode, ensure the exactMatch did not match raw types if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) for (int i = argumentTypes.length; --i >= 0;) if (isPossibleSubtypeOfRawType(argumentTypes[i])) return null; // must find both methods for this case: <S extends A> void foo() {} and <N extends B> N foo() { return null; } // or find an inherited method when the exact match is to a bridge method unitScope.recordTypeReferences(exactMethod.thrownExceptions); if (exactMethod.isAbstract() && exactMethod.thrownExceptions != Binding.NO_EXCEPTIONS) return null; // may need to merge exceptions with interface method // special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type) if (receiverType.isInterface() || exactMethod.canBeSeenBy(receiverType, invocationSite, this)) { if (argumentTypes == Binding.NO_PARAMETERS && CharOperation.equals(selector, TypeConstants.GETCLASS) && exactMethod.returnType.isParameterizedType()/*1.5*/) { return environment().createGetClassMethod(receiverType, exactMethod, this); }// ww w .j a v a2 s . c om // targeting a generic method could find an exact match with variable return type if (invocationSite.genericTypeArguments() != null) { exactMethod = computeCompatibleMethod(exactMethod, argumentTypes, invocationSite); } return exactMethod; } } return null; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
protected final MethodBinding mostSpecificMethodBinding(MethodBinding[] visible, int visibleSize, TypeBinding[] argumentTypes, final InvocationSite invocationSite, ReferenceBinding receiverType) { int[] compatibilityLevels = new int[visibleSize]; for (int i = 0; i < visibleSize; i++) compatibilityLevels[i] = parameterCompatibilityLevel(visible[i], argumentTypes); InvocationSite tieBreakInvocationSite = new InvocationSite() { public TypeBinding[] genericTypeArguments() { return null; } // ignore genericTypeArgs public boolean isSuperAccess() { return invocationSite.isSuperAccess(); }/*from w ww .ja v a 2 s . com*/ public boolean isTypeAccess() { return invocationSite.isTypeAccess(); } public void setActualReceiverType(ReferenceBinding actualReceiverType) { /* ignore */} public void setDepth(int depth) { /* ignore */} public void setFieldIndex(int depth) { /* ignore */} public int sourceStart() { return invocationSite.sourceStart(); } public int sourceEnd() { return invocationSite.sourceStart(); } public TypeBinding expectedType() { return invocationSite.expectedType(); } }; MethodBinding[] moreSpecific = new MethodBinding[visibleSize]; int count = 0; for (int level = 0, max = VARARGS_COMPATIBLE; level <= max; level++) { nextVisible: for (int i = 0; i < visibleSize; i++) { if (compatibilityLevels[i] != level) continue nextVisible; max = level; // do not examine further categories, will either return mostSpecific or report ambiguous case MethodBinding current = visible[i]; MethodBinding original = current.original(); MethodBinding tiebreakMethod = current.tiebreakMethod(); for (int j = 0; j < visibleSize; j++) { if (i == j || compatibilityLevels[j] != level) continue; MethodBinding next = visible[j]; if (original == next.original()) { // parameterized superclasses & interfaces may be walked twice from different paths so skip next from now on compatibilityLevels[j] = -1; continue; } MethodBinding methodToTest = next; if (next instanceof ParameterizedGenericMethodBinding) { ParameterizedGenericMethodBinding pNext = (ParameterizedGenericMethodBinding) next; if (pNext.isRaw && !pNext.isStatic()) { // hold onto the raw substituted method } else { methodToTest = pNext.originalMethod; } } MethodBinding acceptable = computeCompatibleMethod(methodToTest, tiebreakMethod.parameters, tieBreakInvocationSite); /* There are 4 choices to consider with current & next : foo(B) & foo(A) where B extends A 1. the 2 methods are equal (both accept each others parameters) -> want to continue 2. current has more specific parameters than next (so acceptable is a valid method) -> want to continue 3. current has less specific parameters than next (so acceptable is null) -> go on to next 4. current and next are not compatible with each other (so acceptable is null) -> go on to next */ if (acceptable == null || !acceptable.isValidBinding()) continue nextVisible; if (!isAcceptableMethod(tiebreakMethod, acceptable)) continue nextVisible; // pick a concrete method over a bridge method when parameters are equal since the return type of the concrete method is more specific if (current.isBridge() && !next.isBridge()) if (tiebreakMethod.areParametersEqual(acceptable)) continue nextVisible; // skip current so acceptable wins over this bridge method } moreSpecific[i] = current; count++; } } if (count == 1) { for (int i = 0; i < visibleSize; i++) { if (moreSpecific[i] != null) { compilationUnitScope().recordTypeReferences(visible[i].thrownExceptions); return visible[i]; } } } else if (count == 0) { return new ProblemMethodBinding(visible[0], visible[0].selector, visible[0].parameters, ProblemReasons.Ambiguous); } // found several methods that are mutually acceptable -> must be equal // so now with the first acceptable method, find the 'correct' inherited method for each other acceptable method AND // see if they are equal after substitution of type variables (do the type variables have to be equal to be considered an override???) if (receiverType != null) receiverType = receiverType instanceof CaptureBinding ? receiverType : (ReferenceBinding) receiverType.erasure(); nextSpecific: for (int i = 0; i < visibleSize; i++) { MethodBinding current = moreSpecific[i]; if (current != null) { ReferenceBinding[] mostSpecificExceptions = null; MethodBinding original = current.original(); boolean shouldIntersectExceptions = original.declaringClass.isAbstract() && original.thrownExceptions != Binding.NO_EXCEPTIONS; // only needed when selecting from interface methods for (int j = 0; j < visibleSize; j++) { MethodBinding next = moreSpecific[j]; if (next == null || i == j) continue; MethodBinding original2 = next.original(); if (original.declaringClass == original2.declaringClass) break nextSpecific; // duplicates thru substitution if (!original.isAbstract()) { if (original2.isAbstract()) continue; // only compare current against other concrete methods original2 = original.findOriginalInheritedMethod(original2); if (original2 == null) continue nextSpecific; // current's declaringClass is not a subtype of next's declaringClass if (current.hasSubstitutedParameters() || original.typeVariables != Binding.NO_TYPE_VARIABLES) { if (!environment().methodVerifier().isParameterSubsignature(original, original2)) continue nextSpecific; // current does not override next } } else if (receiverType != null) { // should not be null if original isAbstract, but be safe TypeBinding superType = receiverType .findSuperTypeOriginatingFrom(original.declaringClass.erasure()); if (original.declaringClass == superType || !(superType instanceof ReferenceBinding)) { // keep original } else { // must find inherited method with the same substituted variables MethodBinding[] superMethods = ((ReferenceBinding) superType) .getMethods(original.selector, argumentTypes.length); for (int m = 0, l = superMethods.length; m < l; m++) { if (superMethods[m].original() == original) { original = superMethods[m]; break; } } } superType = receiverType.findSuperTypeOriginatingFrom(original2.declaringClass.erasure()); if (original2.declaringClass == superType || !(superType instanceof ReferenceBinding)) { // keep original2 } else { // must find inherited method with the same substituted variables MethodBinding[] superMethods = ((ReferenceBinding) superType) .getMethods(original2.selector, argumentTypes.length); for (int m = 0, l = superMethods.length; m < l; m++) { if (superMethods[m].original() == original2) { original2 = superMethods[m]; break; } } } if (original.typeVariables != Binding.NO_TYPE_VARIABLES) original2 = original.computeSubstitutedMethod(original2, environment()); if (original2 == null || !original.areParameterErasuresEqual(original2)) continue nextSpecific; // current does not override next if (original.returnType != original2.returnType) { if (next.original().typeVariables != Binding.NO_TYPE_VARIABLES) { if (original.returnType.erasure() .findSuperTypeOriginatingFrom(original2.returnType.erasure()) == null) continue nextSpecific; } else if (!current.returnType.isCompatibleWith(next.returnType)) { continue nextSpecific; } // continue with original 15.12.2.5 } if (shouldIntersectExceptions && original2.declaringClass.isInterface()) { if (current.thrownExceptions != next.thrownExceptions) { if (next.thrownExceptions == Binding.NO_EXCEPTIONS) { mostSpecificExceptions = Binding.NO_EXCEPTIONS; } else { if (mostSpecificExceptions == null) { mostSpecificExceptions = current.thrownExceptions; } int mostSpecificLength = mostSpecificExceptions.length; int nextLength = next.thrownExceptions.length; SimpleSet temp = new SimpleSet(mostSpecificLength); boolean changed = false; nextException: for (int t = 0; t < mostSpecificLength; t++) { ReferenceBinding exception = mostSpecificExceptions[t]; for (int s = 0; s < nextLength; s++) { ReferenceBinding nextException = next.thrownExceptions[s]; if (exception.isCompatibleWith(nextException)) { temp.add(exception); continue nextException; } else if (nextException.isCompatibleWith(exception)) { temp.add(nextException); changed = true; continue nextException; } else { changed = true; } } } if (changed) { mostSpecificExceptions = temp.elementSize == 0 ? Binding.NO_EXCEPTIONS : new ReferenceBinding[temp.elementSize]; temp.asArray(mostSpecificExceptions); } } } } } } if (mostSpecificExceptions != null && mostSpecificExceptions != current.thrownExceptions) { return new MostSpecificExceptionMethodBinding(current, mostSpecificExceptions); } return current; } } // if all moreSpecific methods are equal then see if duplicates exist because of substitution return new ProblemMethodBinding(visible[0], visible[0].selector, visible[0].parameters, ProblemReasons.Ambiguous); }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public MethodBinding getStaticFactory(ReferenceBinding allocationType, ReferenceBinding originalEnclosingType, TypeBinding[] argumentTypes, final InvocationSite allocationSite) { TypeVariableBinding[] classTypeVariables = allocationType.typeVariables(); int classTypeVariablesArity = classTypeVariables.length; MethodBinding[] methods = allocationType.getMethods(TypeConstants.INIT, argumentTypes.length); MethodBinding[] staticFactories = new MethodBinding[methods.length]; int sfi = 0;//from w w w .ja va2 s . co m for (int i = 0, length = methods.length; i < length; i++) { MethodBinding method = methods[i]; int paramLength = method.parameters.length; boolean isVarArgs = method.isVarargs(); if (argumentTypes.length != paramLength) if (!isVarArgs || argumentTypes.length < paramLength - 1) continue; // incompatible TypeVariableBinding[] methodTypeVariables = method.typeVariables(); int methodTypeVariablesArity = methodTypeVariables.length; MethodBinding staticFactory = new MethodBinding(method.modifiers | ClassFileConstants.AccStatic, TypeConstants.SYNTHETIC_STATIC_FACTORY, null, null, null, method.declaringClass); staticFactory.typeVariables = new TypeVariableBinding[classTypeVariablesArity + methodTypeVariablesArity]; final SimpleLookupTable map = new SimpleLookupTable(classTypeVariablesArity + methodTypeVariablesArity); // Rename each type variable T of the type to T' final LookupEnvironment environment = environment(); for (int j = 0; j < classTypeVariablesArity; j++) { map.put(classTypeVariables[j], staticFactory.typeVariables[j] = new TypeVariableBinding( CharOperation.concat(classTypeVariables[j].sourceName, "'".toCharArray()), //$NON-NLS-1$ staticFactory, j, environment)); } // Rename each type variable U of method U to U''. for (int j = classTypeVariablesArity, max = classTypeVariablesArity + methodTypeVariablesArity; j < max; j++) { map.put(methodTypeVariables[j - classTypeVariablesArity], (staticFactory.typeVariables[j] = new TypeVariableBinding( CharOperation.concat(methodTypeVariables[j - classTypeVariablesArity].sourceName, "''".toCharArray()), //$NON-NLS-1$ staticFactory, j, environment))); } ReferenceBinding enclosingType = originalEnclosingType; while (enclosingType != null) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=345968 if (enclosingType.kind() == Binding.PARAMETERIZED_TYPE) { final ParameterizedTypeBinding parameterizedType = (ParameterizedTypeBinding) enclosingType; final ReferenceBinding genericType = parameterizedType.genericType(); TypeVariableBinding[] enclosingClassTypeVariables = genericType.typeVariables(); int enclosingClassTypeVariablesArity = enclosingClassTypeVariables.length; for (int j = 0; j < enclosingClassTypeVariablesArity; j++) { map.put(enclosingClassTypeVariables[j], parameterizedType.arguments[j]); } } enclosingType = enclosingType.enclosingType(); } final Scope scope = this; Substitution substitution = new Substitution() { public LookupEnvironment environment() { return scope.environment(); } public boolean isRawSubstitution() { return false; } public TypeBinding substitute(TypeVariableBinding typeVariable) { TypeBinding retVal = (TypeBinding) map.get(typeVariable); return retVal != null ? retVal : typeVariable; } }; // initialize new variable bounds for (int j = 0, max = classTypeVariablesArity + methodTypeVariablesArity; j < max; j++) { TypeVariableBinding originalVariable = j < classTypeVariablesArity ? classTypeVariables[j] : methodTypeVariables[j - classTypeVariablesArity]; TypeBinding substitutedType = (TypeBinding) map.get(originalVariable); if (substitutedType instanceof TypeVariableBinding) { TypeVariableBinding substitutedVariable = (TypeVariableBinding) substitutedType; TypeBinding substitutedSuperclass = Scope.substitute(substitution, originalVariable.superclass); ReferenceBinding[] substitutedInterfaces = Scope.substitute(substitution, originalVariable.superInterfaces); if (originalVariable.firstBound != null) { substitutedVariable.firstBound = originalVariable.firstBound == originalVariable.superclass ? substitutedSuperclass // could be array type or interface : substitutedInterfaces[0]; } switch (substitutedSuperclass.kind()) { case Binding.ARRAY_TYPE: substitutedVariable.superclass = environment.getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null); substitutedVariable.superInterfaces = substitutedInterfaces; break; default: if (substitutedSuperclass.isInterface()) { substitutedVariable.superclass = environment .getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null); int interfaceCount = substitutedInterfaces.length; System.arraycopy(substitutedInterfaces, 0, substitutedInterfaces = new ReferenceBinding[interfaceCount + 1], 1, interfaceCount); substitutedInterfaces[0] = (ReferenceBinding) substitutedSuperclass; substitutedVariable.superInterfaces = substitutedInterfaces; } else { substitutedVariable.superclass = (ReferenceBinding) substitutedSuperclass; // typeVar was extending other typeVar which got substituted with interface substitutedVariable.superInterfaces = substitutedInterfaces; } } } } TypeVariableBinding[] returnTypeParameters = new TypeVariableBinding[classTypeVariablesArity]; for (int j = 0; j < classTypeVariablesArity; j++) { returnTypeParameters[j] = (TypeVariableBinding) map.get(classTypeVariables[j]); } staticFactory.returnType = environment.createParameterizedType(allocationType, returnTypeParameters, allocationType.enclosingType()); staticFactory.parameters = Scope.substitute(substitution, method.parameters); staticFactory.thrownExceptions = Scope.substitute(substitution, method.thrownExceptions); if (staticFactory.thrownExceptions == null) { staticFactory.thrownExceptions = Binding.NO_EXCEPTIONS; } staticFactories[sfi++] = new ParameterizedMethodBinding( (ParameterizedTypeBinding) environment.convertToParameterizedType(staticFactory.declaringClass), staticFactory); } if (sfi == 0) return null; if (sfi != methods.length) { System.arraycopy(staticFactories, 0, staticFactories = new MethodBinding[sfi], 0, sfi); } MethodBinding[] compatible = new MethodBinding[sfi]; int compatibleIndex = 0; for (int i = 0; i < sfi; i++) { MethodBinding compatibleMethod = computeCompatibleMethod(staticFactories[i], argumentTypes, allocationSite); if (compatibleMethod != null) { if (compatibleMethod.isValidBinding()) compatible[compatibleIndex++] = compatibleMethod; } } if (compatibleIndex == 0) { return null; } MethodBinding[] visible = new MethodBinding[compatibleIndex]; int visibleIndex = 0; for (int i = 0; i < compatibleIndex; i++) { MethodBinding method = compatible[i]; if (method.canBeSeenBy(allocationSite, this)) visible[visibleIndex++] = method; } if (visibleIndex == 0) { return null; } return visibleIndex == 1 ? visible[0] : mostSpecificMethodBinding(visible, visibleIndex, argumentTypes, allocationSite, allocationType); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseAllocationExpression.java
License:Open Source License
public static Expression convertToDynAccess(BlockScope scope, AllocationExpression expression, int accessId) { TypeBinding baseclass = expression.resolvedType; AstGenerator gen = new AstGenerator(expression); Expression receiver = gen.typeReference(baseclass); char[] selector = CalloutImplementorDyn.OT_ACCESS_STATIC; int modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic; Expression[] arguments = expression.arguments; Expression enclosingInstance = null; if (expression instanceof QualifiedAllocationExpression) { enclosingInstance = ((QualifiedAllocationExpression) expression).enclosingInstance; } else if (baseclass.isMemberType()) { // extract the enclosing base instance from an outer playedBy: ReferenceBinding enclosingTeam = scope.enclosingReceiverType().enclosingType(); if (enclosingTeam != null && TypeBinding.equalsEquals(baseclass.enclosingType(), enclosingTeam.baseclass)) { enclosingInstance = gen.fieldReference(gen.qualifiedThisReference(gen.typeReference(enclosingTeam)), IOTConstants._OT_BASE); enclosingInstance.resolve(scope); }/*from w ww . j a va 2 s .c o m*/ } if (enclosingInstance != null) { if (arguments == null) { arguments = new Expression[] { enclosingInstance }; } else { int len = arguments.length; System.arraycopy(arguments, 0, arguments = new Expression[len + 1], 1, len); arguments[0] = enclosingInstance; } } MessageSend allocSend = new MessageSend() { @Override public boolean isDecapsulationAllowed(Scope scope2) { // this message send can decapsulate independent of scope return true; } @Override public DecapsulationState getBaseclassDecapsulation() { return DecapsulationState.ALLOWED; } }; gen.setPositions(allocSend); allocSend.receiver = receiver; allocSend.selector = selector; allocSend.constant = Constant.NotAConstant; allocSend.actualReceiverType = baseclass; allocSend.accessId = accessId; allocSend.arguments = createResolvedAccessArguments(gen, accessId, arguments, scope); allocSend.binding = new MethodBinding(modifiers, new TypeBinding[] { TypeBinding.INT, TypeBinding.INT, scope.createArrayType(scope.getJavaLangObject(), 1), scope.getOrgObjectteamsITeam() }, Binding.NO_EXCEPTIONS, (ReferenceBinding) baseclass); allocSend.binding.returnType = scope.getJavaLangObject(); allocSend.binding.selector = selector; return gen.resolvedCastExpression(allocSend, baseclass, CastExpression.RAW); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.FieldAccessSpec.java
License:Open Source License
/** * Create a faked method binding representing the access method to be generated by OTRE. *//* www . ja v a2s. com*/ private MethodBinding createMethod(Scope scope, ReferenceBinding baseType, char[] accessorSelector) { if (baseType.isRoleType()) baseType = baseType.getRealClass(); if (this.calloutModifier == TerminalTokens.TokenNameget) { // Use the actual field type rather than the expected type (role view) // because several callouts to the same field could exist. // RoleTypeCreator.maybeWrapQualifiedRoleType(MessageSend,BlockScope) // will wrap the type using a faked _OT$base receiver. return FieldModel.getDecapsulatingFieldAccessor(scope, baseType, this.resolvedField, true, this.implementationStrategy); } else { TypeBinding declaredFieldType = this.hasSignature ? this.parameters[0] : this.fieldType; int access; TypeBinding[] argTypes; if (this.implementationStrategy == ImplementationStrategy.DYN_ACCESS) { access = ClassFileConstants.AccPublic; argTypes = new TypeBinding[] { declaredFieldType }; } else { access = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic; argTypes = this.resolvedField.isStatic() ? new TypeBinding[] { declaredFieldType } : new TypeBinding[] { baseType, declaredFieldType }; } MethodBinding result = new MethodBinding(access, accessorSelector, TypeBinding.VOID, argTypes, Binding.NO_EXCEPTIONS, baseType); baseType.addMethod(result); return result; } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.GuardPredicateDeclaration.java
License:Open Source License
Statement tryCatch(Statement tryStatement, TypeReference exceptionType, Statement catchStatement) { TryStatement result = new TryStatement() { @Override/*w w w . j a v a2 s . c o m*/ protected ExceptionHandlingFlowContext createFlowContext(FlowContext flowContext, FlowInfo flowInfo) { return new ExceptionHandlingFlowContext(flowContext, this, Binding.NO_EXCEPTIONS, // treat all exceptions as undeclared, want to see the error/warning new int[0], null, // initializationParent this.scope, flowInfo) { @Override public UnconditionalFlowInfo initsOnException(int index) { return new UnconditionalFlowInfo(); // empty, avoid AIOOBE in super method (empty array initsOnExceptions) } }; } }; result.sourceStart = this.sourceStart; result.sourceEnd = this.sourceEnd; // fill sub-elements: AstGenerator gen = new AstGenerator(this.sourceStart, this.sourceEnd); result.tryBlock = gen.block(new Statement[] { tryStatement }); result.catchArguments = new Argument[] { gen.argument("exc".toCharArray(), exceptionType) }; //$NON-NLS-1$ result.catchBlocks = new Block[] { gen.block(new Statement[] { catchStatement }) }; return result; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectReader.java
License:Open Source License
private MethodBinding getMethodRef(int index) { int start = getConstantPoolStartPosition(index); assert (u1At(start) == MethodRefTag); int class_index = u2At(start + 1); int name_index = u2At(start + 3); ReferenceBinding class_rb = getClassBinding(class_index); // deactivated, see below. ReferenceBinding actualReceiver = class_rb; 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); // Note: donot revert to actual receiver, because the linkage of // copyInheritanceSrc will otherwise be broken! if (mb == null && CharOperation.endsWith(name, IOTConstants._OT_TAG)) { // This method is faked within the compiler, will be added by the OTRE. return new MethodBinding(ClassFileConstants.AccPublic, name, TypeBinding.SHORT, Binding.NO_PARAMETERS, Binding.NO_EXCEPTIONS, class_rb); }/*from w w w . j a va 2 s . c o m*/ assert (mb != null); return mb; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectReader.java
License:Open Source License
/** Stolen mainly from BinaryTypeBinding.createMethod. */ private MethodBinding createMethodFromSignature(ReferenceBinding declaringClass, int methodModifiers, char[] methodSelector, char[] methodSignature) { int numOfParams = 0; char nextChar; int index = 0; // first character is always '(' so skip it while ((nextChar = methodSignature[++index]) != ')') { if (nextChar != '[') { numOfParams++;/* www .j a va2s . c o m*/ if (nextChar == 'L') while ((nextChar = methodSignature[++index]) != ';') { /*empty*/} } } // Ignore synthetic argument for member types. int startIndex = 0; TypeBinding[] parameters = Binding.NO_PARAMETERS; int size = numOfParams - startIndex; if (size > 0) { parameters = new TypeBinding[size]; index = 1; int end = 0; // first character is always '(' so skip it for (int i = 0; i < numOfParams; i++) { while ((nextChar = methodSignature[++end]) == '[') { /*empty*/} if (nextChar == 'L') while ((nextChar = methodSignature[++end]) != ';') { /*empty*/} if (i >= startIndex) // skip the synthetic arg if necessary parameters[i - startIndex] = this._environment.getTypeFromSignature(methodSignature, index, end, false/*GENERIC*/, this._srcModel.getBinding(), null, TypeAnnotationWalker.EMPTY_ANNOTATION_WALKER); // no missing type info available index = end + 1; } } return new MethodBinding(methodModifiers, methodSelector, this._environment.getTypeFromSignature(methodSignature, index + 1, -1, false/*GENERIC*/, this._srcModel.getBinding(), // index is currently pointing at the ')' null, TypeAnnotationWalker.EMPTY_ANNOTATION_WALKER), parameters, Binding.NO_EXCEPTIONS, declaringClass); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementorDyn.java
License:Open Source License
public static MethodBinding ensureAccessor(Scope scope, ReferenceBinding baseType, boolean isStatic) { if (baseType.isRoleType()) baseType = baseType.getRealClass(); char[] selector = isStatic ? OT_ACCESS_STATIC : OT_ACCESS; MethodBinding[] methods = baseType.getMethods(selector); if (methods != null && methods.length == 1) { return methods[0]; } else {/* ww w . j a v a2s . co m*/ int modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccSynthetic; if (isStatic) modifiers |= ClassFileConstants.AccStatic; MethodBinding method = new MethodBinding(modifiers, selector, scope.getJavaLangObject(), new TypeBinding[] { TypeBinding.INT, TypeBinding.INT, scope.environment().createArrayType(scope.getJavaLangObject(), 1), scope.getOrgObjectteamsITeam() }, Binding.NO_EXCEPTIONS, baseType); baseType.addMethod(method); return method; } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.FieldModel.java
License:Open Source License
/** Create a faked method binding for a getAccessor to a given base field. * @param isGetter select getter or setter */// ww w .j a v a 2s . c om public static MethodBinding getDecapsulatingFieldAccessor(Scope scope, ReferenceBinding baseType, FieldBinding resolvedField, boolean isGetter, ImplementationStrategy strategy) { FieldModel model = FieldModel.getModel(resolvedField); MethodBinding accessor = isGetter ? model._decapsulatingGetter : model._decapsulatingSetter; if (accessor != null) return accessor; if (strategy == ImplementationStrategy.DYN_ACCESS) { accessor = CalloutImplementorDyn.ensureAccessor(scope, baseType, resolvedField.isStatic()); } else { TypeBinding[] argTypes = resolvedField.isStatic() ? (isGetter ? new TypeBinding[0] : new TypeBinding[] { resolvedField.type }) : (isGetter ? new TypeBinding[] { baseType } : new TypeBinding[] { baseType, resolvedField.type }); accessor = new MethodBinding(ClassFileConstants.AccPublic | ClassFileConstants.AccStatic, CharOperation.concat(isGetter ? OT_GETFIELD : OT_SETFIELD, resolvedField.name), isGetter ? resolvedField.type : TypeBinding.VOID, argTypes, Binding.NO_EXCEPTIONS, baseType); baseType.addMethod(accessor); } MethodModel.getModel(accessor)._fakeKind = FakeKind.BASE_FIELD_ACCESSOR; if (isGetter) model._decapsulatingGetter = accessor; else model._decapsulatingSetter = accessor; return accessor; }