@NotNull private static String findMainClass(VirtualFile gradleHome, VirtualFile script, Project project) { final String userDefined = System.getProperty("gradle.launcher.class"); if (StringUtil.isNotEmpty(userDefined)) { return userDefined; } VirtualFile launcher = gradleHome.findFileByRelativePath("bin/gradle"); if (launcher == null) { launcher = gradleHome.findFileByRelativePath("bin/gradle.bat"); } if (launcher != null) { try { final String text = StringUtil.convertLineSeparators(VfsUtilCore.loadText(launcher)); final Matcher matcher = MAIN_CLASS_NAME_PATTERN.matcher(text); if (matcher.find()) { String candidate = matcher.group(1); if (StringUtil.isNotEmpty(candidate)) { return candidate; } } } catch (IOException ignored) { } } final PsiFile grFile = PsiManager.getInstance(project).findFile(script); if (grFile != null && JavaPsiFacade.getInstance(project) .findClass("org.gradle.BootstrapMain", grFile.getResolveScope()) != null) { return "org.gradle.BootstrapMain"; } return "org.gradle.launcher.GradleMain"; }
@NotNull @Override public PsiElement getNavigationElement() { if (myAntClass != null) { final PsiClass psiClass = JavaPsiFacade.getInstance(getProject()) .findClass(myAntClass.getName(), myPlace.getResolveScope()); if (psiClass != null) { return psiClass; } } return this; }
public AntBuilderMethod( PsiFile place, String name, PsiType closureType, @Nullable Class antClass, final PsiType stringType) { super(place.getManager(), GroovyFileType.GROOVY_LANGUAGE, name); myPlace = place; myAntClass = antClass; setModifiers(PsiModifier.PUBLIC); addParameter("args", new GrMapType(place.getResolveScope())); setBaseIcon(GantIcons.ANT_TASK); addParameter(new GrLightParameter("singleArg", stringType, this).setOptional(true)); addParameter(new GrLightParameter("body", closureType, this).setOptional(true)); setMethodReturnType( new Computable<PsiType>() { @Override public PsiType compute() { return PsiType.getJavaLangObject(getManager(), getResolveScope()); } }); }
@Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { return JavaPsiFacade.getInstance(project) .findClass(CommonClassNames.JAVA_LANG_OBJECT, file.getResolveScope()) == null; }