Java Code Examples for com.intellij.psi.PsiClass#getName()

The following examples show how to use com.intellij.psi.PsiClass#getName() . 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: ComponentsMethodDeclarationHandler.java    From litho with Apache License 2.0 6 votes vote down vote up
private static PsiMethod[] findSpecMethods(PsiMethod componentMethod, Project project) {
  if (!componentMethod.getModifierList().hasModifierProperty(PsiModifier.STATIC)) {
    return PsiMethod.EMPTY_ARRAY;
  }

  final PsiClass containingCls =
      (PsiClass) PsiTreeUtil.findFirstParent(componentMethod, PsiClass.class::isInstance);
  if (containingCls == null) return PsiMethod.EMPTY_ARRAY;

  if (!LithoPluginUtils.isGeneratedClass(containingCls)) return PsiMethod.EMPTY_ARRAY;

  // For Unit testing we don't care about package
  final String containingClsName =
      ApplicationManager.getApplication().isUnitTestMode()
          ? containingCls.getName()
          : containingCls.getQualifiedName();
  final PsiClass specCls =
      PsiSearchUtils.findOriginalClass(
          project, LithoPluginUtils.getLithoComponentSpecNameFromComponent(containingClsName));
  if (specCls == null) return PsiMethod.EMPTY_ARRAY;

  return specCls.findMethodsByName(componentMethod.getName(), true);
}
 
Example 2
Source File: CodeGeneratorAction.java    From code-generator with Apache License 2.0 6 votes vote down vote up
private Entity buildClassEntity(PsiClass psiClass) {
    PsiFile psiFile = psiClass.getContainingFile();
    String className = psiClass.getName();
    String packageName = ((PsiClassOwner) psiFile).getPackageName();

    List<Field> fields = Arrays.stream(psiClass.getAllFields()).map(field -> {
        String fieldType = field.getType().getPresentableText();
        String fieldName = field.getName();
        return new Field(fieldType, fieldName);
    }).collect(Collectors.toList());

    return Entity.builder()
        .name(className)
        .packageName(packageName)
        .fields(fields).build();
}
 
Example 3
Source File: Processor.java    From GsonFormat with Apache License 2.0 6 votes vote down vote up
protected void generateConvertMethod(PsiElementFactory factory, PsiClass cls, ClassEntity classEntity) {
    if (cls == null || cls.getName() == null) {
        return;
    }
    if (Config.getInstant().isObjectFromData()) {
        createMethod(factory, Config.getInstant().getObjectFromDataStr().replace("$ClassName$", cls.getName()).trim(), cls);
    }
    if (Config.getInstant().isObjectFromData1()) {
        createMethod(factory, Config.getInstant().getObjectFromDataStr1().replace("$ClassName$", cls.getName()).trim(), cls);
    }
    if (Config.getInstant().isArrayFromData()) {
        createMethod(factory, Config.getInstant().getArrayFromDataStr().replace("$ClassName$", cls.getName()).trim(), cls);
    }
    if (Config.getInstant().isArrayFromData1()) {
        createMethod(factory, Config.getInstant().getArrayFromData1Str().replace("$ClassName$", cls.getName()).trim(), cls);
    }
}
 
Example 4
Source File: AbstractSuperBuilderPreDefinedInnerClassProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<? super PsiElement> processAnnotation(@NotNull PsiClass psiParentClass, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiClass psiClass) {
  SuperBuilderHandler builderHandler = getBuilderHandler();
  // use parent class as source!
  final String builderBaseClassName = builderHandler.getBuilderClassName(psiParentClass);

  List<? super PsiElement> result = new ArrayList<>();
  // apply only to inner BuilderClass
  final String psiClassName = psiClass.getName();
  if (builderBaseClassName.equals(psiClassName)) {
    result.addAll(generatePsiElementsOfBaseBuilderClass(psiParentClass, psiAnnotation, psiClass));
  } else {
    // use parent class as source!
    final String builderImplClassName = builderHandler.getBuilderImplClassName(psiParentClass);
    if (builderImplClassName.equals(psiClassName)) {
      result.addAll(generatePsiElementsOfImplBuilderClass(psiParentClass, psiAnnotation, psiClass));
    }
  }
  return result;
}
 
