Search in sources :

Example 11 with TypeBinding

use of org.eclipse.jdt.internal.compiler.lookup.TypeBinding in project lombok by rzwitserloot.

the class ExtensionMethodCompletionProposal method setMethodBinding.

public void setMethodBinding(final MethodBinding method, final ASTNode node) {
    MethodBinding original = method.original();
    TypeBinding[] parameters = Arrays.copyOf(method.parameters, method.parameters.length);
    method.parameters = Arrays.copyOfRange(method.parameters, 1, method.parameters.length);
    TypeBinding[] originalParameters = null;
    if (original != method) {
        originalParameters = Arrays.copyOf(method.original().parameters, method.original().parameters.length);
        method.original().parameters = Arrays.copyOfRange(method.original().parameters, 1, method.original().parameters.length);
    }
    int length = method.parameters == null ? 0 : method.parameters.length;
    char[][] parameterPackageNames = new char[length][];
    char[][] parameterTypeNames = new char[length][];
    for (int i = 0; i < length; i++) {
        TypeBinding type = method.original().parameters[i];
        parameterPackageNames[i] = type.qualifiedPackageName();
        parameterTypeNames[i] = type.qualifiedSourceName();
    }
    char[] completion = CharOperation.concat(method.selector, new char[] { '(', ')' });
    setDeclarationSignature(CompletionEngine.getSignature(method.declaringClass));
    setSignature(CompletionEngine.getSignature(method));
    if (original != method) {
        setOriginalSignature(CompletionEngine.getSignature(original));
    }
    setDeclarationPackageName(method.declaringClass.qualifiedPackageName());
    setDeclarationTypeName(method.declaringClass.qualifiedSourceName());
    setParameterPackageNames(parameterPackageNames);
    setParameterTypeNames(parameterTypeNames);
    setPackageName(method.returnType.qualifiedPackageName());
    setTypeName(method.returnType.qualifiedSourceName());
    setName(method.selector);
    setCompletion(completion);
    setFlags(method.modifiers & (~AccStatic));
    int index = node.sourceEnd + 1;
    if (node instanceof CompletionOnQualifiedNameReference) {
        index -= ((CompletionOnQualifiedNameReference) node).completionIdentifier.length;
    }
    if (node instanceof CompletionOnMemberAccess) {
        index -= ((CompletionOnMemberAccess) node).token.length;
    }
    if (node instanceof CompletionOnSingleNameReference) {
        index -= ((CompletionOnSingleNameReference) node).token.length;
    }
    setReplaceRange(index, index);
    setTokenRange(index, index);
    setRelevance(100);
    method.parameters = parameters;
    if (original != method) {
        method.original().parameters = originalParameters;
    }
}
Also used : CompletionOnMemberAccess(org.eclipse.jdt.internal.codeassist.complete.CompletionOnMemberAccess) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) CompletionOnSingleNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference) CompletionOnQualifiedNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnQualifiedNameReference)

Example 12 with TypeBinding

use of org.eclipse.jdt.internal.compiler.lookup.TypeBinding in project lombok by rzwitserloot.

the class PatchDelegate method addAllMethodBindings0.

private static void addAllMethodBindings0(List<BindingTuple> list, TypeBinding binding, Set<String> banList, char[] fieldName, ASTNode responsible) throws DelegateRecursion {
    if (binding instanceof SourceTypeBinding) {
        ClassScope scope = ((SourceTypeBinding) binding).scope;
        if (scope != null)
            scope.environment().globalOptions.storeAnnotations = true;
    }
    if (binding == null)
        return;
    TypeBinding inner;
    if (binding instanceof ParameterizedTypeBinding) {
        inner = ((ParameterizedTypeBinding) binding).genericType();
    } else {
        inner = binding;
    }
    if (inner instanceof SourceTypeBinding) {
        ClassScope cs = ((SourceTypeBinding) inner).scope;
        if (cs != null) {
            try {
                Reflection.classScopeBuildFieldsAndMethodsMethod.invoke(cs);
            } catch (Exception e) {
            // See 'Reflection' class for why we ignore this exception.
            }
        }
    }
    if (!(binding instanceof ReferenceBinding)) {
        return;
    }
    ReferenceBinding rb = (ReferenceBinding) binding;
    MethodBinding[] availableMethods = rb.availableMethods();
    FieldBinding[] availableFields = rb.availableFields();
    failIfContainsAnnotation(binding, availableMethods);
    failIfContainsAnnotation(binding, availableFields);
    MethodBinding[] parameterizedSigs = availableMethods;
    MethodBinding[] baseSigs = parameterizedSigs;
    if (binding instanceof ParameterizedTypeBinding) {
        baseSigs = ((ParameterizedTypeBinding) binding).genericType().availableMethods();
        if (baseSigs.length != parameterizedSigs.length) {
            // The last known state of eclipse source says this can't happen, so we rely on it,
            // but if this invariant is broken, better to go with 'arg0' naming instead of crashing.
            baseSigs = parameterizedSigs;
        }
    }
    for (int i = 0; i < parameterizedSigs.length; i++) {
        MethodBinding mb = parameterizedSigs[i];
        String sig = printSig(mb);
        if (mb.isStatic())
            continue;
        if (mb.isBridge())
            continue;
        if (mb.isConstructor())
            continue;
        if (mb.isDefaultAbstract())
            continue;
        if (!mb.isPublic())
            continue;
        if (mb.isSynthetic())
            continue;
        // If add returns false, it was already in there.
        if (!banList.add(sig))
            continue;
        BindingTuple pair = new BindingTuple(mb, baseSigs[i], fieldName, responsible);
        list.add(pair);
    }
    addAllMethodBindings0(list, rb.superclass(), banList, fieldName, responsible);
    ReferenceBinding[] interfaces = rb.superInterfaces();
    if (interfaces != null) {
        for (ReferenceBinding iface : interfaces) addAllMethodBindings0(list, iface, banList, fieldName, responsible);
    }
}
Also used : ParameterizedTypeBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding) ParameterizedTypeBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding) BaseTypeBinding(org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding) UnresolvedReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) ClassScope(org.eclipse.jdt.internal.compiler.lookup.ClassScope) FieldBinding(org.eclipse.jdt.internal.compiler.lookup.FieldBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding)

