mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
IDEA-122129 agentmain method is highlighted as unused
This commit is contained in:
@@ -65,6 +65,8 @@ public abstract class RefJavaManager implements RefManagerExtension<RefJavaManag
|
||||
|
||||
public abstract PsiMethod getAppPremainPattern();
|
||||
|
||||
public abstract PsiMethod getAppAgentmainPattern();
|
||||
|
||||
public abstract PsiClass getApplet();
|
||||
|
||||
public abstract PsiClass getServlet();
|
||||
|
||||
@@ -157,7 +157,10 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
|
||||
if (MethodSignatureUtil.areSignaturesEqual(psiMethod, appMainPattern)) return true;
|
||||
|
||||
PsiMethod appPremainPattern = ((RefMethodImpl)refMethod).getRefJavaManager().getAppPremainPattern();
|
||||
return MethodSignatureUtil.areSignaturesEqual(psiMethod, appPremainPattern);
|
||||
if (MethodSignatureUtil.areSignaturesEqual(psiMethod, appPremainPattern)) return true;
|
||||
|
||||
PsiMethod appAgentmainPattern = ((RefMethodImpl)refMethod).getRefJavaManager().getAppAgentmainPattern();
|
||||
return MethodSignatureUtil.areSignaturesEqual(psiMethod, appAgentmainPattern);
|
||||
}
|
||||
|
||||
private void checkForSuperCall(PsiMethod method) {
|
||||
|
||||
@@ -43,6 +43,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
|
||||
private static final Logger LOG = Logger.getInstance("#" + RefJavaManagerImpl.class.getName());
|
||||
private PsiMethod myAppMainPattern;
|
||||
private PsiMethod myAppPremainPattern;
|
||||
private PsiMethod myAppAgentmainPattern;
|
||||
private PsiClass myApplet;
|
||||
private PsiClass myServlet;
|
||||
private RefPackage myDefaultPackage;
|
||||
@@ -59,6 +60,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
|
||||
try {
|
||||
myAppMainPattern = factory.createMethodFromText("void main(String[] args);", null);
|
||||
myAppPremainPattern = factory.createMethodFromText("void premain(String[] args, java.lang.instrument.Instrumentation i);", null);
|
||||
myAppAgentmainPattern = factory.createMethodFromText("void agentmain(String[] args, java.lang.instrument.Instrumentation i);", null);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
@@ -140,6 +142,11 @@ public class RefJavaManagerImpl extends RefJavaManager {
|
||||
return myAppPremainPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiMethod getAppAgentmainPattern() {
|
||||
return myAppAgentmainPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiClass getApplet() {
|
||||
return myApplet;
|
||||
@@ -194,6 +201,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
|
||||
myApplet = null;
|
||||
myAppMainPattern = null;
|
||||
myAppPremainPattern = null;
|
||||
myAppAgentmainPattern = null;
|
||||
myServlet = null;
|
||||
myDefaultPackage = null;
|
||||
myProjectIterator = null;
|
||||
|
||||
@@ -385,7 +385,7 @@ public class PsiClassImplUtil {
|
||||
public static boolean isMainOrPremainMethod(@NotNull PsiMethod method) {
|
||||
if (!PsiType.VOID.equals(method.getReturnType())) return false;
|
||||
String name = method.getName();
|
||||
if (!("main".equals(name) || "premain".equals(name))) return false;
|
||||
if (!("main".equals(name) || "premain".equals(name) || !"agentmain".equals(name))) return false;
|
||||
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
|
||||
MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY);
|
||||
@@ -394,6 +394,8 @@ public class PsiClassImplUtil {
|
||||
if (MethodSignatureUtil.areSignaturesEqual(signature, main)) return true;
|
||||
MethodSignature premain = createSignatureFromText(factory, "void premain(String args, java.lang.instrument.Instrumentation i);");
|
||||
if (MethodSignatureUtil.areSignaturesEqual(signature, premain)) return true;
|
||||
MethodSignature agentmain = createSignatureFromText(factory, "void agentmain(String args, java.lang.instrument.Instrumentation i);");
|
||||
if (MethodSignatureUtil.areSignaturesEqual(signature, agentmain)) return true;
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package java.lang.instrument;
|
||||
|
||||
class Instrumentation {}
|
||||
|
||||
class Foo {
|
||||
|
||||
public void agentmain(String args, Instrumentation i) {
|
||||
System.out.println(args);
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
@@ -62,4 +62,7 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testUnhandledExceptionsValueOf() { doTest(true, false); }
|
||||
public void testUnsupportedFeatures7() { doTest(false, false); }
|
||||
public void testEnumInitializers() { doTest(false, false); }
|
||||
public void testAgentPremain() {
|
||||
doTest(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user