Search in sources :

Example 1 with Section

use of org.jetbrains.lang.manifest.psi.Section 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 Section

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

the class OsgiPsiUtil method addHeader.

private static void addHeader(ManifestFile manifestFile, Header newHeader) {
    Section section = manifestFile.getMainSection();
    List<Header> headers = manifestFile.getHeaders();
    if (section == null) {
        manifestFile.add(newHeader.getParent());
    } else if (headers.isEmpty()) {
        section.addBefore(newHeader, section.getFirstChild());
    } else {
        section.addAfter(newHeader, headers.get(headers.size() - 1));
    }
}
Also used : Header(org.jetbrains.lang.manifest.psi.Header) Section(org.jetbrains.lang.manifest.psi.Section)

Aggregations

Section (org.jetbrains.lang.manifest.psi.Section)2 Header (org.jetbrains.lang.manifest.psi.Header)1 ManifestFile (org.jetbrains.lang.manifest.psi.ManifestFile)1