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

The following examples show how to use com.intellij.psi.PsiClass#getProject() . 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: OnEventGenerateUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
/**
 * Adds comment to the given method "// An event handler ContextClassName.methodName(c,
 * parameterName)
 */
public static void addComment(PsiClass contextClass, PsiMethod method) {
  final Project project = contextClass.getProject();
  final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);

  final StringBuilder builder =
      new StringBuilder("// An event handler ")
          .append(LithoPluginUtils.getLithoComponentNameFromSpec(contextClass.getName()))
          .append(".")
          .append(method.getName())
          .append("(")
          .append(CONTEXT_PARAMETER_NAME);
  for (PsiParameter parameter : method.getParameterList().getParameters()) {
    if (LithoPluginUtils.isParam(parameter)) {
      builder.append(", ").append(parameter.getName());
    }
  }

  builder.append(")");
  final PsiComment comment = factory.createCommentFromText(builder.toString(), method);
  method.addBefore(comment, method.getModifierList());
}
 
Example 2
Source File: ComponentGenerateUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
/**
 * Updates generated Component file from the given Spec class or do nothing if provided class
 * doesn't contain {@link LayoutSpec}.
 *
 * @param layoutSpecCls class containing {@link LayoutSpec} class.
 */
public static void updateLayoutComponent(PsiClass layoutSpecCls) {
  final String componentName =
      LithoPluginUtils.getLithoComponentNameFromSpec(layoutSpecCls.getQualifiedName());
  if (componentName == null) return;

  final Project project = layoutSpecCls.getProject();
  final Runnable job =
      () -> {
        final LayoutSpecModel model = createLayoutModel(layoutSpecCls);
        updateComponent(componentName, model, project);
      };
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    job.run();
  } else {
    DumbService.getInstance(project).smartInvokeLater(job);
  }
}
 
Example 3
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 4
Source File: GenerateDialog.java    From android-parcelable-intellij-plugin with Apache License 2.0 6 votes vote down vote up
protected GenerateDialog(final PsiClass psiClass) {
    super(psiClass.getProject());
    setTitle("Select Fields for Parcelable Generation");

    fieldsCollection = new CollectionListModel<PsiField>();
    final JBList fieldList = new JBList(fieldsCollection);
    fieldList.setCellRenderer(new DefaultPsiElementCellRenderer());
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(fieldList).disableAddAction();
    final JPanel panel = decorator.createPanel();

    fieldsComponent = LabeledComponent.create(panel, "Fields to include in Parcelable");

    includeSubclasses = new JBCheckBox("Include fields from base classes");
    setupCheckboxClickAction(psiClass);
    showCheckbox = psiClass.getFields().length != psiClass.getAllFields().length;

    updateFieldsDisplay(psiClass);
    init();
}
 
Example 5
Source File: PsiConsultantImpl.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private static boolean isLazyOrProvider(PsiClass psiClass) {
  if (psiClass == null) {
    return false;
  }
  Project project = psiClass.getProject();
  JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
  GlobalSearchScope globalSearchScope = GlobalSearchScope.allScope(project);

  PsiClass lazyClass = javaPsiFacade.findClass(CLASS_LAZY, globalSearchScope);
  PsiClass providerClass = javaPsiFacade.findClass(CLASS_PROVIDER, globalSearchScope);

  return psiClass.equals(lazyClass) || psiClass.equals(providerClass);
}