Java Code Examples for com.intellij.openapi.util.text.StringUtil#getShortName()

The following examples show how to use com.intellij.openapi.util.text.StringUtil#getShortName() . 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: ComponentsCacheService.java    From litho with Apache License 2.0 6 votes vote down vote up
/** Updates cached class with provided model. Do nothing if name or model are invalid. */
@Nullable
public PsiClass update(String componentQualifiedName, @Nullable SpecModel model) {
  if (model == null) return null;

  final String componentShortName = StringUtil.getShortName(componentQualifiedName);
  if (componentShortName.isEmpty()) return null;

  final PsiFile file =
      ComponentGenerateUtils.createFileFromModel(componentQualifiedName, model, project);
  ComponentScope.include(file);
  final PsiClass inMemory =
      LithoPluginUtils.getFirstClass(file, cls -> componentShortName.equals(cls.getName()))
          .orElse(null);
  if (inMemory == null) return null;

  componentNameToClass.put(componentQualifiedName, inMemory);
  return inMemory;
}
 
Example 2
Source File: ProducerUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static boolean isJUnit4Class(PsiClass psiClass) {
  String qualifiedName = JUnitUtil.RUN_WITH;
  if (AnnotationUtil.isAnnotated(psiClass, qualifiedName, true)) {
    return true;
  }
  // handle the case where RunWith and/or the current class isn't indexed
  PsiModifierList modifierList = psiClass.getModifierList();
  if (modifierList == null) {
    return false;
  }
  if (modifierList.hasAnnotation(qualifiedName)) {
    return true;
  }
  String shortName = StringUtil.getShortName(qualifiedName);
  return modifierList.hasAnnotation(shortName) && hasImport(psiClass, qualifiedName);
}
 
Example 3
Source File: SpecTreeElementFactory.java    From litho with Apache License 2.0 5 votes vote down vote up
private static TreeElement createEvent(SpecMethodModel<?, EventDeclarationModel> methodModel) {
  return new PresentableTreeElement(
      methodModel.name.toString()
          + " (@"
          + StringUtil.getShortName(methodModel.typeModel.name.simpleName())
          + ")",
      methodModel.representedObject,
      Collections.emptyList());
}
 
Example 4
Source File: CreateTemplateInPackageAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected String removeExtension(String templateName, String className) {
  final String extension = StringUtil.getShortName(templateName);
  if (StringUtil.isNotEmpty(extension)) {
    className = StringUtil.trimEnd(className, "." + extension);
  }
  return className;
}
 
Example 5
Source File: TempDirTestFixtureImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public File createTempFile(String fileName) throws IOException {
  String prefix = StringUtil.getPackageName(fileName);
  if (prefix.length() < 3) {
    prefix += "___";
  }
  String suffix = "." + StringUtil.getShortName(fileName);
  return FileUtil.createTempFile(new File(getTempDirPath()), prefix, suffix, true);
}
 
Example 6
Source File: PsiAnnotationSearchUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private static PsiAnnotation findAnnotationQuick(@Nullable PsiAnnotationOwner annotationOwner, @NotNull String... qualifiedNames) {
  if (annotationOwner == null || qualifiedNames.length == 0) {
    return null;
  }

  PsiAnnotation[] annotations = annotationOwner.getAnnotations();
  if (annotations.length == 0) {
    return null;
  }

  final String[] shortNames = new String[qualifiedNames.length];
  for (int i = 0; i < qualifiedNames.length; i++) {
    shortNames[i] = StringUtil.getShortName(qualifiedNames[i]);
  }

  for (PsiAnnotation annotation : annotations) {
    final PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
    if (null != referenceElement) {
      final String referenceName = referenceElement.getReferenceName();
      if (ArrayUtil.find(shortNames, referenceName) > -1) {

        if (referenceElement.isQualified() && referenceElement instanceof SourceJavaCodeReference) {
          final String possibleFullQualifiedName = ((SourceJavaCodeReference) referenceElement).getClassNameText();

          if (ArrayUtil.find(qualifiedNames, possibleFullQualifiedName) > -1) {
            return annotation;
          }
        }

        final String annotationQualifiedName = getAndCacheFQN(annotation, referenceName);
        if (ArrayUtil.find(qualifiedNames, annotationQualifiedName) > -1) {
          return annotation;
        }
      }
    }
  }

  return null;
}
 
