use of com.intellij.psi.PsiPackage in project intellij by bazelbuild.
the class BlazeAndroidProjectPathsTest method mockPsiPackage.
private void mockPsiPackage(Container applicationServices, Container projectServices) {
projectServices.register(PsiManager.class, mock(PsiManager.class));
applicationServices.register(JavaDirectoryService.class, mock(JavaDirectoryService.class));
PsiManager manager = PsiManager.getInstance(project);
PsiDirectory targetPsiDirectory = mock(PsiDirectory.class);
PsiPackage targetPsiPackage = new PsiPackageImpl(manager, "com.google.target");
when(PsiManager.getInstance(project).findDirectory(target)).thenReturn(targetPsiDirectory);
when(JavaDirectoryService.getInstance().getPackage(targetPsiDirectory)).thenReturn(targetPsiPackage);
}
use of com.intellij.psi.PsiPackage in project intellij by bazelbuild.
the class BlazeAndroidProjectPaths method getPackageName.
/**
* The new component wizard uses {@link AndroidSourceSet#getName()} for the default package name
* of the new component. If we can figure it out from the target directory here, then we can pass
* it to the new component wizard.
*/
private static String getPackageName(Project project, VirtualFile targetDirectory) {
PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(targetDirectory);
if (psiDirectory == null) {
return null;
}
PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
if (psiPackage == null) {
return null;
}
return psiPackage.getQualifiedName();
}
use of com.intellij.psi.PsiPackage in project component-runtime by Talend.
the class SuggestionServiceImpl method getFamilyFromPackageInfo.
private String getFamilyFromPackageInfo(final PsiPackage psiPackage, final Module module) {
return of(FilenameIndex.getFilesByName(psiPackage.getProject(), "package-info.java", GlobalSearchScope.moduleScope(module))).map(psiFile -> {
if (!PsiJavaFile.class.cast(psiFile).getPackageName().equals(psiPackage.getQualifiedName())) {
return null;
}
final String[] family = { null };
PsiJavaFile.class.cast(psiFile).accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitAnnotation(final PsiAnnotation annotation) {
super.visitAnnotation(annotation);
if (!COMPONENTS.equals(annotation.getQualifiedName())) {
return;
}
final PsiAnnotationMemberValue familyAttribute = annotation.findAttributeValue("family");
if (familyAttribute == null) {
return;
}
family[0] = removeQuotes(familyAttribute.getText());
}
});
return family[0];
}).filter(Objects::nonNull).findFirst().orElseGet(() -> {
final PsiPackage parent = psiPackage.getParentPackage();
if (parent == null) {
return null;
}
return getFamilyFromPackageInfo(parent, module);
});
}
Aggregations