Example 5
Source File: AbstractBuckTestAction.java    From buck with Apache License 2.0 6 votes vote down vote up
/** Setup and execute a test configuration. */
protected void setupAndExecuteTestConfiguration(
    PsiClass psiClass, @Nullable PsiMethod psiMethod) {
  Project project = psiClass.getProject();
  VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
  String name;
  String testSelectors;
  if (psiMethod != null) {
    name = psiClass.getName() + "#" + psiMethod.getName();
    testSelectors = psiClass.getQualifiedName() + "#" + psiMethod.getName();
  } else {
    name = psiClass.getName();
    testSelectors = psiClass.getQualifiedName();
  }
  createTestConfigurationFromContext(name, testSelectors, project, virtualFile);
}
 
Example 6
Source File: JavaSyncStatusContributor.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public PsiFileAndName toPsiFileAndName(BlazeProjectData projectData, ProjectViewNode<?> node) {
  if (!(node instanceof ClassTreeNode)) {
    return null;
  }
  PsiClass psiClass = ((ClassTreeNode) node).getPsiClass();
  if (psiClass == null) {
    return null;
  }
  PsiFile file = psiClass.getContainingFile();
  return file != null ? new PsiFileAndName(file, psiClass.getName()) : null;
}
 
Example 7
Source File: MultipleJavaClassesTestContextProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private static TestContext fromClasses(
    ListenableFuture<TargetInfo> target, Set<PsiClass> classes) {
  Map<PsiClass, Collection<Location<?>>> methodsPerClass =
      classes.stream().collect(Collectors.toMap(c -> c, c -> ImmutableList.of()));
  String filter = BlazeJUnitTestFilterFlags.testFilterForClassesAndMethods(methodsPerClass);
  if (filter == null || filter.isEmpty()) {
    return null;
  }

  PsiClass sampleClass =
      classes.stream()
          .min(
              Comparator.comparing(
                  PsiClass::getName, Comparator.nullsLast(Comparator.naturalOrder())))
          .orElse(null);
  if (sampleClass == null) {
    return null;
  }
  String name = sampleClass.getName();
  if (name != null && classes.size() > 1) {
    name += String.format(" and %s others", classes.size() - 1);
  }
  return TestContext.builder(sampleClass, ExecutorType.DEBUG_SUPPORTED_TYPES)
      .setTarget(target)
      .setTestFilter(filter)
      .setDescription(name)
      .build();
}
 
Example 8
Source File: JavaBinaryContextProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private static TargetIdeInfo getTarget(Project project, PsiClass mainClass) {
  File mainClassFile = RunUtil.getFileForClass(mainClass);
  if (mainClassFile == null) {
    return null;
  }
  Collection<TargetIdeInfo> javaBinaryTargets = findJavaBinaryTargets(project, mainClassFile);

  String qualifiedName = mainClass.getQualifiedName();
  String className = mainClass.getName();
  if (qualifiedName == null || className == null) {
    // out of date psi element; just take the first match
    return Iterables.getFirst(javaBinaryTargets, null);
  }

  // first look for a matching main_class
  TargetIdeInfo match =
      javaBinaryTargets.stream()
          .filter(
              target ->
                  target.getJavaIdeInfo() != null
                      && qualifiedName.equals(target.getJavaIdeInfo().getJavaBinaryMainClass()))
          .findFirst()
          .orElse(null);
  if (match != null) {
    return match;
  }

  match =
      javaBinaryTargets.stream()
          .filter(target -> className.equals(target.getKey().getLabel().targetName().toString()))
          .findFirst()
          .orElse(null);
  if (match != null) {
    return match;
  }
  return Iterables.getFirst(javaBinaryTargets, null);
}
 