Example 7
Source File: PsiAnnotationSearchUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private static PsiAnnotation findAnnotationQuick(@Nullable PsiAnnotationOwner annotationOwner, @NotNull String qualifiedName) {
  if (annotationOwner == null) {
    return null;
  }

  PsiAnnotation[] annotations = annotationOwner.getAnnotations();
  if (annotations.length == 0) {
    return null;
  }

  final String shortName = StringUtil.getShortName(qualifiedName);

  for (PsiAnnotation annotation : annotations) {
    PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
    if (null != referenceElement) {
      final String referenceName = referenceElement.getReferenceName();
      if (shortName.equals(referenceName)) {

        if (referenceElement.isQualified() && referenceElement instanceof SourceJavaCodeReference) {
          String possibleFullQualifiedName = ((SourceJavaCodeReference) referenceElement).getClassNameText();
          if (qualifiedName.equals(possibleFullQualifiedName)) {
            return annotation;
          }
        }

        final String annotationQualifiedName = getAndCacheFQN(annotation, referenceName);
        if (null != annotationQualifiedName && qualifiedName.endsWith(annotationQualifiedName)) {
          return annotation;
        }
      }
    }
  }

  return null;
}
 
Example 8
Source File: CSharpNamespaceDeclarationImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public String getName()
{
	String qName = getPresentableQName();
	if(qName == null)
	{
		return null;
	}
	return StringUtil.getShortName(qName);
}
 
Example 9
Source File: SpecTreeElementFactory.java    From litho with Apache License 2.0 5 votes vote down vote up
private static TreeElement createDelegate(SpecMethodModel<?, ?> methodModel) {
  return new PresentableTreeElement(
      methodModel.name.toString()
          + " (@"
          + StringUtil.getShortName(
              methodModel.annotations.get(0).annotationType().getSimpleName())
          + ")",
      methodModel.representedObject,
      Collections.emptyList());
}
 
Example 10
Source File: LayoutSpecMethodAnnotationsProvider.java    From litho with Apache License 2.0 5 votes vote down vote up
private static LookupElement createLookup(String annotationFQN, Project project) {
  final String annotation = StringUtil.getShortName(annotationFQN);
  final PsiMethod psiMethod =
      ServiceManager.getService(project, TemplateService.class)
          .getMethodTemplate(annotation, project);
  if (psiMethod != null) {
    PsiClass annotationCls = MethodCompletionContributor.getOrCreateClass(annotationFQN, project);
    return createMethodLookup(psiMethod, annotationCls, "@" + annotation, () -> log(annotation));
  }
  return SpecLookupElement.create(annotationFQN, project, (context1, item) -> log(annotation));
}
 
Example 11
Source File: UnusedUsingVisitor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
@RequiredReadAction
public void visitLinqExpression(CSharpLinqExpressionImpl expression)
{
	super.visitLinqExpression(expression);

	String packageOfEnumerable = StringUtil.getPackageName(DotNetTypes2.System.Linq.Enumerable);
	String className = StringUtil.getShortName(DotNetTypes2.System.Linq.Enumerable);

	for(Map.Entry<CSharpUsingListChild, Boolean> entry : myUsingContext.entrySet())
	{
		if(entry.getValue())
		{
			continue;
		}

		CSharpUsingListChild key = entry.getKey();
		if(key instanceof CSharpUsingTypeStatement)
		{
			if(DotNetTypeRefUtil.isVmQNameEqual(((CSharpUsingTypeStatement) key).getTypeRef(), expression, DotNetTypes2.System.Linq.Enumerable))
			{
				myUsingContext.put(key, Boolean.TRUE);
				break;
			}
		}
		else if(key instanceof CSharpUsingNamespaceStatement)
		{
			String referenceText = ((CSharpUsingNamespaceStatement) key).getReferenceText();

			// our namespace, try find class
			if(packageOfEnumerable.equals(referenceText))
			{
				DotNetNamespaceAsElement namespaceAsElement = ((CSharpUsingNamespaceStatement) key).resolve();
				if(namespaceAsElement != null && namespaceAsElement.findChildren(className, expression.getResolveScope(), DotNetNamespaceAsElement.ChildrenFilter.ONLY_ELEMENTS).size() > 0)
				{
					myUsingContext.put(key, Boolean.TRUE);
					break;
				}
			}
		}
	}
}
 
