Search in sources :

Example 81 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.

the class ChangeUtil method prepareAndRunChangeAction.

public static void prepareAndRunChangeAction(final ChangeAction action, final TreeElement changedElement) {
    final FileElement changedFile = TreeUtil.getFileElement(changedElement);
    final PsiManager manager = changedFile.getManager();
    final PomModel model = PomManager.getModel(manager.getProject());
    final TreeAspect treeAspect = model.getModelAspect(TreeAspect.class);
    model.runTransaction(new PomTransactionBase(changedElement.getPsi(), treeAspect) {

        @Override
        public PomModelEvent runInner() {
            final PomModelEvent event = new PomModelEvent(model);
            final TreeChangeEvent destinationTreeChange = new TreeChangeEventImpl(treeAspect, changedFile);
            event.registerChangeSet(treeAspect, destinationTreeChange);
            action.makeChange(destinationTreeChange);
            changedElement.clearCaches();
            if (changedElement instanceof CompositeElement) {
                ((CompositeElement) changedElement).subtreeChanged();
            }
            return event;
        }
    });
}
Also used : TreeAspect(com.intellij.pom.tree.TreeAspect) TreeChangeEvent(com.intellij.pom.tree.events.TreeChangeEvent) TreeChangeEventImpl(com.intellij.pom.tree.events.impl.TreeChangeEventImpl) PsiManager(com.intellij.psi.PsiManager) PomModel(com.intellij.pom.PomModel) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PomModelEvent(com.intellij.pom.event.PomModelEvent)

Example 82 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.

the class GenericsHighlightingTest method testLeastUpperBoundWithRecursiveTypes.

