Search in sources :

Example 1 with PsiManager

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

the class XsltDebuggerExtension method patchParameters.

public void patchParameters(final SimpleJavaParameters parameters, XsltRunConfiguration configuration, UserDataHolder extensionData) throws CantRunException {
    final XsltRunConfiguration.OutputType outputType = configuration.getOutputType();
    final Sdk jdk = configuration.getEffectiveJDK();
    assert jdk != null;
    final String ver = jdk.getVersionString();
    if (ver == null || (ver.contains("1.0") || ver.contains("1.1") || ver.contains("1.2") || ver.contains("1.3") || ver.contains("1.4"))) {
        throw new CantRunException("The XSLT Debugger can only be used with JDK 1.5+");
    }
    // TODO: fix and remove
    if (outputType != XsltRunConfiguration.OutputType.CONSOLE) {
        throw new CantRunException("XSLT Debugger requires Output Type == CONSOLE");
    }
    try {
        final int port = NetUtils.findAvailableSocketPort();
        parameters.getVMParametersList().defineProperty("xslt.debugger.port", String.valueOf(port));
        extensionData.putUserData(PORT, port);
    } catch (IOException e) {
        LOG.info(e);
        throw new CantRunException("Unable to find a free network port");
    }
    final char c = File.separatorChar;
    final PluginId pluginId = PluginManagerCore.getPluginByClassName(getClass().getName());
    assert pluginId != null || System.getProperty("xslt-debugger.plugin.path") != null;
    final File pluginPath;
    if (pluginId != null) {
        final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(pluginId);
        assert descriptor != null;
        pluginPath = descriptor.getPath();
    } else {
        // -Dxslt-debugger.plugin.path=C:\work\java\intellij/ultimate\out\classes\production\xslt-debugger-engine
        pluginPath = new File(System.getProperty("xslt-debugger.plugin.path"));
    }
    File rtClasspath = new File(pluginPath, "lib" + c + "xslt-debugger-engine.jar");
    if (rtClasspath.exists()) {
        parameters.getClassPath().addTail(rtClasspath.getAbsolutePath());
        final File rmiStubs = new File(pluginPath, "lib" + c + "rmi-stubs.jar");
        assert rmiStubs.exists() : rmiStubs.getAbsolutePath();
        parameters.getClassPath().addTail(rmiStubs.getAbsolutePath());
        final File engineImpl = new File(pluginPath, "lib" + c + "rt" + c + "xslt-debugger-engine-impl.jar");
        assert engineImpl.exists() : engineImpl.getAbsolutePath();
        parameters.getClassPath().addTail(engineImpl.getAbsolutePath());
    } else {
        if (!(rtClasspath = new File(pluginPath, "classes")).exists()) {
            if (ApplicationManagerEx.getApplicationEx().isInternal() && new File(pluginPath, "org").exists()) {
                rtClasspath = pluginPath;
                final File engineImplInternal = new File(pluginPath, ".." + c + "xslt-debugger-engine-impl");
                assert engineImplInternal.exists() : engineImplInternal.getAbsolutePath();
                parameters.getClassPath().addTail(engineImplInternal.getAbsolutePath());
            } else {
                throw new CantRunException("Runtime classes not found");
            }
        }
        parameters.getClassPath().addTail(rtClasspath.getAbsolutePath());
        final File rmiStubs = new File(rtClasspath, "rmi-stubs.jar");
        assert rmiStubs.exists() : rmiStubs.getAbsolutePath();
        parameters.getClassPath().addTail(rmiStubs.getAbsolutePath());
    }
    File trove4j = new File(PathManager.getLibPath() + c + "trove4j.jar");
    if (!trove4j.exists()) {
        trove4j = new File(PathManager.getHomePath() + c + "community" + c + "lib" + c + "trove4j.jar");
        assert trove4j.exists() : trove4j.getAbsolutePath();
    }
    parameters.getClassPath().addTail(trove4j.getAbsolutePath());
    final String type = parameters.getVMParametersList().getPropertyValue("xslt.transformer.type");
    if ("saxon".equalsIgnoreCase(type)) {
        addSaxon(parameters, pluginPath, SAXON_6_JAR);
    } else if ("saxon9".equalsIgnoreCase(type)) {
        addSaxon(parameters, pluginPath, SAXON_9_JAR);
    } else if ("xalan".equalsIgnoreCase(type)) {
        final Boolean xalanPresent = isValidXalanPresent(parameters);
        if (xalanPresent == null) {
            addXalan(parameters, pluginPath);
        } else if (!xalanPresent) {
            throw new CantRunException("Unsupported Xalan version is present in classpath.");
        }
    } else if (type != null) {
        throw new CantRunException("Unsupported Transformer type '" + type + "'");
    } else if (parameters.getClassPath().getPathsString().toLowerCase().contains("xalan")) {
        if (isValidXalanPresent(parameters) == Boolean.TRUE) {
            parameters.getVMParametersList().defineProperty("xslt.transformer.type", "xalan");
        }
    }
    final VirtualFile xsltFile = configuration.findXsltFile();
    final PsiManager psiManager = PsiManager.getInstance(configuration.getProject());
    final XsltChecker.LanguageLevel level;
    if (xsltFile != null) {
        level = XsltSupport.getXsltLanguageLevel(psiManager.findFile(xsltFile));
    } else {
        level = XsltChecker.LanguageLevel.V1;
    }
    extensionData.putUserData(VERSION, level);
    if (!parameters.getVMParametersList().hasProperty("xslt.transformer.type")) {
        // add saxon for backward-compatibility
        if (level == XsltChecker.LanguageLevel.V2) {
            parameters.getVMParametersList().defineProperty("xslt.transformer.type", "saxon9");
            addSaxon(parameters, pluginPath, SAXON_9_JAR);
        } else {
            parameters.getVMParametersList().defineProperty("xslt.transformer.type", "saxon");
            addSaxon(parameters, pluginPath, SAXON_6_JAR);
        }
    }
    parameters.getVMParametersList().defineProperty("xslt.main", "org.intellij.plugins.xsltDebugger.rt.XSLTDebuggerMain");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XsltRunConfiguration(org.intellij.lang.xpath.xslt.run.XsltRunConfiguration) PsiManager(com.intellij.psi.PsiManager) IOException(java.io.IOException) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) XsltChecker(org.intellij.lang.xpath.xslt.impl.XsltChecker) PluginId(com.intellij.openapi.extensions.PluginId) CantRunException(com.intellij.execution.CantRunException) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with PsiManager

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