Example 12
Source File: BaseUnusedUsingVisitor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
@RequiredReadAction
public void visitLinqExpression(CSharpLinqExpressionImpl expression)
{
	super.visitLinqExpression(expression);

	String packageOfEnumerable = StringUtil.getPackageName(DotNetTypes2.System.Linq.Enumerable);
	String className = StringUtil.getShortName(DotNetTypes2.System.Linq.Enumerable);

	Collection<? extends CSharpUsingListChild> statements = getStatements();
	for(CSharpUsingListChild key : statements)
	{
		if(isProcessed(key))
		{
			continue;
		}

		if(key instanceof CSharpUsingTypeStatement)
		{
			if(DotNetTypeRefUtil.isVmQNameEqual(((CSharpUsingTypeStatement) key).getTypeRef(), expression, DotNetTypes2.System.Linq.Enumerable))
			{
				putElement(key, expression);
				break;
			}
		}
		else if(key instanceof CSharpUsingNamespaceStatement)
		{
			String referenceText = ((CSharpUsingNamespaceStatement) key).getReferenceText();

			// our namespace, try find class
			if(packageOfEnumerable.equals(referenceText))
			{
				DotNetNamespaceAsElement namespaceAsElement = ((CSharpUsingNamespaceStatement) key).resolve();
				if(namespaceAsElement != null && namespaceAsElement.findChildren(className, expression.getResolveScope(), DotNetNamespaceAsElement.ChildrenFilter.ONLY_ELEMENTS).size() > 0)
				{
					putElement(key, expression);
					break;
				}
			}
		}
	}
}
 
Example 13
Source File: CSharpLightNamespaceDeclarationBuilder.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
public String getName()
{
	return StringUtil.getShortName(myQualifiedName);
}
 
Example 14
Source File: SMTestSender.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void testRunStarted(Description description) throws Exception {
  myCurrentClassName = StringUtil.getShortName(description.getChildren().get(0).getClassName());
  System.out.println("##teamcity[testSuiteStarted name =\'" + myCurrentClassName + "\']");
}
 
Example 15
Source File: TreeState.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String calcType(@Nullable Object userObject) {
  if (userObject == null) return "";
  String name = userObject.getClass().getName();
  return Integer.toHexString(StringHash.murmur(name, 31)) + ":" + StringUtil.getShortName(name);
}
 
Example 16
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static String obtainActionId(SimpleXmlElement element, String className) {
  String id = element.getAttributeValue(ID_ATTR_NAME);
  return StringUtil.isEmpty(id) ? StringUtil.getShortName(className) : id;
}
 
Example 17
Source File: ToolkitBugsProcessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected Handler() {
  myDetails = StringUtil.getShortName(getClass().getName());
}
 
Example 18
Source File: LocalizeManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void analyzeLibraryJar(String filePath) throws IOException {
  String localeString = null;
  File jarFile = new File(filePath);

  Map<String, LocalizeFileState> localizeFiles = new HashMap<>();

  try (ZipFile zipFile = new ZipFile(jarFile)) {
    Enumeration<? extends ZipEntry> entries = zipFile.entries();

    while (entries.hasMoreElements()) {
      ZipEntry zipEntry = entries.nextElement();

      final String name = zipEntry.getName();

      if (LOCALIZE_LIBRARY_MARKER.equals(name)) {
        try (InputStream inputStream = zipFile.getInputStream(zipEntry)) {
          byte[] bytes = StreamUtil.loadFromStream(inputStream);

          localeString = new String(bytes, StandardCharsets.UTF_8);
        }
      }
      else if (name.startsWith("localize/") && name.endsWith(".yaml")) {
        String pluginId = name.substring(name.indexOf('/') + 1, name.length());
        pluginId = pluginId.substring(0, pluginId.lastIndexOf('/'));
        pluginId = pluginId.replace('/', '.');

        URL localizeFileUrl = URLUtil.getJarEntryURL(jarFile, name);

        String fileName = StringUtil.getShortName(name, '/');
        String id = FileUtilRt.getNameWithoutExtension(fileName);

        String localizeId = pluginId + "." + id;
        localizeFiles.put(localizeId, new LocalizeFileState(localizeId, localizeFileUrl));
      }
    }
  }

  if (StringUtil.isEmptyOrSpaces(localeString)) {
    LOG.warn("There no locale file inside: " + filePath);
    return;
  }

  Locale locale = buildLocale(localeString);
  Map<String, LocalizeFileState> mapByLocalizeId = myLocalizes.computeIfAbsent(locale, l -> new HashMap<>());

  mapByLocalizeId.putAll(localizeFiles);
}
 
Example 19
Source File: DesktopStripeButton.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return StringUtil.getShortName(getClass().getName()) + " text: " + getText();
}