use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class CreatePackageInfoAction method isAvailable.
private static boolean isAvailable(DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (project == null || view == null) {
return false;
}
final PsiDirectory[] directories = view.getDirectories();
if (directories.length == 0) {
return false;
}
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final JavaDirectoryService directoryService = JavaDirectoryService.getInstance();
final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
for (PsiDirectory directory : directories) {
if (projectFileIndex.isUnderSourceRootOfType(directory.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && PsiUtil.isLanguageLevel5OrHigher(directory)) {
final PsiPackage aPackage = directoryService.getPackage(directory);
if (aPackage != null) {
final String qualifiedName = aPackage.getQualifiedName();
if (StringUtil.isEmpty(qualifiedName) || nameHelper.isQualifiedName(qualifiedName)) {
return true;
}
}
}
}
return false;
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class AllInPackageGradleConfigurationProducer method doSetupConfigurationFromContext.
@Override
protected boolean doSetupConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
final PsiPackage psiPackage = JavaRuntimeConfigurationProducerBase.checkPackage(context.getPsiLocation());
if (psiPackage == null)
return false;
sourceElement.set(psiPackage);
final Module module = context.getModule();
if (module == null)
return false;
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
return false;
final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (projectPath == null)
return false;
List<String> tasksToRun = getTasksToRun(module);
if (tasksToRun.isEmpty())
return false;
configuration.getSettings().setExternalProjectPath(projectPath);
configuration.getSettings().setTaskNames(tasksToRun);
if (psiPackage.getQualifiedName().isEmpty()) {
configuration.getSettings().setScriptParameters("--tests *");
} else {
configuration.getSettings().setScriptParameters(String.format("--tests %s.*", psiPackage.getQualifiedName()));
}
configuration.setName(suggestName(psiPackage, module));
return true;
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class MvcTargetDialogCompletionUtils method collectClassesAndPackageNames.
private static void collectClassesAndPackageNames(Collection<LookupElement> res, @NotNull PsiPackage aPackage, GlobalSearchScope scope) {
PsiPackage[] subPackages = aPackage.getSubPackages(scope);
String qualifiedName = aPackage.getQualifiedName();
if (!qualifiedName.isEmpty()) {
if (subPackages.length == 0 || aPackage.getClasses(scope).length > 0) {
res.add(TailTypeDecorator.withTail(LookupElementBuilder.create(qualifiedName), TailType.DOT));
}
}
for (PsiPackage subPackage : subPackages) {
collectClassesAndPackageNames(res, subPackage, scope);
}
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class CoverageJavaRunConfigurationExtension method wrapElementListener.
@Override
public RefactoringElementListener wrapElementListener(PsiElement element, RunConfigurationBase configuration, RefactoringElementListener listener) {
if (!isApplicableFor(configuration)) {
return listener;
}
final JavaCoverageEnabledConfiguration coverageEnabledConfiguration = JavaCoverageEnabledConfiguration.getFrom(configuration);
if (coverageEnabledConfiguration != null) {
final Project project = configuration.getProject();
final ClassFilter[] patterns = coverageEnabledConfiguration.getCoveragePatterns();
final String[] filters = getFilters(coverageEnabledConfiguration);
if (patterns != null) {
assert filters != null;
if (element instanceof PsiClass) {
final String qualifiedName = ((PsiClass) element).getQualifiedName();
final int idx = ArrayUtil.find(filters, qualifiedName);
if (idx > -1) {
final RefactoringListeners.Accessor<PsiClass> accessor = new MyClassAccessor(project, patterns, idx, filters);
final RefactoringElementListener classListener = RefactoringListeners.getClassOrPackageListener(element, accessor);
if (classListener != null) {
listener = appendListener(listener, classListener);
}
} else if (qualifiedName != null) {
final String packageName = StringUtil.getPackageName(qualifiedName);
if (!StringUtil.isEmpty(packageName)) {
for (int i = 0; i < filters.length; i++) {
String filter = filters[i];
if (filter.equals(packageName + ".*")) {
listener = appendListener(listener, new RefactoringListeners.RefactorPackageByClass(new MyClassAccessor(project, patterns, i, filters)));
break;
}
}
}
}
} else if (element instanceof PsiPackage) {
final String qualifiedName = ((PsiPackage) element).getQualifiedName();
for (int i = 0, filtersLength = filters.length; i < filtersLength; i++) {
if (filters[i].startsWith(qualifiedName + ".")) {
final RefactoringElementListener packageListener;
if (filters[i].endsWith("*")) {
packageListener = RefactoringListeners.getListener((PsiPackage) element, new MyPackageAccessor(project, patterns, i, filters));
} else {
packageListener = RefactoringListeners.getClassOrPackageListener(element, new MyClassAccessor(project, patterns, i, filters));
}
if (packageListener != null) {
listener = appendListener(listener, packageListener);
}
}
}
}
}
}
return listener;
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class CoverageIntegrationTest method testSimple.
public void testSimple() {
CoverageSuitesBundle bundle = loadCoverageSuite(IDEACoverageRunner.class, "simple$foo_in_simple.coverage");
PsiPackage psiPackage = JavaPsiFacade.getInstance(myProject).findPackage("foo");
PackageAnnotator annotator = new PackageAnnotator(psiPackage);
PackageAnnotationConsumer consumer = new PackageAnnotationConsumer();
annotator.annotate(bundle, consumer);
PackageAnnotator.ClassCoverageInfo barClassCoverage = consumer.myClassCoverageInfo.get("foo.bar.BarClass");
assertEquals(3, barClassCoverage.totalMethodCount);
assertEquals(1, barClassCoverage.coveredMethodCount);
PackageAnnotator.PackageCoverageInfo barPackageCoverage = consumer.myPackageCoverage.get("foo.bar");
assertEquals(2, barPackageCoverage.coveredLineCount);
assertEquals(9, barPackageCoverage.totalLineCount);
assertEquals(1, barPackageCoverage.coveredMethodCount);
assertEquals(7, barPackageCoverage.totalMethodCount);
PackageAnnotator.ClassCoverageInfo uncoveredClassInfo = consumer.myClassCoverageInfo.get("foo.bar.UncoveredClass");
assertEquals(4, uncoveredClassInfo.totalMethodCount);
assertEquals(0, uncoveredClassInfo.coveredMethodCount);
}
Aggregations