From 8577c8d0538d24d8b88a157421dcc73e718203c8 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Wed, 18 May 2016 19:53:29 +0200 Subject: [PATCH] javafx entry point for unused declaration (IDEA-156062 ) --- .../src/META-INF/common-javaFX-plugin.xml | 1 + .../plugins/javaFX/JavaFxEntryPoint.java | 88 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxEntryPoint.java diff --git a/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml b/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml index edc0b3a82eba..f67860f14a8d 100644 --- a/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml +++ b/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml @@ -60,6 +60,7 @@ + diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxEntryPoint.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxEntryPoint.java new file mode 100644 index 000000000000..018e3db2c9bd --- /dev/null +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxEntryPoint.java @@ -0,0 +1,88 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.plugins.javaFX; + +import com.intellij.codeInspection.reference.EntryPoint; +import com.intellij.codeInspection.reference.RefElement; +import com.intellij.execution.junit.JUnitUtil; +import com.intellij.openapi.util.DefaultJDOMExternalizer; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.WriteExternalException; +import com.intellij.psi.*; +import com.intellij.psi.search.searches.ClassInheritorsSearch; +import com.intellij.psi.util.InheritanceUtil; +import com.intellij.psi.util.PsiClassUtil; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.ArrayUtil; +import com.intellij.util.CommonProcessors; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.javaFX.fxml.JavaFxCommonNames; + +public class JavaFxEntryPoint extends EntryPoint { + public boolean ADD_JAVAFX_TO_ENTRIES = true; + + @NotNull + public String getDisplayName() { + return "JavaFX Applications"; + } + + public boolean isEntryPoint(@NotNull RefElement refElement, @NotNull PsiElement psiElement) { + return isEntryPoint(psiElement); + } + + @Override + public boolean isEntryPoint(@NotNull PsiElement psiElement) { + if (ADD_JAVAFX_TO_ENTRIES) { + if (psiElement instanceof PsiMethod) { + final PsiMethod method = (PsiMethod)psiElement; + if (method.getParameterList().getParameters().length == 1 && + PsiType.VOID.equals(method.getReturnType()) && + "start".equals(method.getName())) { + return InheritanceUtil.isInheritor(method.getContainingClass(), true, JavaFxCommonNames.JAVAFX_APPLICATION_APPLICATION); + } + } + else if (psiElement instanceof PsiClass) { + return InheritanceUtil.isInheritor((PsiClass)psiElement, true, JavaFxCommonNames.JAVAFX_APPLICATION_APPLICATION); + } + } + return false; + } + + public boolean isSelected() { + return ADD_JAVAFX_TO_ENTRIES; + } + + public void setSelected(boolean selected) { + ADD_JAVAFX_TO_ENTRIES = selected; + } + + public void readExternal(Element element) throws InvalidDataException { + DefaultJDOMExternalizer.readExternal(this, element); + } + + public void writeExternal(Element element) throws WriteExternalException { + if (!ADD_JAVAFX_TO_ENTRIES) { + DefaultJDOMExternalizer.writeExternal(this, element); + } + } + + @Override + public String[] getIgnoreAnnotations() { + return ArrayUtil.EMPTY_STRING_ARRAY; + } +} \ No newline at end of file