本文整理汇总了Java中com.intellij.psi.JavaDirectoryService类的典型用法代码示例。如果您正苦于以下问题:Java JavaDirectoryService类的具体用法?Java JavaDirectoryService怎么用?Java JavaDirectoryService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaDirectoryService类属于com.intellij.psi包,在下文中一共展示了JavaDirectoryService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFile
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
@Nullable
@Override
protected SmcFile createFile(String name, String templateName, PsiDirectory dir) {
String aPackageName = getPackageName(dir);
boolean validName = PsiNameHelper.getInstance(dir.getProject()).isQualifiedName(name);
String shortClassName = StringUtils.capitalize(PsiNameHelper.getShortClassName(name));
String smClassName = validName ? shortClassName + STATE_MACHINE_SUFFIX : "";
String smContextClassName = validName ? shortClassName + CONTEXT_SUFFIX : "";
if (validName && !DO_NOT_CREATE_CONTEXT_KIND.equals(templateName)) {
JavaDirectoryService.getInstance().createClass(dir, smContextClassName, templateName, true);
}
String nameWithExtension = name + DOT_EXTENSION;
SmcFile newFile = SmcElementFactory.createNewFile(dir.getProject(), nameWithExtension, aPackageName,
smClassName, smContextClassName);
dir.add(newFile);
return newFile;
}
示例2: create
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
/**
* Create EntityAdapter.class
*/
public static void create() {
PsiDirectory adapterDirectory = createDirectory(getViewPackage(), ADAPTER.toLowerCase());
String className = getEntityConfig().getEntityName() + ADAPTER;
HashMap<String, String> varTemplate = new HashMap<>();
varTemplate.put("PACKAGE_PROJECT", getPackageNameProject(getProjectDirectory()));
varTemplate.put("LAYOUT_NAME", getEntityConfig().getEntityName().toLowerCase());
Runnable runnable = () -> {
JavaDirectoryService.getInstance().createClass(adapterDirectory, className, ADAPTER_TEMPLATE, false, varTemplate);
try {
createLayout(getPackageNameProject(adapterDirectory), className, ADAPTER);
} catch (Exception e) {
e.printStackTrace();
}
};
WriteCommandAction.runWriteCommandAction(getProject(), runnable);
}
示例3: create
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
/**
* Create EntityPresenter.class
*/
public static void create() {
// Create presenter directory
presenterDirectory = createDirectory(getViewPackage(), PRESENTER.toLowerCase());
// Create presenter class
String className = getEntityConfig().getEntityName() + PRESENTER;
HashMap<String, String> varTemplate = new HashMap<>();
varTemplate.put("PACKAGE_PRESENTER_IMPL", getPackageNameProject(Presenter.getPresenterDirectory()));
varTemplate.put("PRESENTER_IMPL", PRESENTER_IMPL);
Runnable runnable = () -> JavaDirectoryService.getInstance().createClass(presenterDirectory, className, PRESENTER_TEMPLATE, false, varTemplate);
WriteCommandAction.runWriteCommandAction(getProject(), runnable);
}
示例4: invoke
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, @Nullable Editor editor, @NotNull PsiFile file) {
if (!FileModificationService.getInstance().prepareFileForWrite(myClass.getContainingFile())) return;
PsiDirectory dir = file.getContainingDirectory();
try{
String name = myClass.getName();
JavaDirectoryService directoryService = JavaDirectoryService.getInstance();
PsiClass placeHolder = myClass.isInterface() ? directoryService.createInterface(dir, name) : directoryService.createClass(dir, name);
PsiClass newClass = (PsiClass)placeHolder.replace(myClass);
myClass.delete();
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, newClass.getContainingFile().getVirtualFile(), newClass.getTextOffset());
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
catch(IncorrectOperationException e){
LOG.error(e);
}
}
示例5: add
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
@Override
public PsiElement add(@NotNull final PsiElement element) throws IncorrectOperationException {
if (element instanceof PsiClass) {
final String name = ((PsiClass)element).getName();
if (name != null) {
final PsiClass newClass = JavaDirectoryService.getInstance().createClass(this, name);
return newClass.replace(element);
}
else {
LOG.error("not implemented");
return null;
}
}
else {
return super.add(element);
}
}
示例6: addSubtreeToUpdateByElement
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
@Override
public boolean addSubtreeToUpdateByElement(Object element) {
// should convert PsiDirectories into PackageElements
if (element instanceof PsiDirectory) {
PsiDirectory dir = (PsiDirectory)element;
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(dir);
if (ProjectView.getInstance(myProject).isShowModules(getId())) {
Module[] modules = getModulesFor(dir);
boolean rv = false;
for (Module module : modules) {
rv |= addPackageElementToUpdate(aPackage, module);
}
return rv;
}
else {
return addPackageElementToUpdate(aPackage, null);
}
}
return super.addSubtreeToUpdateByElement(element);
}
示例7: getNodeName
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
@Nullable
@Override
public String getNodeName(final ViewSettings settings, final Object parentValue, final PsiDirectory directory) {
if (JrtFileSystem.isRoot(directory.getVirtualFile())) {
return LangBundle.message("jrt.node.short");
}
PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
PsiPackage parentPackage;
if (!ProjectRootsUtil.isSourceRoot(directory) && aPackage != null && !aPackage.getQualifiedName().isEmpty() && parentValue instanceof PsiDirectory) {
parentPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory)parentValue));
}
else if (ProjectRootsUtil.isSourceRoot(directory) && aPackage != null) { //package prefix
aPackage = null;
parentPackage = null;
}
else {
parentPackage = null;
}
return PackageUtil.getNodeName(settings, aPackage, parentPackage, directory.getName(), isShowFQName(settings, parentValue, directory));
}
示例8: isEmptyMiddlePackage
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
/**
* a directory is considered "empty" if it has at least one child and all its children are only directories
*
* @param strictlyEmpty if true, the package is considered empty if it has only 1 child and this child is a directory
* otherwise the package is considered as empty if all direct children that it has are directories
*/
public static boolean isEmptyMiddlePackage(@NotNull PsiDirectory dir, boolean strictlyEmpty) {
final VirtualFile[] files = dir.getVirtualFile().getChildren();
if (files.length == 0) {
return false;
}
PsiManager manager = dir.getManager();
int subpackagesCount = 0;
int directoriesCount = 0;
for (VirtualFile file : files) {
if (FileTypeManager.getInstance().isFileIgnored(file)) continue;
if (!file.isDirectory()) return false;
PsiDirectory childDir = manager.findDirectory(file);
if (childDir != null) {
directoriesCount++;
if (strictlyEmpty && directoriesCount > 1) return false;
if (JavaDirectoryService.getInstance().getPackage(childDir) != null) {
subpackagesCount++;
}
}
}
if (strictlyEmpty) {
return directoriesCount == subpackagesCount && directoriesCount == 1;
}
return directoriesCount == subpackagesCount && directoriesCount > 0;
}
示例9: dotest
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
private void dotest(CheckAction checkAction) throws Exception {
final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
final FileEditor fileEditor = fileEditors[0];
try {
final StructureViewComponent structureViewComponent =
(StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
checkAction.testClassStructure(structureViewComponent);
Disposer.dispose(structureViewComponent);
}
finally {
fileEditorManager.closeFile(virtualFile);
}
}
示例10: isAvailable
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
private static boolean isAvailable(DataContext dataContext) {
final Module module = LangDataKeys.MODULE.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (module == null ||
view == null ||
view.getDirectories().length == 0) {
return false;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null || facet.isGradleProject()) {
return false;
}
final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
for (PsiDirectory dir : view.getDirectories()) {
if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
dirService.getPackage(dir) != null) {
return true;
}
}
return false;
}
示例11: isAvailable
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
protected static boolean isAvailable(DataContext dataContext) {
final Module module = LangDataKeys.MODULE.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (module == null ||
view == null ||
view.getDirectories().length == 0 ||
AndroidFacet.getInstance(module) == null) {
return false;
}
final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
for (PsiDirectory dir : view.getDirectories()) {
if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
dirService.getPackage(dir) != null &&
!dirService.getPackage(dir).getQualifiedName().isEmpty()) {
return true;
}
}
return false;
}
示例12: update
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
public void update(final AnActionEvent e) {
super.update(e);
final Project project = e.getData(CommonDataKeys.PROJECT);
final Presentation presentation = e.getPresentation();
if (presentation.isEnabled()) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
if (view != null) {
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final PsiDirectory[] dirs = view.getDirectories();
for (final PsiDirectory dir : dirs) {
if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
return;
}
}
}
presentation.setEnabled(false);
presentation.setVisible(false);
}
}
示例13: buildDialog
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
@Override
protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) {
builder
.setTitle(GroovyBundle.message("newclass.dlg.title"))
.addKind("Class", JetgroovyIcons.Groovy.Class, GroovyTemplates.GROOVY_CLASS)
.addKind("Interface", JetgroovyIcons.Groovy.Interface, GroovyTemplates.GROOVY_INTERFACE);
if (GroovyConfigUtils.getInstance().isVersionAtLeast(directory, GroovyConfigUtils.GROOVY2_3, true)) {
builder.addKind("Trait", JetgroovyIcons.Groovy.Trait, GroovyTemplates.GROOVY_TRAIT);
}
builder
.addKind("Enum", JetgroovyIcons.Groovy.Enum, GroovyTemplates.GROOVY_ENUM)
.addKind("Annotation", JetgroovyIcons.Groovy.AnnotationType, GroovyTemplates.GROOVY_ANNOTATION);
for (FileTemplate template : FileTemplateManager.getInstance(project).getAllTemplates()) {
FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension());
if (fileType.equals(GroovyFileType.GROOVY_FILE_TYPE) && JavaDirectoryService.getInstance().getPackage(directory) != null) {
builder.addKind(template.getName(), JetgroovyIcons.Groovy.Class, template.getName());
}
}
}
示例14: configure
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
@Override
public void configure(JUnitConfiguration jUnitConfiguration, PitestConfiguration configuration) {
JUnitConfiguration.Data data = jUnitConfiguration.getPersistentData();
String targetTests = "";
String targetClasses = "";
String dirName = data.getDirName();
VirtualFile dir = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(dirName));
if (dir != null) {
PsiDirectory directory = PsiManager.getInstance(jUnitConfiguration.getProject()).findDirectory(dir);
if (directory != null) {
PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(directory);
if (psiPackage != null) {
String packageName = psiPackage.getQualifiedName();
targetTests = isEmpty(packageName) ? "" : packageName + ANY_IN_PACKAGE_PATTERN;
targetClasses = targetTests;
}
}
}
configure(configuration, targetTests, targetClasses);
}
示例15: getSubpackages
import com.intellij.psi.JavaDirectoryService; //导入依赖的package包/类
@NotNull
public static PsiPackage[] getSubpackages(@NotNull PsiPackage aPackage,
@Nullable Module module,
@NotNull Project project,
final boolean searchInLibraries) {
final PsiDirectory[] dirs = getDirectories(aPackage, project, module, searchInLibraries);
final Set<PsiPackage> subpackages = new HashSet<PsiPackage>();
for (PsiDirectory dir : dirs) {
final PsiDirectory[] subdirectories = dir.getSubdirectories();
for (PsiDirectory subdirectory : subdirectories) {
final PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(subdirectory);
if (psiPackage != null) {
final String name = psiPackage.getName();
// skip "default" subpackages as they should be attributed to other modules
// this is the case when contents of one module is nested into contents of another
if (name != null && !name.isEmpty()) {
subpackages.add(psiPackage);
}
}
}
}
return subpackages.toArray(new PsiPackage[subpackages.size()]);
}