use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class AbstractAllInPackageConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(JUnitConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
PsiPackage psiPackage = JavaRuntimeConfigurationProducerBase.checkPackage(context.getPsiLocation());
if (psiPackage == null)
return false;
sourceElement.set(psiPackage);
if (!LocationUtil.isJarAttached(context.getLocation(), psiPackage, JUnitUtil.TESTCASE_CLASS, JUnitUtil.TEST5_ANNOTATION))
return false;
final JUnitConfiguration.Data data = configuration.getPersistentData();
data.PACKAGE_NAME = psiPackage.getQualifiedName();
data.TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE;
data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
configuration.setGeneratedName();
return true;
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class JavaClassReferenceCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiElement position = parameters.getPosition();
JavaClassReference reference = findJavaClassReference(position.getContainingFile(), parameters.getOffset());
if (reference == null) {
return;
}
String[] extendClassNames = reference.getExtendClassNames();
PsiElement context = reference.getCompletionContext();
if (extendClassNames != null && context instanceof PsiPackage) {
if (parameters.getCompletionType() == CompletionType.SMART) {
JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
int setStart = set.getRangeInElement().getStartOffset() + set.getElement().getTextRange().getStartOffset();
String fullPrefix = parameters.getPosition().getContainingFile().getText().substring(setStart, parameters.getOffset());
reference.processSubclassVariants((PsiPackage) context, extendClassNames, result.withPrefixMatcher(fullPrefix));
return;
}
result.addLookupAdvertisement("Press " + getActionShortcut(IdeActions.ACTION_SMART_TYPE_COMPLETION) + " to see inheritors of " + StringUtil.join(extendClassNames, ", "));
}
if (parameters.getCompletionType() == CompletionType.SMART) {
return;
}
if (parameters.isExtendedCompletion() || parameters.getCompletionType() == CompletionType.CLASS_NAME) {
JavaClassNameCompletionContributor.addAllClasses(parameters, result);
} else {
LegacyCompletionContributor.completeReference(parameters, result);
}
result.stopHere();
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class TodoPackageNode method getTodoItemCount.
public int getTodoItemCount(PackageElement packageElement) {
int count = 0;
if (getSettings().isFlattenPackages()) {
final PsiPackage aPackage = packageElement.getPackage();
final Module module = packageElement.getModule();
GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(aPackage.getProject());
final PsiDirectory[] directories = aPackage.getDirectories(scope);
for (PsiDirectory directory : directories) {
Iterator<PsiFile> iterator = myBuilder.getFilesUnderDirectory(directory);
while (iterator.hasNext()) {
PsiFile psiFile = iterator.next();
count += getStructure().getTodoItemCount(psiFile);
}
}
} else {
Iterator<PsiFile> iterator = getFiles(packageElement);
while (iterator.hasNext()) {
PsiFile psiFile = iterator.next();
count += getStructure().getTodoItemCount(psiFile);
}
}
return count;
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class TodoPackageNode method update.
@Override
protected void update(PresentationData data) {
super.update(data);
final PackageElement packageElement = getValue();
try {
if (packageElement == null || !packageElement.getPackage().isValid()) {
setValue(null);
return;
}
int fileCount = getFileCount(packageElement);
if (fileCount == 0) {
setValue(null);
return;
}
PsiPackage aPackage = packageElement.getPackage();
String newName;
if (getStructure().areFlattenPackages()) {
newName = aPackage.getQualifiedName();
} else {
newName = myPresentationName != null ? myPresentationName : "";
}
int nameEndOffset = newName.length();
int todoItemCount = getTodoItemCount(packageElement);
newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount);
myHighlightedRegions.clear();
TextAttributes textAttributes = new TextAttributes();
Color newColor = null;
if (CopyPasteManager.getInstance().isCutElement(packageElement)) {
newColor = CopyPasteManager.CUT_COLOR;
}
textAttributes.setForegroundColor(newColor);
myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));
EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
myHighlightedRegions.add(new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
data.setPresentableText(newName);
} catch (IndexNotReadyException e) {
LOG.info(e);
data.setPresentableText("N/A");
}
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class TodoPackageNode method getChildren.
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
ArrayList<AbstractTreeNode> children = new ArrayList<>();
final Project project = getProject();
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final PsiPackage psiPackage = getValue().getPackage();
final Module module = getValue().getModule();
if (!getStructure().getIsFlattenPackages() || psiPackage == null) {
final Iterator<PsiFile> iterator = getFiles(getValue());
while (iterator.hasNext()) {
final PsiFile psiFile = iterator.next();
final Module psiFileModule = projectFileIndex.getModuleForFile(psiFile.getVirtualFile());
//group by module
if (module != null && psiFileModule != null && !module.equals(psiFileModule)) {
continue;
}
// Add files
final PsiDirectory containingDirectory = psiFile.getContainingDirectory();
TodoFileNode todoFileNode = new TodoFileNode(project, psiFile, myBuilder, false);
if (ArrayUtil.find(psiPackage.getDirectories(), containingDirectory) > -1 && !children.contains(todoFileNode)) {
children.add(todoFileNode);
continue;
}
// Add packages
PsiDirectory _dir = psiFile.getContainingDirectory();
while (_dir != null) {
final PsiDirectory parentDirectory = _dir.getParentDirectory();
if (parentDirectory != null) {
PsiPackage _package = JavaDirectoryService.getInstance().getPackage(_dir);
if (_package != null && _package.getParentPackage() != null && psiPackage.equals(_package.getParentPackage())) {
final GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(project);
//compact empty middle packages
_package = TodoJavaTreeHelper.findNonEmptyPackage(_package, module, project, myBuilder, scope);
final String name = _package.getParentPackage().equals(psiPackage) ? //non compacted
null : _package.getQualifiedName().substring(psiPackage.getQualifiedName().length() + 1);
TodoPackageNode todoPackageNode = new TodoPackageNode(project, new PackageElement(module, _package, false), myBuilder, name);
if (!children.contains(todoPackageNode)) {
children.add(todoPackageNode);
break;
}
}
}
_dir = parentDirectory;
}
}
} else {
// flatten packages
final Iterator<PsiFile> iterator = getFiles(getValue());
while (iterator.hasNext()) {
final PsiFile psiFile = iterator.next();
//group by module
final Module psiFileModule = projectFileIndex.getModuleForFile(psiFile.getVirtualFile());
if (module != null && psiFileModule != null && !module.equals(psiFileModule)) {
continue;
}
final PsiDirectory _dir = psiFile.getContainingDirectory();
// Add files
TodoFileNode todoFileNode = new TodoFileNode(getProject(), psiFile, myBuilder, false);
if (ArrayUtil.find(psiPackage.getDirectories(), _dir) > -1 && !children.contains(todoFileNode)) {
children.add(todoFileNode);
continue;
}
}
}
Collections.sort(children, TodoFileDirAndModuleComparator.INSTANCE);
return children;
}
Aggregations