org.eclipse.jdt.core.BindingKey Java Examples
The following examples show how to use
org.eclipse.jdt.core.BindingKey.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private IMethod findJavaMethod(IType type) { // Locate the method from its signature. // String[] parameterTypes = Signature.getParameterTypes(new BindingKey("Lx;.x(" + signature + ")").toSignature()); IMethod javaMethod = type.getMethod(name, parameterTypes); // If the method doesn't exist and this is a nested type... // if (!javaMethod.exists() && type.getDeclaringType() != null) { // This special case handles what appears to be a JDT bug // that sometimes it knows when there are implicit constructor arguments for nested types and sometimes it doesn't. // Infer one more initial parameter type and locate the method based on that. // String[] augmented = new String[parameterTypes.length + 1]; System.arraycopy(parameterTypes, 0, augmented, 1, parameterTypes.length); String first = Signature.createTypeSignature(type.getDeclaringType().getFullyQualifiedName(), true); augmented[0] = first; javaMethod = type.getMethod(name, augmented); } return javaMethod; }
Example #2
Source File: NamedMember.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected String getFullyQualifiedParameterizedName(String fullyQualifiedName, String uniqueKey) throws JavaModelException { String[] typeArguments = new BindingKey(uniqueKey).getTypeArguments(); int length = typeArguments.length; if (length == 0) return fullyQualifiedName; StringBuffer buffer = new StringBuffer(); buffer.append(fullyQualifiedName); buffer.append('<'); for (int i = 0; i < length; i++) { String typeArgument = typeArguments[i]; buffer.append(Signature.toString(typeArgument)); if (i < length-1) buffer.append(','); } buffer.append('>'); return buffer.toString(); }
Example #3
Source File: JavaElementLabelComposer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Appends the style label for a field. Considers the F_* flags. * * @param field the element to render * @param flags the rendering flags. Flags with names starting with 'F_' are considered. */ public void appendFieldLabel(IField field, long flags) { try { if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) { if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) { appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags); } else { appendTypeSignatureLabel(field, field.getTypeSignature(), flags); } fBuilder.append(' '); } // qualification if (getFlag(flags, JavaElementLabels.F_FULLY_QUALIFIED)) { appendTypeLabel(field.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); fBuilder.append('.'); } fBuilder.append(getElementName(field)); if (getFlag(flags, JavaElementLabels.F_APP_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) { fBuilder.append(JavaElementLabels.DECL_STRING); if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) { appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags); } else { appendTypeSignatureLabel(field, field.getTypeSignature(), flags); } } // post qualification if (getFlag(flags, JavaElementLabels.F_POST_QUALIFIED)) { fBuilder.append(JavaElementLabels.CONCAT_STRING); appendTypeLabel(field.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("", e); // NotExistsException will not reach this point } }
Example #4
Source File: TypeEnvironment.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public ArrayType createArrayType(TType elementType, int dimensions) { Assert.isTrue(! elementType.isArrayType()); Assert.isTrue(! elementType.isAnonymous()); Assert.isTrue(dimensions > 0); int index= dimensions - 1; Map<TType, ArrayType> arrayTypes= getArrayTypesMap(index); ArrayType result= arrayTypes.get(elementType); if (result != null) return result; result= new ArrayType(this, BindingKey.createArrayTypeBindingKey(elementType.getBindingKey(), dimensions)); arrayTypes.put(elementType, result); result.initialize(elementType, dimensions); return result; }
Example #5
Source File: JdtParser.java From j2cl with Apache License 2.0 | 4 votes |
/** Returns a map from file paths to compilation units after JDT parsing. */ public CompilationUnitsAndTypeBindings parseFiles( List<FileInfo> filePaths, boolean useTargetPath) { // Parse and create a compilation unit for every file. ASTParser parser = newASTParser(true); // The map must be ordered because it will be iterated over later and if it was not ordered then // our output would be unstable final Map<String, CompilationUnit> compilationUnitsByFilePath = new LinkedHashMap<>(); final List<ITypeBinding> wellKnownTypeBindings = new ArrayList<>(); final Map<String, String> targetPathBySourcePath = filePaths.stream().collect(Collectors.toMap(FileInfo::sourcePath, FileInfo::targetPath)); FileASTRequestor astRequestor = new FileASTRequestor() { @Override public void acceptAST(String filePath, CompilationUnit compilationUnit) { if (compilationHasErrors(filePath, compilationUnit)) { return; } String filePathKey = filePath; if (useTargetPath) { filePathKey = targetPathBySourcePath.get(filePath); } compilationUnitsByFilePath.put(filePathKey, compilationUnit); } @Override public void acceptBinding(String bindingKey, IBinding binding) { wellKnownTypeBindings.add((ITypeBinding) binding); } }; parser.createASTs( filePaths.stream().map(f -> f.sourcePath()).toArray(String[]::new), getEncodings(filePaths.size()), FrontendConstants.WELL_KNOWN_CLASS_NAMES.stream() .map(BindingKey::createTypeBindingKey) .toArray(String[]::new), astRequestor, null); return new CompilationUnitsAndTypeBindings(compilationUnitsByFilePath, wellKnownTypeBindings); }
Example #6
Source File: ParameterGuesser.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public Variable createVariable(IJavaElement element, IType enclosingType, String expectedType, int positionScore) throws JavaModelException { int variableType; int elementType= element.getElementType(); String elementName= element.getElementName(); String typeSignature; switch (elementType) { case IJavaElement.FIELD: { IField field= (IField) element; if (field.getDeclaringType().equals(enclosingType)) { variableType= Variable.FIELD; } else { variableType= Variable.INHERITED_FIELD; } if (field.isResolved()) { typeSignature= new BindingKey(field.getKey()).toSignature(); } else { typeSignature= field.getTypeSignature(); } break; } case IJavaElement.LOCAL_VARIABLE: { ILocalVariable locVar= (ILocalVariable) element; variableType= Variable.LOCAL; typeSignature= locVar.getTypeSignature(); break; } case IJavaElement.METHOD: { IMethod method= (IMethod) element; if (isMethodToSuggest(method)) { if (method.getDeclaringType().equals(enclosingType)) { variableType= Variable.METHOD; } else { variableType= Variable.INHERITED_METHOD; } if (method.isResolved()) { typeSignature= Signature.getReturnType(new BindingKey(method.getKey()).toSignature()); } else { typeSignature= method.getReturnType(); } elementName= elementName + "()"; //$NON-NLS-1$ } else { return null; } break; } default: return null; } String type= Signature.toString(typeSignature); boolean isAutoboxMatch= isPrimitiveType(expectedType) != isPrimitiveType(type); return new Variable(type, elementName, variableType, isAutoboxMatch, positionScore); }
Example #7
Source File: ParameterGuesser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public Variable createVariable(IJavaElement element, IType enclosingType, String expectedType, int positionScore) throws JavaModelException { int variableType; int elementType= element.getElementType(); String elementName= element.getElementName(); String typeSignature; switch (elementType) { case IJavaElement.FIELD: { IField field= (IField) element; if (field.getDeclaringType().equals(enclosingType)) { variableType= Variable.FIELD; } else { variableType= Variable.INHERITED_FIELD; } if (field.isResolved()) { typeSignature= new BindingKey(field.getKey()).toSignature(); } else { typeSignature= field.getTypeSignature(); } break; } case IJavaElement.LOCAL_VARIABLE: { ILocalVariable locVar= (ILocalVariable) element; variableType= Variable.LOCAL; typeSignature= locVar.getTypeSignature(); break; } case IJavaElement.METHOD: { IMethod method= (IMethod) element; if (isMethodToSuggest(method)) { if (method.getDeclaringType().equals(enclosingType)) { variableType= Variable.METHOD; } else { variableType= Variable.INHERITED_METHOD; } if (method.isResolved()) { typeSignature= Signature.getReturnType(new BindingKey(method.getKey()).toSignature()); } else { typeSignature= method.getReturnType(); } elementName= elementName + "()"; //$NON-NLS-1$ } else { return null; } break; } default: return null; } String type= Signature.toString(typeSignature); boolean isAutoboxMatch= isPrimitiveType(expectedType) != isPrimitiveType(type); return new Variable(type, elementName, variableType, isAutoboxMatch, positionScore, NO_TRIGGERS, getImageDescriptor(element)); }
Example #8
Source File: ConstructorPattern.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public ConstructorPattern( char[] declaringSimpleName, char[] declaringQualification, char[][] parameterQualifications, char[][] parameterSimpleNames, String[] parameterSignatures, IMethod method, int limitTo, int matchRule) { this(declaringSimpleName, declaringQualification, parameterQualifications, parameterSimpleNames, limitTo, matchRule); // Set flags try { this.varargs = (method.getFlags() & Flags.AccVarargs) != 0; } catch (JavaModelException e) { // do nothing } // Get unique key for parameterized constructors String genericDeclaringTypeSignature = null; if (method.isResolved()) { String key = method.getKey(); BindingKey bindingKey = new BindingKey(key); if (bindingKey.isParameterizedType()) { genericDeclaringTypeSignature = Util.getDeclaringTypeSignature(key); // Store type signature and arguments for declaring type if (genericDeclaringTypeSignature != null) { this.typeSignatures = Util.splitTypeLevelsSignature(genericDeclaringTypeSignature); setTypeArguments(Util.getAllTypeArguments(this.typeSignatures)); } } } else { this.constructorParameters = true; storeTypeSignaturesAndArguments(method.getDeclaringType()); } // store type signatures and arguments for method parameters type if (parameterSignatures != null) { int length = parameterSignatures.length; if (length > 0) { this.parametersTypeSignatures = new char[length][][]; this.parametersTypeArguments = new char[length][][][]; for (int i=0; i<length; i++) { this.parametersTypeSignatures[i] = Util.splitTypeLevelsSignature(parameterSignatures[i]); this.parametersTypeArguments[i] = Util.getAllTypeArguments(this.parametersTypeSignatures[i]); } } } // Store type signatures and arguments for method this.constructorArguments = extractMethodArguments(method); if (hasConstructorArguments()) this.mustResolve = true; }
Example #9
Source File: SuperTypeRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 2 votes |
/** * Returns a new ast node corresponding to the given type. * * @param rewrite the compilation unit rewrite to use * @param type the new type * @param node the old node * @return A corresponding ast node */ protected static ASTNode createCorrespondingNode(final CompilationUnitRewrite rewrite, final TType type, ASTNode node) { ImportRewrite importRewrite= rewrite.getImportRewrite(); ImportRewriteContext context = new ContextSensitiveImportRewriteContext(node, importRewrite); return importRewrite.addImportFromSignature(new BindingKey(type.getBindingKey()).toSignature(), rewrite.getAST(), context); }