List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding qualifiedSourceName
@Override public char[] qualifiedSourceName()
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. ja va 2 s . c o m*/ } 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.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected IType lookupType(ReferenceBinding typeBinding) { if (typeBinding == null || !typeBinding.isValidBinding()) return null; char[] packageName = typeBinding.qualifiedPackageName(); IPackageFragment[] pkgs = this.nameLookup.findPackageFragments( (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME : new String(packageName), false);//w w w . j a v a 2 s . c o m // iterate type lookup in each package fragment char[] sourceName = typeBinding.qualifiedSourceName(); String typeName = new String(sourceName); int acceptFlag = 0; if (typeBinding.isAnnotationType()) { acceptFlag = NameLookup.ACCEPT_ANNOTATIONS; } else if (typeBinding.isEnum()) { acceptFlag = NameLookup.ACCEPT_ENUMS; } else if (typeBinding.isInterface()) { acceptFlag = NameLookup.ACCEPT_INTERFACES; } else if (typeBinding.isClass()) { acceptFlag = NameLookup.ACCEPT_CLASSES; } if (pkgs != null) { for (int i = 0, length = pkgs.length; i < length; i++) { IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag, true/*consider secondary types*/); if (type != null) return type; } } // search inside enclosing element char[][] qualifiedName = CharOperation.splitOn('.', sourceName); int length = qualifiedName.length; if (length == 0) return null; IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type if (type == null) return null; for (int i = 1; i < length; i++) { type = type.getType(new String(qualifiedName[i])); if (type == null) return null; } if (type.exists()) return type; return null; }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTMethod.java
License:Open Source License
public boolean isOverloadingMethod() { if (isOverloading == null) { isOverloading = Boolean.FALSE; doWithBindings(new ActionOnMethodBinding() { @Override// w w w.ja v a 2 s. c o m public void doWithBinding(IType declaringClassModel, ReferenceBinding declaringClass, MethodBinding method) { // Exception has a pretend supertype of Object, unlike its Java supertype of java.lang.RuntimeException // so we stop there for it, especially since it does not have any overloading if (CharOperation.equals(declaringClass.qualifiedSourceName(), "ceylon.language.Exception".toCharArray())) { isOverloading = false; return; } // try the superclass first if (isOverloadingInSuperClasses(declaringClass, method)) { isOverloading = Boolean.TRUE; } if (isOverloadingInSuperInterfaces(declaringClass, method)) { isOverloading = Boolean.TRUE; } } }); } return isOverloading.booleanValue(); }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTMethod.java
License:Open Source License
boolean isOverloadingInSuperClasses(ReferenceBinding declaringClass, MethodBinding method) { ReferenceBinding superClass = declaringClass.superclass(); if (superClass == null) { return false; }/* ww w . j a va 2s.c o m*/ // Exception has a pretend supertype of Object, unlike its Java supertype of java.lang.RuntimeException // so we stop there for it, especially since it does not have any overloading if (CharOperation.equals(superClass.qualifiedSourceName(), "ceylon.language.Exception".toCharArray())) return false; superClass = JDTUtils.inferTypeParametersFromSuperClass(declaringClass, superClass); if (isOverloadingInType(superClass, method)) { return true; } return isOverloadingInSuperClasses(superClass, method); }
From source file:org.eclipse.che.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected IType lookupType(ReferenceBinding typeBinding) { if (typeBinding == null || !typeBinding.isValidBinding()) return null; char[] packageName = typeBinding.qualifiedPackageName(); IPackageFragment[] pkgs = this.nameLookup.findPackageFragments( (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME : new String(packageName), false);/*from w ww.j a v a2 s .c om*/ // iterate type lookup in each package fragment char[] sourceName = typeBinding.qualifiedSourceName(); String typeName = new String(sourceName); int acceptFlag = 0; if (typeBinding.isAnnotationType()) { acceptFlag = NameLookup.ACCEPT_ANNOTATIONS; } else if (typeBinding.isEnum()) { acceptFlag = NameLookup.ACCEPT_ENUMS; } else if (typeBinding.isInterface()) { acceptFlag = NameLookup.ACCEPT_INTERFACES; } else if (typeBinding.isClass()) { acceptFlag = NameLookup.ACCEPT_CLASSES; } if (pkgs != null) { for (int i = 0, length = pkgs.length; i < length; i++) { IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag, false, true/*consider secondary types*/); if (type != null) return type; } } // search inside enclosing element char[][] qualifiedName = CharOperation.splitOn('.', sourceName); int length = qualifiedName.length; if (length == 0) return null; IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type if (type == null) return null; for (int i = 1; i < length; i++) { type = type.getType(new String(qualifiedName[i])); if (type == null) return null; } if (type.exists()) return type; return null; }
From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected IType lookupType(ReferenceBinding typeBinding) { if (typeBinding == null) return null; char[] packageName = typeBinding.qualifiedPackageName(); IPackageFragment[] pkgs = this.nameLookup.findPackageFragments( (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME : new String(packageName), false);// ww w . ja v a 2 s. co m // iterate type lookup in each package fragment char[] sourceName = typeBinding.qualifiedSourceName(); String typeName = new String(sourceName); int acceptFlag = 0; if (typeBinding.isAnnotationType()) { acceptFlag = NameLookup.ACCEPT_ANNOTATIONS; } else if (typeBinding.isEnum()) { acceptFlag = NameLookup.ACCEPT_ENUMS; } else if (typeBinding.isInterface()) { acceptFlag = NameLookup.ACCEPT_INTERFACES; } else if (typeBinding.isClass()) { acceptFlag = NameLookup.ACCEPT_CLASSES; } if (pkgs != null) { for (int i = 0, length = pkgs.length; i < length; i++) { IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag, true/*consider secondary types*/); if (type != null) return type; } } // search inside enclosing element char[][] qualifiedName = CharOperation.splitOn('.', sourceName); int length = qualifiedName.length; if (length == 0) return null; IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type if (type == null) return null; for (int i = 1; i < length; i++) { type = type.getType(new String(qualifiedName[i])); if (type == null) return null; } if (type.exists()) return type; return null; }
From source file:spoon.support.compiler.jdt.ContextBuilder.java
License:Open Source License
/** * Returns qualified name with appropriate package separator and inner type separator *///from w w w .j a va 2 s . c om private static String getNormalQualifiedName(ReferenceBinding referenceBinding) { String pkg = new String(referenceBinding.getPackage().readableName()).replaceAll("\\.", "\\" + CtPackage.PACKAGE_SEPARATOR); String name = new String(referenceBinding.qualifiedSourceName()).replaceAll("\\.", "\\" + CtType.INNERTTYPE_SEPARATOR); return pkg.equals("") ? name : pkg + "." + name; }