Java Code Examples for org.eclipse.jdt.core.Signature#C_UNRESOLVED

The following examples show how to use org.eclipse.jdt.core.Signature#C_UNRESOLVED . 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: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves a type name in the context of the declaring type.
 *
 * @param refTypeSig the type name in signature notation (for example 'QVector') this can also be an array type, but dimensions will be ignored.
 * @param declaringType the context for resolving (type where the reference was made in)
 * @return returns the fully qualified type name or build-in-type name. if a unresolved type couldn't be resolved null is returned
 * @throws JavaModelException thrown when the type can not be accessed
 */
public static String getResolvedTypeName(String refTypeSig, IType declaringType) throws JavaModelException {
	int arrayCount= Signature.getArrayCount(refTypeSig);
	char type= refTypeSig.charAt(arrayCount);
	if (type == Signature.C_UNRESOLVED) {
		String name= ""; //$NON-NLS-1$
		int bracket= refTypeSig.indexOf(Signature.C_GENERIC_START, arrayCount + 1);
		if (bracket > 0)
			name= refTypeSig.substring(arrayCount + 1, bracket);
		else {
			int semi= refTypeSig.indexOf(Signature.C_SEMICOLON, arrayCount + 1);
			if (semi == -1) {
				throw new IllegalArgumentException();
			}
			name= refTypeSig.substring(arrayCount + 1, semi);
		}
		String[][] resolvedNames= declaringType.resolveType(name);
		if (resolvedNames != null && resolvedNames.length > 0) {
			return JavaModelUtil.concatenateName(resolvedNames[0][0], resolvedNames[0][1]);
		}
		return null;
	} else {
		return Signature.toString(refTypeSig.substring(arrayCount));
	}
}
 
Example 2
Source File: JavaElementFinder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void toQualifiedTypeName(String signature, IType context, StringBuilder result) throws JavaModelException {
	switch(Signature.getTypeSignatureKind(signature)) {
		case Signature.ARRAY_TYPE_SIGNATURE:
			toQualifiedTypeName(Signature.getElementType(signature), context, result);
			for(int i = 0; i < Signature.getArrayCount(signature); i++) {
				result.append("[]");
			}
			return;
		case Signature.CLASS_TYPE_SIGNATURE:
			if (signature.charAt(0) == Signature.C_UNRESOLVED) {
				String[][] resolved = context.resolveType(Signature.toString(signature));
				if (resolved != null && resolved.length == 1) {
					if (resolved[0][0] != null)
						result.append(resolved[0][0]);
					if (result.length() > 0)
						result.append('.');
					result.append(resolved[0][1]);
				} else {
					result.append(Signature.toString(signature));
				}
			} else {
				result.append(Signature.toString(signature));
			}
			return;
		default:
			result.append(Signature.toString(signature));
	}
}
 
Example 3
Source File: SearchUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 4
Source File: Jdt2Ecore.java    From sarl with Apache License 2.0 5 votes vote down vote up
private String resolve(IMethod operation, String typename) throws JavaModelException {
	if (Signature.C_UNRESOLVED == Signature.getElementType(typename).charAt(0)) {
		final ICompilationUnit unit = operation.getCompilationUnit();
		if (unit != null) {
			final String post = "." + Signature.toString(typename); //$NON-NLS-1$
			for (final IImportDeclaration decl : unit.getImports()) {
				if (decl.getElementName().endsWith(post)) {
					return decl.getElementName();
				}
			}
		}
	}
	return Signature.toString(typename);
}
 
Example 5
Source File: Binding2JavaModel.java    From lapse-plus with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isPrimitiveType(String s) {
    char c= s.charAt(0);
    return c != Signature.C_RESOLVED && c != Signature.C_UNRESOLVED;
}
 
Example 6
Source File: GenerateDelegateMethodsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
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: JavaModelSearch.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean methodSignaturesEqual(IType type2, String methodName,
    String[] paramTypes, boolean isConstructor, IMethod method2) {
  try {
    // Method names must match, unless we're comparing constructors
    if (!isConstructor && !method2.getElementName().equals(methodName)) {
      return false;
    }

    // Only compare ctors to ctors and methods to methods
    if (isConstructor != method2.isConstructor()) {
      return false;
    }

    // Parameter count must match
    String signature2 = method2.getSignature();
    String[] paramTypes2 = Signature.getParameterTypes(signature2);
    if (paramTypes.length != paramTypes2.length) {
      return false;
    }

    // Compare each parameter type
    for (int i = 0; i < paramTypes.length; i++) {
      String paramType = paramTypes[i];
      String paramType2 = paramTypes2[i];

      // Compare array nesting depth ([] = 1, [][] = 2, etc.)
      if (Signature.getArrayCount(paramType) != Signature.getArrayCount(paramType2)) {
        return false;
      }

      // Remove any array nesting and generic type parameters
      paramType = getBaseType(paramType);
      paramType2 = getBaseType(paramType2);

      // Extract the full type names from the signatures
      String paramTypeName = getQualifiedTypeName(paramType);
      String paramTypeName2 = getQualifiedTypeName(paramType2);

      if (isTypeParameter(method2, paramTypeName2)) {
        // Skip parameters whose type is a generic type parameter of the
        // method we're comparing against, or the method's containing class
        continue;

        /*
         * TODO: we're currently not checking the bounds of generic type
         * parameters, so sometimes we may return true here even when the
         * caller's method signature doesn't match the method we're comparing
         * against. We could try to add that logic here, or better still, we
         * could integrate TypeOracle and take advantage of its type searching
         * capabilities.
         */
      }

      // If we run into an unresolved parameter type in the method we're
      // searching, we'll need to resolve that before doing the comparison
      if (paramType2.charAt(0) == Signature.C_UNRESOLVED) {
        paramTypeName2 = resolveTypeName(type2, paramTypeName2);
      }

      // Finally, compare the type names
      if (!paramTypeName.equals(paramTypeName2)) {
        return false;
      }
    }

    // We passed all the checks, so the signatures are equal
    return true;

  } catch (JavaModelException e) {
    CorePluginLog.logError(e,
        "Error comparing method signatures of {0} and {1}", methodName,
        method2.getElementName());
    return false;
  }
}
 
Example 8
Source File: AddDelegateMethodsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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);
}