当前位置: 首页>>代码示例>>Java>>正文


Java Signature.getTypeErasure方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.Signature.getTypeErasure方法的典型用法代码示例。如果您正苦于以下问题:Java Signature.getTypeErasure方法的具体用法?Java Signature.getTypeErasure怎么用?Java Signature.getTypeErasure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.Signature的用法示例。


在下文中一共展示了Signature.getTypeErasure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAnonymousTypeLabel

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
private void createAnonymousTypeLabel(CompletionProposal proposal, CompletionItem item) {
	char[] declaringTypeSignature= proposal.getDeclarationSignature();
	declaringTypeSignature= Signature.getTypeErasure(declaringTypeSignature);
	String name = new String(Signature.getSignatureSimpleName(declaringTypeSignature));
	item.setInsertText(name);
	StringBuilder buf= new StringBuilder();
	buf.append(name);
	buf.append('(');
	appendUnboundedParameterList(buf, proposal);
	buf.append(')');
	buf.append("  "); //$NON-NLS-1$
	buf.append("Anonymous Inner Type"); //TODO: consider externalization
	item.setLabel(buf.toString());

	if (proposal.getRequiredProposals() != null) {
		char[] signatureQualifier= Signature.getSignatureQualifier(declaringTypeSignature);
		if (signatureQualifier.length > 0) {
			item.setDetail(String.valueOf(signatureQualifier));
		}
	}
	setDeclarationSignature(item, String.valueOf(declaringTypeSignature));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:CompletionProposalDescriptionProvider.java

示例2: createAnonymousTypeLabel

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
StyledString createAnonymousTypeLabel(CompletionProposal proposal) {
  char[] declaringTypeSignature = proposal.getDeclarationSignature();
  declaringTypeSignature = Signature.getTypeErasure(declaringTypeSignature);

  StyledString buffer = new StyledString();
  buffer.append(Signature.getSignatureSimpleName(declaringTypeSignature));
  buffer.append('(');
  appendUnboundedParameterList(buffer, proposal);
  buffer.append(')');
  buffer.append("  "); // $NON-NLS-1$
  buffer.append(JavaTextMessages.ResultCollector_anonymous_type);

  if (proposal.getRequiredProposals() != null) {
    char[] signatureQualifier = Signature.getSignatureQualifier(declaringTypeSignature);
    if (signatureQualifier.length > 0) {
      buffer.append(JavaElementLabels.CONCAT_STRING, StyledString.QUALIFIER_STYLER);
      buffer.append(signatureQualifier, StyledString.QUALIFIER_STYLER);
    }
  }

  return Strings.markJavaElementLabelLTR(buffer);
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:CompletionProposalLabelProvider.java

示例3: getQualifiedNameFromTypeSignature

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
public static String getQualifiedNameFromTypeSignature(String typeSignature, IType declaringType)
		throws JavaModelException {
	typeSignature = Signature.getTypeErasure(typeSignature);
	String signatureQualifier = Signature.getSignatureQualifier(typeSignature);
	String signatureSimpleName = Signature.getSignatureSimpleName(typeSignature);
	String simpleName = signatureQualifier.isEmpty() ? signatureSimpleName
			: signatureQualifier + '.' + signatureSimpleName;

	// workaround https://bugs.eclipse.org/bugs/show_bug.cgi?id=494209.
	boolean isArray = false;
	if (simpleName.endsWith("[]")) {
		isArray = true;
		simpleName = simpleName.substring(0, simpleName.lastIndexOf('['));
	}

	String[][] allResults = declaringType.resolveType(simpleName);
	String fullName = null;
	if (allResults != null) {
		String[] nameParts = allResults[0];
		if (nameParts != null) {
			StringBuilder fullNameBuilder = new StringBuilder();
			for (String part : nameParts) {
				if (fullNameBuilder.length() > 0)
					fullNameBuilder.append('.');
				if (part != null)
					fullNameBuilder.append(part);
			}
			fullName = fullNameBuilder.toString();
		}
	} else
		fullName = simpleName;

	// workaround https://bugs.eclipse.org/bugs/show_bug.cgi?id=494209.
	if (isArray)
		fullName += "[]";

	return fullName;
}
 
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:39,代码来源:Util.java

示例4: sameParameter

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:38,代码来源:Bindings.java

示例5: qualifySignature

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
 * Returns the qualified signature corresponding to <code>signature</code>.
 *
 * @param signature the signature to qualify
 * @param context the type inside which an unqualified type will be resolved to find the
 *     qualifier, or <code>null</code> if no context is available
 * @return the qualified signature
 */
public static String qualifySignature(final String signature, final IType context) {
  if (context == null) return signature;

  String qualifier = Signature.getSignatureQualifier(signature);
  if (qualifier.length() > 0) return signature;

  String elementType = Signature.getElementType(signature);
  String erasure = Signature.getTypeErasure(elementType);
  String simpleName = Signature.getSignatureSimpleName(erasure);
  String genericSimpleName = Signature.getSignatureSimpleName(elementType);

  int dim = Signature.getArrayCount(signature);

  try {
    String[][] strings = context.resolveType(simpleName);
    if (strings != null && strings.length > 0) qualifier = strings[0][0];
  } catch (JavaModelException e) {
    // ignore - not found
  }

  if (qualifier.length() == 0) return signature;

  String qualifiedType = Signature.toQualifiedName(new String[] {qualifier, genericSimpleName});
  String qualifiedSignature = Signature.createTypeSignature(qualifiedType, true);
  String newSignature = Signature.createArraySignature(qualifiedSignature, dim);

  return newSignature;
}
 
开发者ID:eclipse,项目名称:che,代码行数:37,代码来源:SignatureUtil.java

示例6: computeSimpleTypeName

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
 * Returns the simple erased name for a given type signature, possibly replacing type variables.
 *
 * @param signature the type signature
 * @param typeVariables the Map&lt;SimpleName, VariableName>
 * @return the simple erased name for signature
 */
private String computeSimpleTypeName(String signature, Map<String, char[]> typeVariables) {
  // method equality uses erased types
  String erasure = Signature.getTypeErasure(signature);
  erasure = erasure.replaceAll("/", "."); // $NON-NLS-1$//$NON-NLS-2$
  String simpleName = Signature.getSimpleName(Signature.toString(erasure));
  char[] typeVar = typeVariables.get(simpleName);
  if (typeVar != null) simpleName = String.valueOf(Signature.getSignatureSimpleName(typeVar));
  return simpleName;
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:MethodProposalInfo.java

示例7: collectTypeArguments

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
static void collectTypeArguments(String signature, Set<String> types){
    String[] typeArguments = Signature.getTypeArguments(signature);
    for (String arg : typeArguments) {
        String[] newArguments = Signature.getTypeArguments(arg);
        String simpleName = Signature.getTypeErasure(arg);
        types.add(simpleName);
        if(newArguments.length == 0) {
            types.add(arg);
        } else {
            collectTypeArguments(arg, types);
        }
    }
}
 
开发者ID:iloveeclipse,项目名称:datahierarchy,代码行数:14,代码来源:JavaSearchJob.java

示例8: getBaseType

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
 * Removes any type parameters and any array nesting in a type signature.
 */
private static String getBaseType(String typeSignature) {
  // Strip off any type parameters
  typeSignature = Signature.getTypeErasure(typeSignature);

  // Strip off any array nesting
  typeSignature = Signature.getElementType(typeSignature);

  return typeSignature;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:13,代码来源:JavaModelSearch.java

示例9: resolveToQualifiedErasure

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
private static String resolveToQualifiedErasure(IType context,
    String typeSignature) throws RemoteServiceException {
  try {
    String typeErasureSig = Signature.getTypeErasure(typeSignature);
    String type = Signature.getSignatureSimpleName(typeErasureSig);
    String qualifiedErasure = JavaModelSearch.resolveTypeName(context, type);
    if (qualifiedErasure == null) {
      throw new RemoteServiceException("Could not resolve type " + type);
    }
    return qualifiedErasure;
  } catch (JavaModelException e) {
    throw new RemoteServiceException(e);
  }
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:15,代码来源:RemoteServiceUtilities.java

示例10: appendImportProposal

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
private StringBuilder appendImportProposal(StringBuilder buffer, CompletionProposal proposal, int coreKind) {
	int proposalKind= proposal.getKind();
	String qualifiedTypeName= null;
	char[] qualifiedType= null;
	if (proposalKind == CompletionProposal.TYPE_IMPORT) {
		qualifiedType= proposal.getSignature();
		qualifiedTypeName= String.valueOf(Signature.toCharArray(qualifiedType));
	} else if (proposalKind == CompletionProposal.METHOD_IMPORT || proposalKind == CompletionProposal.FIELD_IMPORT) {
		qualifiedType= Signature.getTypeErasure(proposal.getDeclarationSignature());
		qualifiedTypeName= String.valueOf(Signature.toCharArray(qualifiedType));
	} else {
		/*
		 * In 3.3 we only support the above import proposals, see
		 * CompletionProposal#getRequiredProposals()
		 */
		Assert.isTrue(false);
	}

	/* Add imports if the preference is on. */
	if (importRewrite != null) {
		if (proposalKind == CompletionProposal.TYPE_IMPORT) {
			String simpleType= importRewrite.addImport(qualifiedTypeName, null);
			if (coreKind == CompletionProposal.METHOD_REF) {
				buffer.append(simpleType);
				buffer.append(COMMA);
				return buffer;
			}
		} else {
			String res= importRewrite.addStaticImport(qualifiedTypeName, String.valueOf(proposal.getName()), proposalKind == CompletionProposal.FIELD_IMPORT, null);
			int dot= res.lastIndexOf('.');
			if (dot != -1) {
				buffer.append(importRewrite.addImport(res.substring(0, dot), null));
				buffer.append('.');
				return buffer;
			}
		}
		return buffer;
	}

	// Case where we don't have an import rewrite (see allowAddingImports)

	if (compilationUnit != null && isImplicitImport(Signature.getQualifier(qualifiedTypeName), compilationUnit)) {
		/* No imports for implicit imports. */

		if (proposal.getKind() == CompletionProposal.TYPE_IMPORT && coreKind == CompletionProposal.FIELD_REF) {
			return buffer;
		}
		qualifiedTypeName= String.valueOf(Signature.getSignatureSimpleName(qualifiedType));
	}
	buffer.append(qualifiedTypeName);
	buffer.append('.');
	return buffer;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:54,代码来源:CompletionProposalReplacementProvider.java

示例11: sameParameter

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:43,代码来源:Bindings.java

示例12: computeReplacementString

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
 * Computes the replacement string.
 *
 * @return the replacement string
 */
private String computeReplacementString() {
  int proposalKind = fProposal.getKind();
  String qualifiedTypeName = null;
  char[] qualifiedType = null;
  if (proposalKind == CompletionProposal.TYPE_IMPORT) {
    qualifiedType = fProposal.getSignature();
    qualifiedTypeName = String.valueOf(Signature.toCharArray(qualifiedType));
  } else if (proposalKind == CompletionProposal.METHOD_IMPORT
      || proposalKind == CompletionProposal.FIELD_IMPORT) {
    qualifiedType = Signature.getTypeErasure(fProposal.getDeclarationSignature());
    qualifiedTypeName = String.valueOf(Signature.toCharArray(qualifiedType));
  } else {
    /*
     * In 3.3 we only support the above import proposals, see
     * CompletionProposal#getRequiredProposals()
     */
    Assert.isTrue(false);
  }

  /* Add imports if the preference is on. */
  fImportRewrite = createImportRewrite();
  if (fImportRewrite != null) {
    if (proposalKind == CompletionProposal.TYPE_IMPORT) {
      String simpleType = fImportRewrite.addImport(qualifiedTypeName, fImportContext);
      if (fParentProposalKind == CompletionProposal.METHOD_REF)
        return simpleType + "."; // $NON-NLS-1$
    } else {
      String res =
          fImportRewrite.addStaticImport(
              qualifiedTypeName,
              String.valueOf(fProposal.getName()),
              proposalKind == CompletionProposal.FIELD_IMPORT,
              fImportContext);
      int dot = res.lastIndexOf('.');
      if (dot != -1) {
        String typeName = fImportRewrite.addImport(res.substring(0, dot), fImportContext);
        return typeName + '.';
      }
    }
    return ""; // $NON-NLS-1$
  }

  // Case where we don't have an import rewrite (see allowAddingImports)

  if (fCompilationUnit != null
      && JavaModelUtil.isImplicitImport(
          Signature.getQualifier(qualifiedTypeName), fCompilationUnit)) {
    /* No imports for implicit imports. */

    if (fProposal.getKind() == CompletionProposal.TYPE_IMPORT
        && fParentProposalKind == CompletionProposal.FIELD_REF) return ""; // $NON-NLS-1$
    qualifiedTypeName = String.valueOf(Signature.getSignatureSimpleName(qualifiedType));
  }

  return qualifiedTypeName + "."; // $NON-NLS-1$
}
 
开发者ID:eclipse,项目名称:che,代码行数:62,代码来源:ImportCompletionProposal.java

示例13: appendMethodReference

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
private static void appendMethodReference(IMethod meth, StringBuffer buf)
    throws JavaModelException {
  buf.append(meth.getElementName());

  /*
   * The Javadoc tool for Java SE 8 changed the anchor syntax and now tries to avoid "strange" characters in URLs.
   * This breaks all clients that directly create such URLs.
   * We can't know what format is required, so we just guess by the project's compiler compliance.
   */
  boolean is18OrHigher = JavaModelUtil.is18OrHigher(meth.getJavaProject());
  buf.append(is18OrHigher ? '-' : '(');
  String[] params = meth.getParameterTypes();
  IType declaringType = meth.getDeclaringType();
  boolean isVararg = Flags.isVarargs(meth.getFlags());
  int lastParam = params.length - 1;
  for (int i = 0; i <= lastParam; i++) {
    if (i != 0) {
      buf.append(is18OrHigher ? "-" : ", "); // $NON-NLS-1$ //$NON-NLS-2$
    }
    String curr = Signature.getTypeErasure(params[i]);
    String fullName = JavaModelUtil.getResolvedTypeName(curr, declaringType);
    if (fullName == null) { // e.g. a type parameter "QE;"
      fullName = Signature.toString(Signature.getElementType(curr));
    }
    if (fullName != null) {
      buf.append(fullName);
      int dim = Signature.getArrayCount(curr);
      if (i == lastParam && isVararg) {
        dim--;
      }
      while (dim > 0) {
        buf.append(is18OrHigher ? ":A" : "[]"); // $NON-NLS-1$ //$NON-NLS-2$
        dim--;
      }
      if (i == lastParam && isVararg) {
        buf.append("..."); // $NON-NLS-1$
      }
    }
  }
  buf.append(is18OrHigher ? '-' : ')');
}
 
开发者ID:eclipse,项目名称:che,代码行数:42,代码来源:JavaDocLocations.java

示例14: createTypeProposalLabel

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
 * Updates a display label for a given type proposal. The display label
 * consists of:
 * <ul>
 *   <li>the simple type name (erased when the context is in javadoc)</li>
 *   <li>the package name</li>
 * </ul>
 * <p>
 * Examples:
 * A proposal for the generic type <code>java.util.List&lt;E&gt;</code>, the display label
 * is: <code>List<E> - java.util</code>.
 * </p>
 *
 * @param typeProposal the method proposal to display
 * @param item the completion to update
 */
private void createTypeProposalLabel(CompletionProposal typeProposal, CompletionItem item) {
	char[] signature;
	if (fContext != null && fContext.isInJavadoc()) {
		signature= Signature.getTypeErasure(typeProposal.getSignature());
	} else {
		signature= typeProposal.getSignature();
	}
	char[] fullName= Signature.toCharArray(signature);
	createTypeProposalLabel(fullName, item);
	setDeclarationSignature(item, String.valueOf(signature));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:28,代码来源:CompletionProposalDescriptionProvider.java

示例15: createTypeProposalLabel

import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
 * Creates a display label for a given type proposal. The display label consists of:
 *
 * <ul>
 *   <li>the simple type name (erased when the context is in javadoc)
 *   <li>the package name
 * </ul>
 *
 * <p>Examples: A proposal for the generic type <code>java.util.List&lt;E&gt;</code>, the display
 * label is: <code>List<E> - java.util</code>.
 *
 * @param typeProposal the method proposal to display
 * @return the display label for the given type proposal
 */
StyledString createTypeProposalLabel(CompletionProposal typeProposal) {
  char[] signature;
  if (fContext != null && fContext.isInJavadoc())
    signature = Signature.getTypeErasure(typeProposal.getSignature());
  else signature = typeProposal.getSignature();
  char[] fullName = Signature.toCharArray(signature);
  return createTypeProposalLabel(fullName);
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:CompletionProposalLabelProvider.java


注:本文中的org.eclipse.jdt.core.Signature.getTypeErasure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。