List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding typeVariables
TypeVariableBinding[] typeVariables
To view the source code for org.eclipse.jdt.internal.compiler.lookup MethodBinding typeVariables.
Click Source Link
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTMethod.java
License:Open Source License
@Override public List<TypeParameterMirror> getTypeParameters() { if (typeParameters == null) { doWithBindings(new ActionOnMethodBinding() { @Override//from w w w. ja v a 2s . c o m public void doWithBinding(IType declaringClassModel, ReferenceBinding declaringClassBinding, MethodBinding methodBinding) { TypeVariableBinding[] jdtTypeParameters = methodBinding.typeVariables(); typeParameters = new ArrayList<TypeParameterMirror>(jdtTypeParameters.length); for (TypeVariableBinding jdtTypeParameter : jdtTypeParameters) typeParameters.add(new JDTTypeParameter(jdtTypeParameter)); } }); } return typeParameters; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode.java
License:Open Source License
/** * Convert a JDT MethodBinding to a Groovy MethodNode *//* w w w.j av a 2 s . c om*/ private MethodNode methodBindingToMethodNode(MethodBinding methodBinding) { String name = new String(methodBinding.selector); TypeVariableBinding[] typeVariables = methodBinding.typeVariables(); GenericsType[] generics = createGenericsTypeInfoForTypeVariableBindings(typeVariables); MethodNode mNode = null; try { resolver.pushMemberGenerics(generics); // FIXASC What value is there in getting the parameter names correct? (for methods and ctors) // If they need to be correct we need to retrieve the method decl from the binding scope int modifiers = methodBinding.modifiers; if (jdtBinding.isInterface()) { modifiers |= Modifier.ABSTRACT; } ClassNode returnType = resolver.convertToClassNode(methodBinding.returnType); Parameter[] gParameters = convertJdtParametersToGroovyParameters(methodBinding.parameters); ClassNode[] thrownExceptions = new ClassNode[0]; // FIXASC use constant of size 0 if (methodBinding.thrownExceptions != null) { thrownExceptions = new ClassNode[methodBinding.thrownExceptions.length]; for (int i = 0; i < methodBinding.thrownExceptions.length; i++) { thrownExceptions[i] = resolver.convertToClassNode(methodBinding.thrownExceptions[i]); } } mNode = new JDTMethodNode(methodBinding, resolver, name, modifiers, returnType, gParameters, thrownExceptions, null); // FIXASC (M3) likely to need something like this... // if (jdtBinding.isEnum()) { // if (methodBinding.getDefaultValue() != null) { // mNode.setAnnotationDefault(true); // } // } } finally { resolver.popMemberGenerics(); } mNode.setGenericsTypes(generics); return mNode; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode.java
License:Open Source License
private ConstructorNode constructorBindingToConstructorNode(MethodBinding methodBinding) { TypeVariableBinding[] typeVariables = methodBinding.typeVariables(); GenericsType[] generics = createGenericsTypeInfoForTypeVariableBindings(typeVariables); ConstructorNode ctorNode = null;/*from ww w. j a va 2 s . co m*/ try { resolver.pushMemberGenerics(generics); int modifiers = methodBinding.modifiers; Parameter[] parameters = convertJdtParametersToGroovyParameters(methodBinding.parameters); ClassNode[] thrownExceptions = new ClassNode[0]; if (methodBinding.thrownExceptions != null) { thrownExceptions = new ClassNode[methodBinding.thrownExceptions.length]; for (int i = 0; i < methodBinding.thrownExceptions.length; i++) { thrownExceptions[i] = resolver.convertToClassNode(methodBinding.thrownExceptions[i]); } } ctorNode = new ConstructorNode(modifiers, parameters, thrownExceptions, null); } finally { resolver.popMemberGenerics(); } ctorNode.setGenericsTypes(generics); return ctorNode; }
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 www .j av a 2 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.util.AstConverter.java
License:Open Source License
public static AbstractMethodDeclaration createMethod(MethodBinding methodBinding, ReferenceBinding site, CompilationResult compilationResult, DecapsulationState decapsulation, AstGenerator gen) { if (methodBinding == null) return null; AbstractMethodDeclaration abstractMethodDeclaration; if (CharOperation.equals(methodBinding.selector, TypeConstants.INIT)) { ConstructorDeclaration constructorDeclaration = new ConstructorDeclaration(compilationResult); constructorDeclaration.selector = site != null ? site.sourceName : methodBinding.declaringClass.sourceName; abstractMethodDeclaration = constructorDeclaration; } else {/*from w w w . j a va2 s .c o m*/ MethodDeclaration methodDeclaration = new MethodDeclaration(compilationResult); // on these special methods see class header comment in CopyInheritance: if (CharOperation.prefixEquals(IOTConstants.CAST_PREFIX, methodBinding.selector) || CharOperation.prefixEquals(IOTConstants._OT_LIFT_TO, methodBinding.selector)) methodDeclaration.returnType = new SingleTypeReference(methodBinding.returnType.internalName(), 0); else methodDeclaration.returnType = gen.typeReference(methodBinding.returnType); methodDeclaration.returnType.setBaseclassDecapsulation(decapsulation); methodDeclaration.selector = methodBinding.selector; TypeVariableBinding[] typeVariables = methodBinding.typeVariables(); if (typeVariables != Binding.NO_TYPE_VARIABLES) { TypeParameter[] parameters = new TypeParameter[typeVariables.length]; for (int i = 0; i < typeVariables.length; i++) parameters[i] = gen.typeParameter(typeVariables[i]); methodDeclaration.typeParameters = parameters; } abstractMethodDeclaration = methodDeclaration; } gen.setMethodPositions(abstractMethodDeclaration); abstractMethodDeclaration.modifiers = methodBinding.modifiers & ~ClassFileConstants.AccSynthetic; if (methodBinding.isAbstract()) // AccSemicolonBody - flag does not exist in binary methods: abstractMethodDeclaration.modifiers |= AccSemicolonBody; abstractMethodDeclaration.arguments = createArguments(methodBinding.parameters, site, decapsulation, gen); abstractMethodDeclaration.isCopied = true; abstractMethodDeclaration.sourceMethodBinding = methodBinding; abstractMethodDeclaration.thrownExceptions = AstClone.copyExceptions(methodBinding, gen); return abstractMethodDeclaration; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstConverter.java
License:Open Source License
/** * Create the declaration of a role method to be inserted into the role interface. * @param teamDecl/*from w w w .j a va2 s . co m*/ * @param classpartMethod * @return the method AST */ public static MethodDeclaration genIfcMethodFromBinding(TypeDeclaration teamDecl, MethodBinding classpartMethod, AstGenerator gen) { MethodDeclaration newmethod = new MethodDeclaration(teamDecl.compilationResult); newmethod.selector = classpartMethod.selector; newmethod.modifiers = computeIfcpartModifiers(classpartMethod.modifiers); // special case of copying cast method for non-public role: if (CharOperation.prefixEquals(IOTConstants.CAST_PREFIX, classpartMethod.selector) && !((ReferenceBinding) classpartMethod.returnType).isPublic()) { newmethod.modifiers = AccProtected | AstGenerator.AccIfcMethod; // see StandardElementGenerator.getCastMethod(); } newmethod.isGenerated = true; // don't try to parse it etc.. // no position, created from binding, so use pre-set default location gen.setMethodPositions(newmethod); newmethod.arguments = AstConverter.createArgumentsFromParameters(classpartMethod.parameters, gen); newmethod.returnType = gen.typeReference(classpartMethod.returnType); if (classpartMethod.typeVariables() != Binding.NO_TYPE_VARIABLES) { TypeVariableBinding[] typeVarBindings = classpartMethod.typeVariables; newmethod.typeParameters = new TypeParameter[typeVarBindings.length]; for (int i = 0; i < typeVarBindings.length; i++) { newmethod.typeParameters[i] = gen.typeParameter(typeVarBindings[i]); } } newmethod.thrownExceptions = AstClone.copyExceptions(classpartMethod, gen); return newmethod; }