Example 9
Source File: ScalaSyncStatusContributor.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public PsiFileAndName toPsiFileAndName(BlazeProjectData projectData, ProjectViewNode<?> node) {
  if (!(node instanceof ClassTreeNode)) {
    return null;
  }
  PsiClass psiClass = ((ClassTreeNode) node).getPsiClass();
  if (psiClass == null) {
    return null;
  }
  PsiFile file = psiClass.getContainingFile();
  return file != null ? new PsiFileAndName(file, psiClass.getName()) : null;
}
 
Example 10
Source File: SetterFieldProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
private String createCodeBlockText(@NotNull PsiField psiField, @NotNull PsiClass psiClass, PsiType returnType, boolean isStatic, PsiParameter methodParameter) {
  final String blockText;
  final String thisOrClass = isStatic ? psiClass.getName() : "this";
  blockText = String.format("%s.%s = %s; ", thisOrClass, psiField.getName(), methodParameter.getName());

  String codeBlockText = blockText;
  if (!isStatic && !PsiType.VOID.equals(returnType)) {
    codeBlockText += "return this;";
  }

  return codeBlockText;
}
 
Example 11
Source File: QuarkusConfigPropertiesProvider.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
private static String getPrefixFromClassName(PsiClass className) {
	String simpleName = className.getName(); // className.isInner() ? className.local() :
													// className.withoutPackagePrefix();
	return join("-", withoutSuffix(lowerCase(camelHumpsIterator(simpleName)), "config", "configuration",
			"properties", "props"));
}
 
Example 12
Source File: SimpleCompletionExtension.java    From camel-idea-plugin with Apache License 2.0 4 votes vote down vote up
private String createLocationText(PsiClass clazz, PsiFile file) {
    String location = clazz == null ? file.getName() : clazz.getName();
    return " (" + location + ")";
}
 
Example 13
Source File: BlazeJavaAbstractTestCaseConfigurationProducer.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static String configName(PsiClass psiClass, @Nullable PsiMethod method) {
  String classPart = psiClass.getName();
  return method == null ? classPart : String.format("%s.%s", classPart, method.getName());
}
 
Example 14
Source File: PsiUtils.java    From intellij-reference-diagram with Apache License 2.0 4 votes vote down vote up
public static String getPresentableName(PsiElement psiElement) {
    PsiElementDispatcher<String> psiElementDispatcher = new PsiElementDispatcher<String>() {

        @Override
        public String processClass(PsiClass psiClass) {
            return psiClass.getName();
        }

        @Override
        public String processMethod(PsiMethod psiMethod) {
            List<String> parameterArray = MethodFQN.getParameterArray(psiMethod);
            String parameterRepresentation = MethodFQN.createParameterRepresentation(parameterArray);
            return psiMethod.getName() + "(" + parameterRepresentation + ")";
        }

        @Override
        public String processField(PsiField psiField) {
            return psiField.getName();
        }

        @Override
        public String processClassInitializer(PsiClassInitializer psiClassInitializer) {
            return getName(psiClassInitializer);
        }

        @Override
        public String processInnerClass(PsiClass innerClass) {
            return innerClass.getName();
        }

        @Override
        public String processStaticInnerClass(PsiClass staticInnerClass) {
            return staticInnerClass.getName();
        }

        @Override
        public String processEnum(PsiClass anEnum) {
            return anEnum.getName();
        }

        @Override
        public String processPackage(PsiJavaDirectoryImpl aPackage) {
            return aPackage.getName();
        }

        @Override
        public String processFile(PsiJavaFile aFile) {
            return aFile.getName();
        }
    };

    return psiElementDispatcher.dispatch(psiElement);
}
 
Example 15
Source File: OnEventGenerateUtils.java    From litho with Apache License 2.0 2 votes vote down vote up
/**
 * @return String representation of the @OnEvent method first line.
 *     <p>Example:
 *     <pre><code>{@literal @OnEvent(ColorChangedEvent.class)}</code></pre>
 */
static String createOnEventLookupString(PsiClass eventClass) {
  return "@" + OnEvent.class.getSimpleName() + "(" + eventClass.getName() + ".class)";
}