本文整理汇总了Java中com.intellij.psi.PsiPackage类的典型用法代码示例。如果您正苦于以下问题:Java PsiPackage类的具体用法?Java PsiPackage怎么用?Java PsiPackage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiPackage类属于com.intellij.psi包,在下文中一共展示了PsiPackage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOrCreatePackageInfoFile
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
@Nullable
private PsiJavaFile getOrCreatePackageInfoFile(PsiFile file) {
if (!(file instanceof PsiJavaFile)) {
return null;
}
PsiPackageStatement packageStatement = ((PsiJavaFile) file).getPackageStatement();
if (packageStatement == null) {
return null;
}
PsiJavaCodeReferenceElement packageReference = packageStatement.getPackageReference();
PsiElement target = packageReference.resolve();
if (!(target instanceof PsiPackage)) {
return null;
}
PsiJavaFile packageInfoFile = packageInfoFile((PsiPackage) target, file.getContainingDirectory());
if (packageInfoFile == null) {
packageInfoFile = createPackageInfoFile(file, (PsiPackage) target);
}
return packageInfoFile;
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:25,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java
示例2: run
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
@Override
protected void run(@NotNull Result<PsiFile> result) throws Throwable {
final PsiPackage packageElement = directoryService.getPackage(directory);
if (packageElement == null) {
throw new InvalidDirectoryException("Target directory does not provide a package");
}
final String fileName = Extensions.append(name, StdFileTypes.JAVA);
final PsiFile found = directory.findFile(fileName);
if (found != null) {
throw new ClassAlreadyExistsException("Class '" + name + "'already exists in " + packageElement.getName());
}
final String packageName = packageElement.getQualifiedName();
final String className = Extensions.remove(this.name, StdFileTypes.JAVA);
try {
final String java = converter.convert(packageName, className, json);
final PsiFile classFile = fileFactory.createFileFromText(fileName, JavaFileType.INSTANCE, java);
CodeStyleManager.getInstance(classFile.getProject()).reformat(classFile);
JavaCodeStyleManager.getInstance(classFile.getProject()).optimizeImports(classFile);
final PsiFile created = (PsiFile) directory.add(classFile);
result.setResult(created);
} catch (IOException e) {
throw new ClassCreationException("Failed to create new class from JSON", e);
}
}
示例3: findResourceBundle
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
private Optional<PropertiesFile> findResourceBundle(Project project, PsiClass configClass) {
String qualifiedName = configClass.getQualifiedName();
if (qualifiedName != null) {
int lastDotIndex = qualifiedName.lastIndexOf(".");
String packageName = qualifiedName.substring(0, lastDotIndex);
String className = qualifiedName.substring(lastDotIndex + 1);
PsiPackage psiPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
if (psiPackage != null) {
return Arrays.stream(psiPackage.getFiles(GlobalSearchScope.allScope(project)))
.filter(psiFile -> psiFile instanceof PropertiesFile && psiFile.getVirtualFile().getNameWithoutExtension().equals(className))
.map(psiFile -> (PropertiesFile) psiFile)
.findFirst();
}
}
return Optional.empty();
}
示例4: processPackageDirectories
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
@Override
public boolean processPackageDirectories(@NotNull PsiPackage psiPackage,
@NotNull final GlobalSearchScope scope,
@NotNull final Processor<PsiDirectory> consumer,
boolean includeLibrarySources) {
//System.out.println( "processDirectories() : " + psiPackage + " : " + scope );
final PsiManager psiManager = PsiManager.getInstance( _project );
return PackageIndex.getInstance( _project )
.getDirsByPackageName(psiPackage.getQualifiedName(), includeLibrarySources)
.forEach(new ReadActionProcessor<VirtualFile>() {
@Override
public boolean processInReadAction(final VirtualFile dir) {
if (!scope.contains(dir)) return true;
PsiDirectory psiDir = psiManager.findDirectory(dir);
return psiDir == null || consumer.process(psiDir);
}
});
}
示例5: findPackage
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
@Override
public PsiPackage findPackage( String fqn )
{
//System.out.println( "findPackage() : " + fqn );
List<ManModule> modules = ManProject.manProjectFrom( _project ).getModules();
PsiManager manager = PsiManagerImpl.getInstance( _project );
for( ManModule mm : modules )
{
for( ITypeManifold sp : mm.getTypeManifolds() )
{
if( sp.getProducerKind() != Supplemental && sp.isPackage( fqn ) )
{
return new NonDirectoryPackage( manager, fqn );
}
}
}
return null;
}
示例6: getClasses
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
@NotNull
@Override
public PsiClass[] getClasses(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
String fqn = psiPackage.getQualifiedName();
if (isShortCircuit(fqn)) {
return PsiClass.EMPTY_ARRAY;
}
addShortCircuit(fqn);
try {
PsiClass[] classes = psiPackage.getClasses(scope);
return Arrays.stream(classes).map(LightClass::new).toArray(PsiClass[]::new);
} finally {
removeShortCircuit(fqn);
}
}
示例7: getPresentation
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
@Override
public ItemPresentation getPresentation(@NotNull final PsiPackage aPackage) {
return new ColoredItemPresentation() {
@Override
public TextAttributesKey getTextAttributesKey() {
return null;
}
@Override
public String getPresentableText() {
return aPackage.getName();
}
@Override
public String getLocationString() {
return aPackage.getQualifiedName();
}
@Override
public Icon getIcon(boolean open) {
return PlatformIcons.PACKAGE_ICON;
}
};
}
示例8: actionPerformed
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
@Override
public void actionPerformed(final AnActionEvent e) {
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
PackageChooserDialog chooser = new PackageChooserDialog("Choose packages", project);
chooser.show();
final List<PsiPackage> packages = chooser.getSelectedPackages();
for (PsiPackage aPackage : packages) {
final String qualifiedName = aPackage.getQualifiedName();
if (qualifiedName.isEmpty()){
myDataModel.addElement(GroovyDocConfiguration.ALL_PACKAGES);
}
myDataModel.addElement(qualifiedName);
}
}
示例9: setupConfigurationFromContext
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
@Override
protected boolean setupConfigurationFromContext(TestNGConfiguration configuration,
ConfigurationContext context,
Ref<PsiElement> sourceElement) {
final PsiElement element = context.getPsiLocation();
PsiPackage aPackage = JavaRuntimeConfigurationProducerBase.checkPackage(element);
if (aPackage == null) {
return false;
}
final Location location = context.getLocation();
if (location == null) {
return false;
}
if (!LocationUtil.isJarAttached(location, aPackage, TestNGUtil.TEST_ANNOTATION_FQN)) {
return false;
}
final TestData data = configuration.data;
data.PACKAGE_NAME = aPackage.getQualifiedName();
data.TEST_OBJECT = TestType.PACKAGE.getType();
data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
configuration.setGeneratedName();
sourceElement.set(aPackage);
return true;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:AbstractTestNGPackageConfigurationProducer.java
示例10: isConfigurationFromContext
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
@Override
public boolean isConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context) {
if (configuration == null) return false;
if (!GradleConstants.SYSTEM_ID.equals(configuration.getSettings().getExternalSystemId())) return false;
final PsiPackage psiPackage = JavaRuntimeConfigurationProducerBase.checkPackage(context.getPsiLocation());
if (psiPackage == null) return false;
if (context.getModule() == null) return false;
if (!StringUtil.equals(
context.getModule().getOptionValue(ExternalSystemConstants.LINKED_PROJECT_PATH_KEY),
configuration.getSettings().getExternalProjectPath())) {
return false;
}
if (!configuration.getSettings().getTaskNames().containsAll(TASKS_TO_RUN)) return false;
final String scriptParameters = configuration.getSettings().getScriptParameters() + ' ';
return psiPackage.getQualifiedName().isEmpty()
? scriptParameters.contains("--tests * ")
: scriptParameters.contains(String.format("--tests %s.* ", psiPackage.getQualifiedName()));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AllInPackageGradleConfigurationProducer.java
示例11: checkResult
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
private static void checkResult(HashMap<String, String[][]> expected, HashMap<PsiPackage, Set<List<PsiPackage>>> cycles, boolean forceContains){
assertEquals(expected.size(), cycles.size());
for (final PsiPackage psiPackage : cycles.keySet()) {
assertTrue(expected.containsKey(psiPackage.getQualifiedName()));
final String packs = psiPackage.getQualifiedName();
if (forceContains) {
assertEquals(expected.get(packs).length, cycles.get(psiPackage).size());
}
for (final List<PsiPackage> cycle : cycles.get(psiPackage)) {
final String[][] expectedCycles = expected.get(packs);
final String[] string = new String[cycle.size()];
int i = 0;
for (final PsiPackage packageInCycle : cycle) {
string[i++] = packageInCycle.getQualifiedName();
}
assertTrue(findInMatrix(expectedCycles, string) > -1);
}
}
}
示例12: testBackwardPackageScope
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
public void testBackwardPackageScope(){
final PsiPackage bPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage("com.a");
final DependenciesBuilder builder = new BackwardDependenciesBuilder(myProject, new JavaAnalysisScope(bPackage, null));
builder.analyze();
final Set<PsiFile> searchFor = new HashSet<PsiFile>();
searchFor.add(myJavaFacade.findClass("com.a.A", GlobalSearchScope.allScope(myProject)).getContainingFile());
final Set<PsiFile> searchIn = new HashSet<PsiFile>();
final PsiClass bClass = myJavaFacade.findClass("com.b.B", GlobalSearchScope.allScope(myProject));
searchIn.add(bClass.getContainingFile());
final PsiClass cClass = myJavaFacade.findClass("com.a.C", GlobalSearchScope.allScope(myProject));
searchFor.add(cClass.getContainingFile());
final UsageInfo[] usagesInfos = FindDependencyUtil.findBackwardDependencies(builder, searchIn, searchFor);
final UsageInfo2UsageAdapter[] usages = UsageInfo2UsageAdapter.convert(usagesInfos);
final String [] psiUsages = new String [usagesInfos.length];
for (int i = 0; i < usagesInfos.length; i++) {
psiUsages[i] = toString(usages[i]);
}
checkResult(new String []{"(4: 3) A myA = new A();", "(4: 15) A myA = new A();", "(5: 3) C myC = new C();", "(5: 15) C myC = new C();", "(7: 9) myA.aa();", "(8: 9) myC.cc();"}, psiUsages);
}
示例13: spansMultipleModules
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
private boolean spansMultipleModules() {
final String qualifiedName = getConfiguration().getPackage();
if (qualifiedName != null) {
final Project project = getConfiguration().getProject();
final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(qualifiedName);
if (aPackage != null) {
final TestSearchScope scope = getScope();
if (scope != null) {
final SourceScope sourceScope = scope.getSourceScope(getConfiguration());
if (sourceScope != null) {
final GlobalSearchScope configurationSearchScope = GlobalSearchScopesCore.projectTestScope(project).intersectWith(
sourceScope.getGlobalSearchScope());
final PsiDirectory[] directories = aPackage.getDirectories(configurationSearchScope);
return directories.length > 1;
}
}
}
}
return false;
}
示例14: testReusingConfiguration
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
public void testReusingConfiguration() {
RunManagerEx runManager = RunManagerEx.getInstanceEx(myProject);
PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
PsiPackage psiPackage = JUnitUtil.getContainingPackage(psiClass);
ConfigurationContext context = createContext(psiClass);
assertEquals(null, context.findExisting());
RunnerAndConfigurationSettings testClass = context.getConfiguration();
runManager.addConfiguration(testClass, false);
context = createContext(psiClass);
assertSame(testClass, context.findExisting());
runManager.setSelectedConfiguration(testClass);
context = createContext(psiPackage);
assertEquals(null, context.findExisting());
RunnerAndConfigurationSettings testPackage = context.getConfiguration();
runManager.addConfiguration(testPackage, false);
context = createContext(psiPackage);
assertSame(testPackage, context.findExisting());
assertSame(testClass, runManager.getSelectedConfiguration());
runManager.setSelectedConfiguration(context.findExisting());
assertSame(testPackage, runManager.getSelectedConfiguration());
}
示例15: updateLeftTreeModel
import com.intellij.psi.PsiPackage; //导入依赖的package包/类
private void updateLeftTreeModel() {
final Set<PsiPackage> psiPackages = myDependencies.keySet();
final Set<PsiFile> psiFiles = new HashSet<PsiFile>();
for (PsiPackage psiPackage : psiPackages) {
final Set<List<PsiPackage>> cycles = myDependencies.get(psiPackage);
if (!mySettings.UI_FILTER_OUT_OF_CYCLE_PACKAGES || cycles != null && !cycles.isEmpty()) {
psiFiles.addAll(getPackageFiles(psiPackage));
}
}
boolean showFiles = mySettings.UI_SHOW_FILES; //do not show files in the left tree
mySettings.UI_FLATTEN_PACKAGES = true;
mySettings.UI_SHOW_FILES = false;
myLeftTreeExpansionMonitor.freeze();
myLeftTree.setModel(TreeModelBuilder.createTreeModel(myProject, false, psiFiles, new Marker() {
public boolean isMarked(VirtualFile file) {
return false;
}
}, mySettings));
myLeftTreeExpansionMonitor.restore();
expandFirstLevel(myLeftTree);
mySettings.UI_SHOW_FILES = showFiles;
mySettings.UI_FLATTEN_PACKAGES = false;
}