Example 13 with TypeBinding

use of org.eclipse.jdt.internal.compiler.lookup.TypeBinding in project lombok by rzwitserloot.

the class PatchExtensionMethodCompletionProposal method getFirstParameterType.

static TypeBinding getFirstParameterType(TypeDeclaration decl, CompletionProposalCollector completionProposalCollector) {
    TypeBinding firstParameterType = null;
    ASTNode node = getAssistNode(completionProposalCollector);
    if (node == null)
        return null;
    if (!(node instanceof CompletionOnQualifiedNameReference) && !(node instanceof CompletionOnSingleNameReference) && !(node instanceof CompletionOnMemberAccess))
        return null;
    // Never offer on 'super.<autocomplete>'.
    if (node instanceof FieldReference && ((FieldReference) node).receiver instanceof SuperReference)
        return null;
    if (node instanceof NameReference) {
        Binding binding = ((NameReference) node).binding;
        /*			if ((node instanceof SingleNameReference) && (((SingleNameReference) node).token.length == 0)) {
				firstParameterType = decl.binding;
			} else */
        if (binding instanceof VariableBinding) {
            firstParameterType = ((VariableBinding) binding).type;
        }
    } else if (node instanceof FieldReference) {
        firstParameterType = ((FieldReference) node).actualReceiverType;
    }
    return firstParameterType;
}
Also used : Binding(org.eclipse.jdt.internal.compiler.lookup.Binding) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) VariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding) CompletionOnQualifiedNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnQualifiedNameReference) NameReference(org.eclipse.jdt.internal.compiler.ast.NameReference) CompletionOnSingleNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference) CompletionOnMemberAccess(org.eclipse.jdt.internal.codeassist.complete.CompletionOnMemberAccess) FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) ASTNode(org.eclipse.jdt.internal.compiler.ast.ASTNode) CompletionOnSingleNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference) CompletionOnQualifiedNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnQualifiedNameReference) VariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding) SuperReference(org.eclipse.jdt.internal.compiler.ast.SuperReference)

Aggregations

TypeBinding (org.eclipse.jdt.internal.compiler.lookup.TypeBinding)13 MethodBinding (org.eclipse.jdt.internal.compiler.lookup.MethodBinding)7 ReferenceBinding (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)7 ArrayList (java.util.ArrayList)5 ParameterizedTypeBinding (org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding)5 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)4 EclipseNode (lombok.eclipse.EclipseNode)3 QualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)3 SingleTypeReference (org.eclipse.jdt.internal.compiler.ast.SingleTypeReference)3 TypeDeclaration (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration)3 Binding (org.eclipse.jdt.internal.compiler.lookup.Binding)3 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 IMethod (org.eclipse.jdt.core.IMethod)2 IType (org.eclipse.jdt.core.IType)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 CompletionOnMemberAccess (org.eclipse.jdt.internal.codeassist.complete.CompletionOnMemberAccess)2 CompletionOnQualifiedNameReference (org.eclipse.jdt.internal.codeassist.complete.CompletionOnQualifiedNameReference)2 CompletionOnSingleNameReference (org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference)2 ASTNode (org.eclipse.jdt.internal.compiler.ast.ASTNode)2 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)2