public void testLeastUpperBoundWithRecursiveTypes() throws Exception {
    final PsiManager manager = getPsiManager();
    final GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
    final PsiType leastUpperBound = GenericsUtil.getLeastUpperBound(PsiType.INT.getBoxedType(manager, scope), PsiType.LONG.getBoxedType(manager, scope), manager);
    assertNotNull(leastUpperBound);
    assertEquals("Number & Comparable<? extends Number & Comparable<?>>", leastUpperBound.getPresentableText());
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiManager(com.intellij.psi.PsiManager) PsiType(com.intellij.psi.PsiType)

Example 83 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.

the class FilenameIndex method processFilesByName.

public static boolean processFilesByName(@NotNull final String name, boolean includeDirs, boolean caseSensitively, @NotNull Processor<? super PsiFileSystemItem> processor, @NotNull final GlobalSearchScope scope, @NotNull final Project project, @Nullable IdFilter idFilter) {
    final Collection<VirtualFile> files;
    if (caseSensitively) {
        files = getService().getVirtualFilesByName(project, name, scope, idFilter);
    } else {
        files = getVirtualFilesByNameIgnoringCase(name, scope, project, idFilter);
    }
    if (files.isEmpty())
        return false;
    PsiManager psiManager = PsiManager.getInstance(project);
    int processedFiles = 0;
    for (VirtualFile file : files) {
        if (!file.isValid())
            continue;
        if (!includeDirs && !file.isDirectory()) {
            PsiFile psiFile = psiManager.findFile(file);
            if (psiFile != null) {
                if (!processor.process(psiFile))
                    return true;
                ++processedFiles;
            }
        } else if (includeDirs && file.isDirectory()) {
            PsiDirectory dir = psiManager.findDirectory(file);
            if (dir != null) {
                if (!processor.process(dir))
                    return true;
                ++processedFiles;
            }
        }
    }
    return processedFiles > 0;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile)

Example 84 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.

the class IntroduceParameterUtil method processUsages.

public static void processUsages(UsageInfo[] usages, IntroduceParameterData data) {
    PsiManager manager = PsiManager.getInstance(data.getProject());
    List<UsageInfo> methodUsages = new ArrayList<>();
    for (UsageInfo usage : usages) {
        if (usage instanceof InternalUsageInfo)
            continue;
        if (usage instanceof DefaultConstructorImplicitUsageInfo) {
            addSuperCall(usage, usages, data);
        } else if (usage instanceof NoConstructorClassUsageInfo) {
            addDefaultConstructor(usage, usages, data);
        } else {
            PsiElement element = usage.getElement();
            if (element instanceof PsiMethod) {
                if (!manager.areElementsEquivalent(element, data.getMethodToReplaceIn())) {
                    methodUsages.add(usage);
                }
            } else if (!data.isGenerateDelegate()) {
                changeExternalUsage(usage, usages, data);
            }
        }
    }
    for (UsageInfo usage : methodUsages) {
        changeMethodSignatureAndResolveFieldConflicts(usage, usages, data);
    }
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement)

Example 85 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.

the class I18nizeQuickFixDialog method createPropertiesFileIfNotExists.

private boolean createPropertiesFileIfNotExists() {
    if (getPropertiesFile() != null)
        return true;
    final String path = FileUtil.toSystemIndependentName(myPropertiesFile.getText());
    if (StringUtil.isEmptyOrSpaces(path)) {
        String message = CodeInsightBundle.message("i18nize.empty.file.path", myPropertiesFile.getText());
        Messages.showErrorDialog(myProject, message, CodeInsightBundle.message("i18nize.error.creating.properties.file"));
        myPropertiesFile.requestFocusInWindow();
        return false;
    }
    final FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(path);
    if (fileType != StdFileTypes.PROPERTIES && fileType != StdFileTypes.XML) {
        String message = CodeInsightBundle.message("i18nize.cant.create.properties.file.because.its.name.is.associated", myPropertiesFile.getText(), fileType.getDescription());
        Messages.showErrorDialog(myProject, message, CodeInsightBundle.message("i18nize.error.creating.properties.file"));
        myPropertiesFile.requestFocusInWindow();
        return false;
    }
    try {
        final File file = new File(path).getCanonicalFile();
        FileUtil.createParentDirs(file);
        ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<PsiFile, Exception>() {

            @Override
            public PsiFile compute() throws Exception {
                VirtualFile dir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file.getParentFile());
                final PsiManager psiManager = PsiManager.getInstance(myProject);
                if (dir == null) {
                    throw new IOException("Error creating directory structure for file '" + path + "'");
                }
                if (fileType == StdFileTypes.PROPERTIES) {
                    return psiManager.findFile(dir.createChildData(this, file.getName()));
                } else {
                    FileTemplate template = FileTemplateManager.getInstance(myProject).getInternalTemplate("XML Properties File.xml");
                    LOG.assertTrue(template != null);
                    return (PsiFile) FileTemplateUtil.createFromTemplate(template, file.getName(), null, psiManager.findDirectory(dir));
                }
            }
        });
    } catch (Exception e) {
        Messages.showErrorDialog(myProject, e.getLocalizedMessage(), CodeInsightBundle.message("i18nize.error.creating.properties.file"));
        return false;
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileType(com.intellij.openapi.fileTypes.FileType) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) IOException(java.io.IOException)

Aggregations

PsiManager (com.intellij.psi.PsiManager)120 VirtualFile (com.intellij.openapi.vfs.VirtualFile)84 PsiFile (com.intellij.psi.PsiFile)61 PsiDirectory (com.intellij.psi.PsiDirectory)31 NotNull (org.jetbrains.annotations.NotNull)26 Project (com.intellij.openapi.project.Project)20 File (java.io.File)19 PsiElement (com.intellij.psi.PsiElement)18 ArrayList (java.util.ArrayList)18 Module (com.intellij.openapi.module.Module)17 Nullable (org.jetbrains.annotations.Nullable)16 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 XmlFile (com.intellij.psi.xml.XmlFile)11 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)9 PsiClass (com.intellij.psi.PsiClass)7 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)6 HashSet (java.util.HashSet)6 Nullable (javax.annotation.Nullable)5 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)4