本文整理汇总了Java中com.intellij.psi.util.PsiMethodUtil类的典型用法代码示例。如果您正苦于以下问题:Java PsiMethodUtil类的具体用法?Java PsiMethodUtil怎么用?Java PsiMethodUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiMethodUtil类属于com.intellij.psi.util包,在下文中一共展示了PsiMethodUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isActionEnabled
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
private static boolean isActionEnabled(final AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) return false;
Editor editor = e.getData(CommonDataKeys.EDITOR);
if (editor == null) return false;
int offset = editor.getCaretModel().getOffset();
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null) return false;
PsiElement element = file.findElementAt(offset);
if (element == null) return false;
PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (psiClass == null) return false;
if (PsiMethodUtil.findMainMethod(psiClass) != null) return false;
if (FormClassIndex.findFormsBoundToClass(project, psiClass).isEmpty()) return false;
return true;
}
示例2: isActionEnabled
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
private static boolean isActionEnabled(final AnActionEvent e) {
Project project = e.getData(PlatformDataKeys.PROJECT);
if (project == null) return false;
Editor editor = e.getData(PlatformDataKeys.EDITOR);
if (editor == null) return false;
int offset = editor.getCaretModel().getOffset();
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null) return false;
PsiElement element = file.findElementAt(offset);
if (element == null) return false;
PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (psiClass == null) return false;
if (PsiMethodUtil.findMainMethod(psiClass) != null) return false;
if (FormClassIndex.findFormsBoundToClass(psiClass).isEmpty()) return false;
return true;
}
示例3: isActionEnabled
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
private static boolean isActionEnabled(final AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) return false;
Editor editor = e.getData(PlatformDataKeys.EDITOR);
if (editor == null) return false;
int offset = editor.getCaretModel().getOffset();
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null) return false;
PsiElement element = file.findElementAt(offset);
if (element == null) return false;
PsiClass psiClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (psiClass == null) return false;
if (PsiMethodUtil.findMainMethod(psiClass) != null) return false;
if (FormClassIndex.findFormsBoundToClass(psiClass).isEmpty()) return false;
return true;
}
示例4: getInfo
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
@Nullable
@Override
public Info getInfo(final PsiElement e)
{
if(isIdentifier(e))
{
PsiElement element = e.getParent();
if(element instanceof PsiClass && PsiMethodUtil.findMainInClass((PsiClass) element) != null || element instanceof PsiMethod && "main".equals(((PsiMethod) element).getName()) &&
PsiMethodUtil.isMainMethod((PsiMethod) element))
{
final AnAction[] actions = ExecutorAction.getActions(0);
return new Info(AllIcons.RunConfigurations.TestState.Run, element1 -> StringUtil.join(ContainerUtil.mapNotNull(actions, action -> getText(action, element1)), "\n"), actions);
}
}
return null;
}
示例5: findMain
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
@Nullable
private static PsiMethod findMain(PsiElement element)
{
PsiMethod method;
while((method = PsiTreeUtil.getParentOfType(element, PsiMethod.class)) != null)
{
if(PsiMethodUtil.isMainMethod(method))
{
return method;
}
else
{
element = method.getParent();
}
}
return null;
}
示例6: createUIComponents
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
private void createUIComponents() {
myMainClass = new LabeledComponent<>();
myMainClass.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, (declaration, place) -> {
if (declaration instanceof PsiClass) {
final PsiClass aClass = (PsiClass) declaration;
if (ConfigurationUtil.MAIN_CLASS.value(aClass) && PsiMethodUtil.findMainMethod(aClass) != null) {
return JavaCodeFragment.VisibilityChecker.Visibility.VISIBLE;
}
}
return JavaCodeFragment.VisibilityChecker.Visibility.NOT_VISIBLE;
}
));
}
示例7: isEntryPoint
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
public boolean isEntryPoint(@NotNull PsiElement element) {
final Project project = element.getProject();
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
if (element instanceof PsiMethod && isAddMainsEnabled() && PsiClassImplUtil.isMainOrPremainMethod((PsiMethod)element)) {
return true;
}
if (element instanceof PsiClass) {
PsiClass aClass = (PsiClass)element;
final PsiClass applet = psiFacade.findClass("java.applet.Applet", GlobalSearchScope.allScope(project));
if (isAddAppletEnabled() && applet != null && aClass.isInheritor(applet, true)) {
return true;
}
final PsiClass servlet = psiFacade.findClass("javax.servlet.Servlet", GlobalSearchScope.allScope(project));
if (isAddServletEnabled() && servlet != null && aClass.isInheritor(servlet, true)) {
return true;
}
if (isAddMainsEnabled() && PsiMethodUtil.hasMainMethod(aClass)) return true;
}
if (element instanceof PsiModifierListOwner) {
final EntryPointsManager entryPointsManager = EntryPointsManager.getInstance(project);
if (entryPointsManager.isEntryPoint(element)) return true;
}
for (EntryPoint extension : myExtensions) {
if (extension.isEntryPoint(element)) {
return true;
}
}
final ImplicitUsageProvider[] implicitUsageProviders = Extensions.getExtensions(ImplicitUsageProvider.EP_NAME);
for (ImplicitUsageProvider provider : implicitUsageProviders) {
if (provider.isImplicitUsage(element)) return true;
}
return false;
}
示例8: checkClass
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
protected boolean checkClass(@NotNull HeaderValuePart valuePart, @NotNull PsiClass aClass, @NotNull AnnotationHolder holder) {
if (!PsiMethodUtil.hasMainMethod(aClass)) {
holder.createErrorAnnotation(valuePart.getHighlightingRange(), ManifestBundle.message("header.main.class.invalid"));
return true;
}
return false;
}
示例9: checkConfiguration
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
JavaParametersUtil.checkAlternativeJRE(this);
final JavaRunConfigurationModule configurationModule = getConfigurationModule();
final PsiClass psiClass = configurationModule.checkModuleAndClassName(MAIN_CLASS_NAME, ExecutionBundle.message("no.main.class.specified.error.text"));
if (!PsiMethodUtil.hasMainMethod(psiClass)) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message("main.method.not.found.in.class.error.message", MAIN_CLASS_NAME));
}
ProgramParametersUtil.checkWorkingDirectoryExist(this, getProject(), configurationModule.getModule());
JavaRunConfigurationExtensionManager.checkConfigurationIsValid(this);
}
示例10: createUIComponents
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
private void createUIComponents() {
myMainClass = new LabeledComponent<EditorTextFieldWithBrowseButton>();
myMainClass.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, new JavaCodeFragment.VisibilityChecker() {
@Override
public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
if (declaration instanceof PsiClass) {
final PsiClass aClass = (PsiClass)declaration;
if (ConfigurationUtil.MAIN_CLASS.value(aClass) && PsiMethodUtil.findMainMethod(aClass) != null || place.getParent() != null && myModuleSelector.findClass(((PsiClass)declaration).getQualifiedName()) != null) {
return Visibility.VISIBLE;
}
}
return Visibility.NOT_VISIBLE;
}
}));
}
示例11: getInfo
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
@Nullable
@Override
public Info getInfo(PsiElement e) {
if (isIdentifier(e)) {
PsiElement element = e.getParent();
if (element instanceof PsiClass && PsiMethodUtil.findMainInClass((PsiClass)element) != null)
return new Info(ApplicationConfigurationType.getInstance().getIcon(), null, ExecutorAction.getActions(0));
if (element instanceof PsiMethod && "main".equals(((PsiMethod)element).getName()) && PsiMethodUtil.isMainMethod((PsiMethod)element))
return new Info(ApplicationConfigurationType.getInstance().getIcon(), null, ExecutorAction.getActions(0));
}
return null;
}
示例12: findMain
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
@Nullable
private static PsiMethod findMain(PsiElement element) {
PsiMethod method;
while ((method = PsiTreeUtil.getParentOfType(element, PsiMethod.class)) != null) {
if (PsiMethodUtil.isMainMethod(method)) return method;
else element = method.getParent();
}
return null;
}
示例13: isAccepted
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
public boolean isAccepted(final PsiClass aClass) {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return PsiMethodUtil.MAIN_CLASS.value(aClass) && PsiMethodUtil.hasMainMethod(aClass);
}
});
}
示例14: visitMethodCallExpression
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
@NonNls final String methodName = methodExpression.getReferenceName();
if (!"exit".equals(methodName) && !"halt".equals(methodName)) {
return;
}
final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiClass.class, PsiLambdaExpression.class);
if (ignoreInMainMethod && PsiMethodUtil.isMainMethod(containingMethod)) {
return;
}
final PsiMethod method = expression.resolveMethod();
if (method == null) {
return;
}
final PsiParameterList parameterList = method.getParameterList();
if (parameterList.getParametersCount() != 1) {
return;
}
final PsiParameter[] parameters = parameterList.getParameters();
final PsiType parameterType = parameters[0].getType();
if (!parameterType.equals(PsiType.INT)) {
return;
}
final PsiClass aClass = method.getContainingClass();
if (aClass == null) {
return;
}
final String className = aClass.getQualifiedName();
if (!"java.lang.System".equals(className) && !"java.lang.Runtime".equals(className)) {
return;
}
registerMethodCallError(expression, "System");
}
示例15: findMainInClass
import com.intellij.psi.util.PsiMethodUtil; //导入依赖的package包/类
@Override
public PsiMethod findMainInClass(PsiClass clazz) {
final PsiMethod[] launches = clazz.findMethodsByName(LAUNCH_MAIN, true);
for (PsiMethod launchMethod : launches) {
if (PsiMethodUtil.isMainMethod(launchMethod)) {
return launchMethod;
}
}
return null;
}