Search in sources :

Example 1 with ManifestFile

use of org.jetbrains.lang.manifest.psi.ManifestFile in project intellij-community by JetBrains.

the class MissingFinalNewlineInspection method checkFile.

@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    if (file instanceof ManifestFile) {
        String text = file.getText();
        if (text != null && text.length() > 0 && !StringUtil.endsWith(text, "\n")) {
            List<Section> sections = ((ManifestFile) file).getSections();
            assert sections.size() > 0 : text;
            Section section = sections.get(sections.size() - 1);
            ProblemDescriptor descriptor = manager.createProblemDescriptor(section.getLastChild(), ManifestBundle.message("inspection.newline.message"), new AddNewlineQuickFix(section), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
            return new ProblemDescriptor[] { descriptor };
        }
    }
    return null;
}
Also used : Section(org.jetbrains.lang.manifest.psi.Section) ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile)

Example 2 with ManifestFile

use of org.jetbrains.lang.manifest.psi.ManifestFile in project intellij-community by JetBrains.

the class HeaderValuePartManipulator method handleContentChange.

@Override
public HeaderValuePart handleContentChange(@NotNull HeaderValuePart element, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
    String text = "HeaderValuePartManipulator: " + range.replace(element.getText(), newContent);
    PsiFile file = PsiFileFactory.getInstance(element.getProject()).createFileFromText("DUMMY.MF", ManifestFileTypeFactory.MANIFEST, text);
    HeaderValue value = ((ManifestFile) file).getHeaders().get(0).getHeaderValue();
    assert value != null : text;
    return (HeaderValuePart) element.replace(value);
}
Also used : HeaderValue(org.jetbrains.lang.manifest.psi.HeaderValue) PsiFile(com.intellij.psi.PsiFile) HeaderValuePart(org.jetbrains.lang.manifest.psi.HeaderValuePart) ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile)

Example 3 with ManifestFile

use of org.jetbrains.lang.manifest.psi.ManifestFile in project intellij-community by JetBrains.

the class ManifestPsiTest method testFile.

public void testFile() {
    ManifestFile file = createFile("");
    assertEquals(0, file.getSections().size());
    assertNull(file.getMainSection());
    assertEquals(0, file.getHeaders().size());
    file = createFile("Header: value\n\nAnother-Header: another value\n");
    assertEquals(2, file.getSections().size());
    assertNotNull(file.getMainSection());
    assertEquals(1, file.getHeaders().size());
    assertNotNull(file.getHeader("Header"));
    assertNull(file.getHeader("Another-Header"));
}
Also used : ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile)

Example 4 with ManifestFile

use of org.jetbrains.lang.manifest.psi.ManifestFile in project intellij-plugins by JetBrains.

the class OsgiPsiUtil method createHeader.

private static Header createHeader(Project project, String headerName, String valueText) {
    String text = String.format("%s: %s\n", headerName, valueText);
    PsiFile file = PsiFileFactory.getInstance(project).createFileFromText("DUMMY.MF", ManifestFileTypeFactory.MANIFEST, text);
    Header header = ((ManifestFile) file).getHeader(headerName);
    if (header == null) {
        throw new IncorrectOperationException("Bad header: '" + text + "'");
    }
    return header;
}
Also used : Header(org.jetbrains.lang.manifest.psi.Header) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile)

Example 5 with ManifestFile

use of org.jetbrains.lang.manifest.psi.ManifestFile in project intellij-plugins by JetBrains.

the class AbstractOsgiQuickFix method getVerifiedManifestFile.

@Nullable
protected ManifestFile getVerifiedManifestFile(@NotNull PsiElement element) {
    Module module = ModuleUtilCore.findModuleForPsiElement(element);
    assert module != null : element;
    OsmorcFacet facet = OsmorcFacet.getInstance(module);
    if (facet != null) {
        OsmorcFacetConfiguration configuration = facet.getConfiguration();
        for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) {
            VirtualFile file = root.findFileByRelativePath(configuration.getManifestLocation());
            if (file != null) {
                PsiFile psiFile = element.getManager().findFile(file);
                if (psiFile instanceof ManifestFile && CommonRefactoringUtil.checkReadOnlyStatus(psiFile)) {
                    return (ManifestFile) psiFile;
                }
            }
        }
    }
    OsmorcBundle.notification(getFamilyName(), OsmorcBundle.message("inspection.fix.no.manifest"), NotificationType.WARNING).notify(element.getProject());
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) OsmorcFacet(org.osmorc.facet.OsmorcFacet) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ManifestFile (org.jetbrains.lang.manifest.psi.ManifestFile)13 Header (org.jetbrains.lang.manifest.psi.Header)4 PsiFile (com.intellij.psi.PsiFile)3 Nullable (org.jetbrains.annotations.Nullable)2 HeaderValue (org.jetbrains.lang.manifest.psi.HeaderValue)2 OsmorcFacet (org.osmorc.facet.OsmorcFacet)2 OsmorcFacetConfiguration (org.osmorc.facet.OsmorcFacetConfiguration)2 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 List (java.util.List)1 HeaderValuePart (org.jetbrains.lang.manifest.psi.HeaderValuePart)1 Section (org.jetbrains.lang.manifest.psi.Section)1 Version (org.osgi.framework.Version)1 Clause (org.osmorc.manifest.lang.psi.Clause)1