org.eclipse.jdt.core.Signature.getSimpleName()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中org.eclipse.jdt.core.Signature.getSimpleName()方法的一些代码示例,展示了Signature.getSimpleName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Signature.getSimpleName()方法的具体详情如下:
包路径:org.eclipse.jdt.core.Signature
类名称:Signature
方法名:getSimpleName

Signature.getSimpleName介绍

[英]Returns the last segment of the given dot-separated qualified name. Returns the given name if it is not qualified.

For example:

getSimpleName("java.lang.Object") -> "Object" 
 
 
getSimpleName("java.util.Map<java.lang.String, java.lang.Object>") -> "Map<String,Object>"

[中]返回给定的以点分隔的限定名称的最后一段。如果给定名称不合格,则返回该名称。
例如:

getSimpleName("java.lang.Object") -> "Object" 
 
 
getSimpleName("java.util.Map<java.lang.String, java.lang.Object>") -> "Map<String,Object>"

代码示例

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

public JavaTypeCompletionProposal(String replacementString, ICompilationUnit cu, int replacementOffset, int replacementLength, Image image, StyledString displayString, int relevance, String fullyQualifiedTypeName, JavaContentAssistInvocationContext invocationContext) {
  super(replacementString, replacementOffset, replacementLength, image, displayString, relevance, false, invocationContext);
  fCompilationUnit= cu;
  fFullyQualifiedTypeName= fullyQualifiedTypeName;
  fUnqualifiedTypeName= fullyQualifiedTypeName != null ? Signature.getSimpleName(fullyQualifiedTypeName) : null;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

public JavaTypeCompletionProposal(String replacementString, ICompilationUnit cu, int replacementOffset, int replacementLength, Image image, StyledString displayString, int relevance, String fullyQualifiedTypeName, JavaContentAssistInvocationContext invocationContext) {
  super(replacementString, replacementOffset, replacementLength, image, displayString, relevance, false, invocationContext);
  fCompilationUnit= cu;
  fFullyQualifiedTypeName= fullyQualifiedTypeName;
  fUnqualifiedTypeName= fullyQualifiedTypeName != null ? Signature.getSimpleName(fullyQualifiedTypeName) : null;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

protected final String getSimpleTypeName() {
  if (fSimpleName == null)
    fSimpleName= Signature.getSimpleName(getQualifiedTypeName());
  return fSimpleName;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

protected final String getSimpleTypeName() {
  if (fSimpleName == null)
    fSimpleName= Signature.getSimpleName(getQualifiedTypeName());
  return fSimpleName;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

private String computeTypeParameterDisplayName(ITypeParameter parameter, String[] bounds) {
  if (bounds.length == 0 || bounds.length == 1 && "java.lang.Object".equals(bounds[0])) //$NON-NLS-1$
    return parameter.getElementName();
  StringBuilder buf= new StringBuilder(parameter.getElementName());
  buf.append(" extends "); //$NON-NLS-1$
  for (int i= 0; i < bounds.length; i++) {
    buf.append(Signature.getSimpleName(bounds[i]));
    if (i < bounds.length - 1)
      buf.append(" & "); //$NON-NLS-1$
  }
  return buf.toString();
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private String[] suggestVariableName(String type, String[] excludes) throws IllegalArgumentException {
  int dim=0;
  while (type.endsWith("[]")) {//$NON-NLS-1$
    dim++;
    type= type.substring(0, type.length() - 2);
  }
  
  IJavaProject project= getJavaProject();
  if (project != null)
    return StubUtility.getVariableNameSuggestions(StubUtility.LOCAL, project, type, dim, Arrays.asList(excludes), true);
  
  // fallback if we lack proper context: roll-our own lowercasing
  return new String[] {Signature.getSimpleName(type).toLowerCase()};
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

private void validateHasChildProperty(ASTNode parent, StructuralPropertyDescriptor property) {
  if (!parent.structuralPropertiesForType().contains(property)) {
    String message= Signature.getSimpleName(parent.getClass().getName()) + " has no property " + property.getId(); //$NON-NLS-1$
    throw new IllegalArgumentException(message);
  }
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core

private void validateHasChildProperty(ASTNode parent, StructuralPropertyDescriptor property) {
  if (!parent.structuralPropertiesForType().contains(property)) {
    String message= Signature.getSimpleName(parent.getClass().getName()) + " has no property " + property.getId(); //$NON-NLS-1$
    throw new IllegalArgumentException(message);
  }
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

private String computeTypeProposal(ITypeParameter parameter) throws JavaModelException {
  String[] bounds= parameter.getBounds();
  String elementName= parameter.getElementName();
  if (bounds.length == 1 && !"java.lang.Object".equals(bounds[0])) {
    return Signature.getSimpleName(bounds[0]);
  } else {
    return elementName;
  }
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

/**
 * Returns the simple name of the given type signature.
 *
 * @param enclosingElement the enclosing element in which to resolve the signature
 * @param typeSig a {@link Signature#CLASS_TYPE_SIGNATURE} or {@link Signature#TYPE_VARIABLE_SIGNATURE}
 * @return the simple name of the given type signature
 */
protected String getSimpleTypeName(IJavaElement enclosingElement, String typeSig) {
  return Signature.getSimpleName(Signature.toString(Signature.getTypeErasure(typeSig)));
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core

public static ImportName createFor(boolean isStatic, String qualifiedName) {
  String containerName = Signature.getQualifier(qualifiedName);
  String simpleName = Signature.getSimpleName(qualifiedName);
  return new ImportName(isStatic, containerName, simpleName);
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core.manipulation

/**
 * Returns the simple name of the given type signature.
 *
 * @param enclosingElement the enclosing element in which to resolve the signature
 * @param typeSig a {@link Signature#CLASS_TYPE_SIGNATURE} or {@link Signature#TYPE_VARIABLE_SIGNATURE}
 * @return the simple name of the given type signature
 */
protected String getSimpleTypeName(IJavaElement enclosingElement, String typeSig) {
  return Signature.getSimpleName(Signature.toString(Signature.getTypeErasure(typeSig)));
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

/**
 * Returns the simple name of the given type signature.
 *
 * @param enclosingElement the enclosing element in which to resolve the signature
 * @param typeSig a {@link Signature#CLASS_TYPE_SIGNATURE} or {@link Signature#TYPE_VARIABLE_SIGNATURE}
 * @return the simple name of the given type signature
 */
protected String getSimpleTypeName(IJavaElement enclosingElement, String typeSig) {
  return Signature.getSimpleName(Signature.toString(Signature.getTypeErasure(typeSig)));
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

public static ImportName createFor(boolean isStatic, String qualifiedName) {
  String containerName = Signature.getQualifier(qualifiedName);
  String simpleName = Signature.getSimpleName(qualifiedName);
  return new ImportName(isStatic, containerName, simpleName);
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

public static IStorage getResourceBundle(ICompilationUnit compilationUnit) throws JavaModelException {
  IJavaProject project= compilationUnit.getJavaProject();
  if (project == null)
    return null;
  String name= getResourceBundleName(compilationUnit);
  if (name == null)
    return null;
  String packName= Signature.getQualifier(name);
  String resourceName= Signature.getSimpleName(name) + NLSRefactoring.PROPERTY_FILE_EXT;
  return getResourceBundle(project, packName, resourceName);
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

private void addType(char[] typeNameSig, int flags, int relevance) {
  int kind= getKind(flags, typeNameSig);
  if (!isKind(kind)) {
    return;
  }
  String fullName= new String(Signature.toCharArray(Signature.getTypeErasure(typeNameSig)));
  //		if (TypeFilter.isFiltered(fullName)) {  // requires jdt.ui preferences
  //			return;
  //		}
  if (NameMatcher.isSimilarName(fName, Signature.getSimpleName(fullName))) {
    addResult(new SimilarElement(kind, fullName, relevance));
  }
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.junit.core

public static boolean hasSuiteMethod(IType type) throws JavaModelException {
  IMethod method= type.getMethod("suite", new String[0]); //$NON-NLS-1$
  if (!method.exists())
    return false;
  if (!Flags.isStatic(method.getFlags()) || !Flags.isPublic(method.getFlags())) {
    return false;
  }
  if (!Signature.getSimpleName(Signature.toString(method.getReturnType())).equals(JUnitCorePlugin.SIMPLE_TEST_INTERFACE_NAME)) {
    return false;
  }
  return true;
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

private void updateImport(ICompilationUnit cu, IImportDeclaration importDeclaration, String updatedImport) throws JavaModelException {
  ImportChange importChange= fImportsManager.getImportChange(cu);
  if (Flags.isStatic(importDeclaration.getFlags())) {
    importChange.removeStaticImport(importDeclaration.getElementName());
    importChange.addStaticImport(Signature.getQualifier(updatedImport), Signature.getSimpleName(updatedImport));
  } else {
    importChange.removeImport(importDeclaration.getElementName());
    importChange.addImport(updatedImport);
  }
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

static CompilationUnitChange createAddImportChange(ICompilationUnit cu, Name name, String fullyQualifiedName) throws CoreException {
  String[] args= { BasicElementLabels.getJavaElementName(Signature.getSimpleName(fullyQualifiedName)),
      BasicElementLabels.getJavaElementName(Signature.getQualifier(fullyQualifiedName)) };
  String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_importtype_description, args);
  CompilationUnitChange cuChange= new CompilationUnitChange(label, cu);
  ImportRewrite importRewrite = CodeStyleConfiguration.createImportRewrite((CompilationUnit) name.getRoot(), true);
  importRewrite.addImport(fullyQualifiedName);
  cuChange.setEdit(importRewrite.rewriteImports(null));
  return cuChange;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

private void updateImport(ICompilationUnit cu, IImportDeclaration importDeclaration, String updatedImport) throws JavaModelException {
  ImportChange importChange= fImportsManager.getImportChange(cu);
  if (Flags.isStatic(importDeclaration.getFlags())) {
    importChange.removeStaticImport(importDeclaration.getElementName());
    importChange.addStaticImport(Signature.getQualifier(updatedImport), Signature.getSimpleName(updatedImport));
  } else {
    importChange.removeImport(importDeclaration.getElementName());
    importChange.addImport(updatedImport);
  }
}

相关文章