下面列出了com.intellij.psi.PsiClass#getProject ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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());
}
/**
* 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);
}
}
/** 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);
}
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();
}
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);
}