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;
}
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);
}
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"));
}
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;
}
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;
}
Aggregations