Java Code Examples for org.eclipse.jdt.core.Signature#C_RESOLVED
The following examples show how to use
org.eclipse.jdt.core.Signature#C_RESOLVED .
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: Bindings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean sameParameter(ITypeBinding type, String candidate, IType scope) throws JavaModelException { if (type.getDimensions() != Signature.getArrayCount(candidate)) return false; // Normalizes types if (type.isArray()) type= type.getElementType(); candidate= Signature.getElementType(candidate); if ((Signature.getTypeSignatureKind(candidate) == Signature.BASE_TYPE_SIGNATURE) != type.isPrimitive()) { return false; } if (type.isPrimitive() || type.isTypeVariable()) { return type.getName().equals(Signature.toString(candidate)); } else { // normalize (quick hack until binding.getJavaElement works) candidate= Signature.getTypeErasure(candidate); type= type.getErasure(); if (candidate.charAt(Signature.getArrayCount(candidate)) == Signature.C_RESOLVED) { return Signature.toString(candidate).equals(Bindings.getFullyQualifiedName(type)); } else { String[][] qualifiedCandidates= scope.resolveType(Signature.toString(candidate)); if (qualifiedCandidates == null || qualifiedCandidates.length == 0) return false; String packageName= type.getPackage().isUnnamed() ? "" : type.getPackage().getName(); //$NON-NLS-1$ String typeName= getTypeQualifiedName(type); for (int i= 0; i < qualifiedCandidates.length; i++) { String[] qualifiedCandidate= qualifiedCandidates[i]; if ( qualifiedCandidate[0].equals(packageName) && qualifiedCandidate[1].equals(typeName)) return true; } } } return false; }
Example 2
Source File: SearchUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean isPrimitiveOrString(IField field) { String fieldType; try { fieldType= field.getTypeSignature(); } catch (JavaModelException ex) { return false; } char first= fieldType.charAt(0); return (first != Signature.C_RESOLVED && first != Signature.C_UNRESOLVED && first != Signature.C_ARRAY) || ((first == Signature.C_RESOLVED || first == Signature.C_UNRESOLVED) && fieldType.substring(1, fieldType.length() - 1).equals(String.class.getName()) || (first == Signature.C_UNRESOLVED && fieldType.substring(1, fieldType.length() - 1).equals("String"))); //$NON-NLS-1$ }
Example 3
Source File: Binding2JavaModel.java From lapse-plus with GNU General Public License v3.0 | 4 votes |
private static boolean isPrimitiveType(String s) { char c= s.charAt(0); return c != Signature.C_RESOLVED && c != Signature.C_UNRESOLVED; }
Example 4
Source File: Binding2JavaModel.java From lapse-plus with GNU General Public License v3.0 | 4 votes |
private static boolean isResolvedType(String s) { int arrayCount= Signature.getArrayCount(s); return s.charAt(arrayCount) == Signature.C_RESOLVED; }
Example 5
Source File: GenerateDelegateMethodsHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private static boolean hasPrimitiveType(IField field) throws JavaModelException { String signature = field.getTypeSignature(); char first = Signature.getElementType(signature).charAt(0); return (first != Signature.C_RESOLVED && first != Signature.C_UNRESOLVED); }
Example 6
Source File: AddDelegateMethodsAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean hasPrimitiveType(IField field) throws JavaModelException { String signature= field.getTypeSignature(); char first= Signature.getElementType(signature).charAt(0); return (first != Signature.C_RESOLVED && first != Signature.C_UNRESOLVED); }
Example 7
Source File: ImportRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Adds a new import to the rewriter's record and returns a {@link Type} node that can be used * in the code as a reference to the type. The type binding can be an array binding, type variable or wildcard. * If the binding is a generic type, the type parameters are ignored. For parameterized types, also the type * arguments are processed and imports added if necessary. Anonymous types inside type arguments are normalized to their base type, wildcard * of wildcards are ignored. * <p> * No imports are added for types that are already known. If a import for a type is recorded to be removed, this record is discarded instead. * </p> * <p> * The content of the compilation unit itself is actually not modified * in any way by this method; rather, the rewriter just records that a new import has been added. * </p> * @param typeSig the signature of the type to be added. * @param ast the AST to create the returned type for. * @param context an optional context that knows about types visible in the current scope or <code>null</code> * to use the default context only using the available imports. * @return a type node for the given type signature. Type names are simple names if an import could be used, * or else qualified names if an import conflict prevented an import. */ public Type addImportFromSignature(String typeSig, AST ast, ImportRewriteContext context) { if (typeSig == null || typeSig.length() == 0) { throw new IllegalArgumentException("Invalid type signature: empty or null"); //$NON-NLS-1$ } int sigKind= Signature.getTypeSignatureKind(typeSig); switch (sigKind) { case Signature.BASE_TYPE_SIGNATURE: return ast.newPrimitiveType(PrimitiveType.toCode(Signature.toString(typeSig))); case Signature.ARRAY_TYPE_SIGNATURE: Type elementType= addImportFromSignature(Signature.getElementType(typeSig), ast, context); return ast.newArrayType(elementType, Signature.getArrayCount(typeSig)); case Signature.CLASS_TYPE_SIGNATURE: String erasureSig= Signature.getTypeErasure(typeSig); String erasureName= Signature.toString(erasureSig); if (erasureSig.charAt(0) == Signature.C_RESOLVED) { erasureName= internalAddImport(erasureName, context); } Type baseType= ast.newSimpleType(ast.newName(erasureName)); String[] typeArguments= Signature.getTypeArguments(typeSig); if (typeArguments.length > 0) { ParameterizedType type= ast.newParameterizedType(baseType); List argNodes= type.typeArguments(); for (int i= 0; i < typeArguments.length; i++) { String curr= typeArguments[i]; if (containsNestedCapture(curr)) { // see bug 103044 argNodes.add(ast.newWildcardType()); } else { argNodes.add(addImportFromSignature(curr, ast, context)); } } return type; } return baseType; case Signature.TYPE_VARIABLE_SIGNATURE: return ast.newSimpleType(ast.newSimpleName(Signature.toString(typeSig))); case Signature.WILDCARD_TYPE_SIGNATURE: WildcardType wildcardType= ast.newWildcardType(); char ch= typeSig.charAt(0); if (ch != Signature.C_STAR) { Type bound= addImportFromSignature(typeSig.substring(1), ast, context); wildcardType.setBound(bound, ch == Signature.C_EXTENDS); } return wildcardType; case Signature.CAPTURE_TYPE_SIGNATURE: return addImportFromSignature(typeSig.substring(1), ast, context); default: throw new IllegalArgumentException("Unknown type signature kind: " + typeSig); //$NON-NLS-1$ } }
Example 8
Source File: JavaStatementPostfixContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private Type createType(String typeSig, AST ast) { int sigKind = Signature.getTypeSignatureKind(typeSig); switch (sigKind) { case Signature.BASE_TYPE_SIGNATURE: return ast.newPrimitiveType(PrimitiveType.toCode(Signature.toString(typeSig))); case Signature.ARRAY_TYPE_SIGNATURE: Type elementType = createType(Signature.getElementType(typeSig), ast); return ast.newArrayType(elementType, Signature.getArrayCount(typeSig)); case Signature.CLASS_TYPE_SIGNATURE: String erasureSig = Signature.getTypeErasure(typeSig); String erasureName = Signature.toString(erasureSig); if (erasureSig.charAt(0) == Signature.C_RESOLVED) { erasureName = addImport(erasureName); } Type baseType= ast.newSimpleType(ast.newName(erasureName)); String[] typeArguments = Signature.getTypeArguments(typeSig); if (typeArguments.length > 0) { ParameterizedType type = ast.newParameterizedType(baseType); List argNodes = type.typeArguments(); for (int i = 0; i < typeArguments.length; i++) { String curr = typeArguments[i]; if (containsNestedCapture(curr)) { argNodes.add(ast.newWildcardType()); } else { argNodes.add(createType(curr, ast)); } } return type; } return baseType; case Signature.TYPE_VARIABLE_SIGNATURE: return ast.newSimpleType(ast.newSimpleName(Signature.toString(typeSig))); case Signature.WILDCARD_TYPE_SIGNATURE: WildcardType wildcardType= ast.newWildcardType(); char ch = typeSig.charAt(0); if (ch != Signature.C_STAR) { Type bound= createType(typeSig.substring(1), ast); wildcardType.setBound(bound, ch == Signature.C_EXTENDS); } return wildcardType; case Signature.CAPTURE_TYPE_SIGNATURE: return createType(typeSig.substring(1), ast); } return ast.newSimpleType(ast.newName("java.lang.Object")); }