Example usage for org.eclipse.jdt.internal.compiler.lookup PackageBinding readableName

List of usage examples for org.eclipse.jdt.internal.compiler.lookup PackageBinding readableName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup PackageBinding readableName.

Prototype

@Override
    public char[] readableName()  

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java

License:Open Source License

private void selectFrom(Binding binding, CompilationUnitDeclaration parsedUnit, ICompilationUnit unit,
        boolean isDeclaration) {
    if (binding instanceof TypeVariableBinding) {
        TypeVariableBinding typeVariableBinding = (TypeVariableBinding) binding;
        Binding enclosingElement = typeVariableBinding.declaringElement;
        this.noProposal = false;

        if (enclosingElement instanceof SourceTypeBinding) {
            SourceTypeBinding enclosingType = (SourceTypeBinding) enclosingElement;
            if (isLocal(enclosingType) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalTypeParameter(typeVariableBinding);
            } else {
                this.requestor.acceptTypeParameter(enclosingType.qualifiedPackageName(),
                        enclosingType.qualifiedSourceName(), typeVariableBinding.sourceName(), false,
                        this.actualSelectionStart, this.actualSelectionEnd);
            }//from  w  ww  . j a  v a 2s  .  com
        } else if (enclosingElement instanceof MethodBinding) {
            MethodBinding enclosingMethod = (MethodBinding) enclosingElement;
            if (isLocal(enclosingMethod.declaringClass) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalMethodTypeParameter(typeVariableBinding);
            } else {
                this.requestor.acceptMethodTypeParameter(enclosingMethod.declaringClass.qualifiedPackageName(),
                        enclosingMethod.declaringClass.qualifiedSourceName(),
                        enclosingMethod.isConstructor() ? enclosingMethod.declaringClass.sourceName()
                                : enclosingMethod.selector,
                        enclosingMethod.sourceStart(), enclosingMethod.sourceEnd(),
                        typeVariableBinding.sourceName(), false, this.actualSelectionStart,
                        this.actualSelectionEnd);
            }
        }
        this.acceptedAnswer = true;
    } else if (binding instanceof ReferenceBinding) {
        ReferenceBinding typeBinding = (ReferenceBinding) binding;
        if (typeBinding instanceof ProblemReferenceBinding) {
            TypeBinding closestMatch = typeBinding.closestMatch();
            if (closestMatch instanceof ReferenceBinding) {
                typeBinding = (ReferenceBinding) closestMatch;
            } else {
                typeBinding = null;
            }
        }
        if (typeBinding == null)
            return;
        if (isLocal(typeBinding) && this.requestor instanceof SelectionRequestor) {
            this.noProposal = false;
            ((SelectionRequestor) this.requestor).acceptLocalType(typeBinding);
        } else {
            this.noProposal = false;

            this.requestor.acceptType(typeBinding.qualifiedPackageName(), typeBinding.qualifiedSourceName(),
                    typeBinding.modifiers, false, typeBinding.computeUniqueKey(), this.actualSelectionStart,
                    this.actualSelectionEnd);
        }
        this.acceptedAnswer = true;
    } else if (binding instanceof MethodBinding) {
        MethodBinding methodBinding = getCorrectMethodBinding((MethodBinding) binding);
        this.noProposal = false;

        boolean isValuesOrValueOf = false;
        if (binding instanceof SyntheticMethodBinding) {
            SyntheticMethodBinding syntheticMethodBinding = (SyntheticMethodBinding) binding;
            if (syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValues
                    || syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValueOf) {
                isValuesOrValueOf = true;
            }
        }

        if (!isValuesOrValueOf && !methodBinding.isSynthetic()) {
            TypeBinding[] parameterTypes = methodBinding.original().parameters;
            int length = parameterTypes.length;
            char[][] parameterPackageNames = new char[length][];
            char[][] parameterTypeNames = new char[length][];
            String[] parameterSignatures = new String[length];
            for (int i = 0; i < length; i++) {
                parameterPackageNames[i] = parameterTypes[i].qualifiedPackageName();
                parameterTypeNames[i] = parameterTypes[i].qualifiedSourceName();
                parameterSignatures[i] = new String(getSignature(parameterTypes[i])).replace('/', '.');
            }

            TypeVariableBinding[] typeVariables = methodBinding.original().typeVariables;
            length = typeVariables == null ? 0 : typeVariables.length;
            char[][] typeParameterNames = new char[length][];
            char[][][] typeParameterBoundNames = new char[length][][];
            for (int i = 0; i < length; i++) {
                TypeVariableBinding typeVariable = typeVariables[i];
                typeParameterNames[i] = typeVariable.sourceName;
                if (typeVariable.firstBound == null) {
                    typeParameterBoundNames[i] = new char[0][];
                } else if (TypeBinding.equalsEquals(typeVariable.firstBound, typeVariable.superclass)) {
                    int boundCount = 1
                            + (typeVariable.superInterfaces == null ? 0 : typeVariable.superInterfaces.length);
                    typeParameterBoundNames[i] = new char[boundCount][];
                    typeParameterBoundNames[i][0] = typeVariable.superclass.sourceName;
                    for (int j = 1; j < boundCount; j++) {
                        typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j - 1].sourceName;
                    }
                } else {
                    int boundCount = typeVariable.superInterfaces == null ? 0
                            : typeVariable.superInterfaces.length;
                    typeParameterBoundNames[i] = new char[boundCount][];
                    for (int j = 0; j < boundCount; j++) {
                        typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j].sourceName;
                    }
                }
            }

            ReferenceBinding declaringClass = methodBinding.declaringClass;
            if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalMethod(methodBinding);
            } else {
                this.requestor.acceptMethod(declaringClass.qualifiedPackageName(),
                        declaringClass.qualifiedSourceName(),
                        declaringClass.enclosingType() == null ? null
                                : new String(getSignature(declaringClass.enclosingType())),
                        methodBinding.isConstructor() ? declaringClass.sourceName() : methodBinding.selector,
                        parameterPackageNames, parameterTypeNames, parameterSignatures, typeParameterNames,
                        typeParameterBoundNames, methodBinding.isConstructor(), isDeclaration,
                        methodBinding.computeUniqueKey(), this.actualSelectionStart, this.actualSelectionEnd);
            }
        }
        this.acceptedAnswer = true;
    } else if (binding instanceof FieldBinding) {
        FieldBinding fieldBinding = (FieldBinding) binding;
        ReferenceBinding declaringClass = fieldBinding.declaringClass;
        if (declaringClass != null) { // arraylength
            this.noProposal = false;
            if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalField(fieldBinding);
            } else {
                // if the binding is a problem field binding, we want to make sure
                // we can retrieve the closestMatch if the problem reason is NotVisible
                FieldBinding currentFieldBinding = fieldBinding;
                while (currentFieldBinding instanceof ProblemFieldBinding) {
                    ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) currentFieldBinding;
                    if (problemFieldBinding.problemId() == ProblemReasons.NotVisible) {
                        currentFieldBinding = problemFieldBinding.closestMatch;
                    } else {
                        currentFieldBinding = null;
                    }
                }
                char[] fieldName = null;
                char[] key = null;
                if (currentFieldBinding != null) {
                    fieldName = currentFieldBinding.name;
                    key = currentFieldBinding.computeUniqueKey();
                } else {
                    fieldName = fieldBinding.name;
                    key = fieldBinding.computeUniqueKey();
                }
                this.requestor.acceptField(declaringClass.qualifiedPackageName(),
                        declaringClass.qualifiedSourceName(), fieldName, false, key, this.actualSelectionStart,
                        this.actualSelectionEnd);
            }
            this.acceptedAnswer = true;
        }
    } else if (binding instanceof LocalVariableBinding) {
        if (this.requestor instanceof SelectionRequestor) {
            ((SelectionRequestor) this.requestor).acceptLocalVariable((LocalVariableBinding) binding, unit);
            this.acceptedAnswer = true;
        } else {
            // open on the type of the variable
            selectFrom(((LocalVariableBinding) binding).type, parsedUnit, false);
        }
    } else if (binding instanceof ArrayBinding) {
        selectFrom(((ArrayBinding) binding).leafComponentType, parsedUnit, false);
        // open on the type of the array
    } else if (binding instanceof PackageBinding) {
        PackageBinding packageBinding = (PackageBinding) binding;
        this.noProposal = false;
        this.requestor.acceptPackage(packageBinding.readableName());
        this.acceptedAnswer = true;
    } else if (binding instanceof BaseTypeBinding) {
        this.acceptedAnswer = true;
    }
}

From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTPackage.java

License:Open Source License

public JDTPackage(PackageBinding pkg) {
    name = pkg == null ? "java.lang" : new String(pkg.readableName());
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.smap.AbstractSmapGenerator.java

License:Open Source License

protected String getPackagePathFromRefBinding(ReferenceBinding toplevelBinding) {
    PackageBinding pkgBinding = null;
    if (toplevelBinding.enclosingType() != null)
        pkgBinding = toplevelBinding.enclosingType().teamPackage;
    if (pkgBinding == null)
        pkgBinding = toplevelBinding.getPackage();
    String pkgName = String.valueOf(pkgBinding.readableName());
    pkgName = pkgName.replace('.', ISMAPConstants.OTJ_PATH_DELIMITER_CHAR);

    if (pkgName != null && pkgName.length() > 0)
        return pkgName + ISMAPConstants.OTJ_PATH_DELIMITER;

    return DEFAULT_PACKAGE;
}