the class XsltBreakpointHandler method getActualLineNumber.

public static int getActualLineNumber(Project project, @Nullable XSourcePosition position) {
    if (position == null) {
        return -1;
    }
    final PsiElement element = findContextElement(project, position);
    if (element == null) {
        return -1;
    }
    if (element instanceof XmlToken) {
        final IElementType tokenType = ((XmlToken) element).getTokenType();
        if (tokenType == XmlTokenType.XML_START_TAG_START || tokenType == XmlTokenType.XML_NAME) {
            final PsiManager psiManager = PsiManager.getInstance(project);
            final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
            final PsiFile psiFile = psiManager.findFile(position.getFile());
            if (psiFile == null) {
                return -1;
            }
            final Document document = documentManager.getDocument(psiFile);
            if (document == null) {
                return -1;
            }
            if (document.getLineNumber(element.getTextRange().getStartOffset()) == position.getLine()) {
                final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
                if (tag != null) {
                    final ASTNode node = tag.getNode();
                    assert node != null;
                    // TODO: re-check if/when Xalan is supported
                    final ASTNode end = XmlChildRole.START_TAG_END_FINDER.findChild(node);
                    if (end != null) {
                        return document.getLineNumber(end.getTextRange().getEndOffset()) + 1;
                    } else {
                        final ASTNode end2 = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(node);
                        if (end2 != null) {
                            return document.getLineNumber(end2.getTextRange().getEndOffset()) + 1;
                        }
                    }
                }
            }
        }
    }
    return -1;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ASTNode(com.intellij.lang.ASTNode) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 3 with PsiManager

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

the class PyExtractSuperclassTest method testMultifileAppend.

public void testMultifileAppend() {
    // this is half-copy-paste of testMultifileNew. generalization won't make either easier to follow.
    String baseName = "/refactoring/extractsuperclass/multifile/";
    myFixture.configureByFiles(baseName + "source.py", baseName + "a/__init__.py", baseName + "a/b/__init__.py", baseName + "a/b/foo.py");
    final String className = "Foo";
    final String superclassName = "Suppa";
    final PyClass clazz = findClass(className);
    final List<PyMemberInfo<PyElement>> members = new ArrayList<>();
    final PyElement member = findMember(className, ".foo");
    members.add(MembersManager.findMember(clazz, member));
    final VirtualFile base_dir = myFixture.getFile().getVirtualFile().getParent();
    new WriteCommandAction.Simple(myFixture.getProject()) {

        @Override
        protected void run() throws Throwable {
            //TODO: Test via presenter
            //noinspection ConstantConditions
            final String path = base_dir.getPath() + "/a/b";
            PyExtractSuperclassHelper.extractSuperclass(clazz, members, superclassName, path + "/foo.py");
        }
    }.execute();
    final PsiManager psi_mgr = PsiManager.getInstance(myFixture.getProject());
    VirtualFile vfile = base_dir.findChild("a");
    assertTrue(vfile.isDirectory());
    vfile = vfile.findChild(PyNames.INIT_DOT_PY);
    assertNotNull(vfile);
    vfile = base_dir.findChild("a").findChild("b");
    assertTrue(vfile.isDirectory());
    assertNotNull(vfile.findChild(PyNames.INIT_DOT_PY));
    vfile = vfile.findChild("foo.py");
    assertNotNull(vfile);
    PsiFile psi_file = psi_mgr.findFile(vfile);
    String result = psi_file.getText().trim();
    File expected_file = new File(getTestDataPath() + baseName, "target.append.py");
    String expected = psi_mgr.findFile(LocalFileSystem.getInstance().findFileByIoFile(expected_file)).getText().trim();
    assertEquals(expected, result);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ArrayList(java.util.ArrayList) PyMemberInfo(com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) PyElement(com.jetbrains.python.psi.PyElement)

Example 4 with PsiManager

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

the class InsertComponentProcessor method checkAddDependencyOnInsert.

private boolean checkAddDependencyOnInsert(final ComponentItem item) {
    if (item.getClassName().equals(HSpacer.class.getName()) || item.getClassName().equals(VSpacer.class.getName())) {
        // this is mostly required for IDEA developers, so that developers don't receive prompt to offer ui-designer-impl dependency
        return true;
    }
    PsiManager manager = PsiManager.getInstance(myEditor.getProject());
    final GlobalSearchScope projectScope = GlobalSearchScope.allScope(myEditor.getProject());
    final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myEditor.getModule());
    final PsiClass componentClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(item.getClassName(), projectScope);
    if (componentClass != null && JavaPsiFacade.getInstance(manager.getProject()).findClass(item.getClassName(), moduleScope) == null) {
        final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myEditor.getProject()).getFileIndex();
        List<OrderEntry> entries = fileIndex.getOrderEntriesForFile(componentClass.getContainingFile().getVirtualFile());
        if (entries.size() > 0) {
            if (entries.get(0) instanceof ModuleSourceOrderEntry) {
                if (!checkAddModuleDependency(item, (ModuleSourceOrderEntry) entries.get(0)))
                    return false;
            } else if (entries.get(0) instanceof LibraryOrderEntry) {
                if (!checkAddLibraryDependency(item, (LibraryOrderEntry) entries.get(0)))
                    return false;
            }
        }
    }
    return true;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager)

Example 5 with PsiManager

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

the class Java15FormInspection method checkComponentProperties.

protected void checkComponentProperties(Module module, final IComponent component, final FormErrorCollector collector) {
    final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    final PsiManager psiManager = PsiManager.getInstance(module.getProject());
    final PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(component.getComponentClassName(), scope);
    if (aClass == null) {
        return;
    }
    for (final IProperty prop : component.getModifiedProperties()) {
        final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, prop.getName(), false, true);
        if (getter == null)
            continue;
        final LanguageLevel languageLevel = LanguageLevelUtil.getEffectiveLanguageLevel(module);
        if (Java15APIUsageInspection.getLastIncompatibleLanguageLevel(getter, languageLevel) != null) {
            registerError(component, collector, prop, "@since " + Java15APIUsageInspection.getShortName(languageLevel));
        }
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IProperty(com.intellij.uiDesigner.lw.IProperty) PsiMethod(com.intellij.psi.PsiMethod) LanguageLevel(com.intellij.pom.java.LanguageLevel) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager)

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