use of org.jetbrains.lang.manifest.psi.HeaderValue in project intellij-community by JetBrains.
the class ClassReferenceParser method annotate.
@Override
public boolean annotate(@NotNull Header header, @NotNull AnnotationHolder holder) {
HeaderValue value = header.getHeaderValue();
if (!(value instanceof HeaderValuePart))
return false;
HeaderValuePart valuePart = (HeaderValuePart) value;
String className = valuePart.getUnwrappedText();
if (StringUtil.isEmptyOrSpaces(className)) {
holder.createErrorAnnotation(valuePart.getHighlightingRange(), ManifestBundle.message("header.reference.invalid"));
return true;
}
Project project = header.getProject();
Module module = ModuleUtilCore.findModuleForPsiElement(header);
GlobalSearchScope scope = module != null ? module.getModuleWithDependenciesAndLibrariesScope(false) : ProjectScope.getAllScope(project);
PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, scope);
if (aClass == null) {
String message = JavaErrorMessages.message("error.cannot.resolve.class", className);
Annotation anno = holder.createErrorAnnotation(valuePart.getHighlightingRange(), message);
anno.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
return true;
}
return checkClass(valuePart, aClass, holder);
}
use of org.jetbrains.lang.manifest.psi.HeaderValue 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.HeaderValue in project intellij-community by JetBrains.
the class ManifestPsiTest method assertHeaderValue.
private static void assertHeaderValue(ManifestFile file, String name, @Nullable String expected) {
Header header = file.getHeader(name);
assertNotNull(header);
HeaderValue value = header.getHeaderValue();
if (expected == null) {
assertNull(value);
} else {
assertNotNull(value);
assertEquals(expected, value.getUnwrappedText());
}
}
use of org.jetbrains.lang.manifest.psi.HeaderValue in project intellij-plugins by JetBrains.
the class BasePackageParser method annotate.
@Override
public boolean annotate(@NotNull Header header, @NotNull AnnotationHolder holder) {
boolean annotated = false;
for (HeaderValue value : header.getHeaderValues()) {
if (value instanceof Clause) {
HeaderValuePart valuePart = ((Clause) value).getValue();
if (valuePart != null) {
String packageName = valuePart.getUnwrappedText();
packageName = StringUtil.trimEnd(packageName, ".*");
if (StringUtil.isEmptyOrSpaces(packageName)) {
holder.createErrorAnnotation(valuePart.getHighlightingRange(), ManifestBundle.message("header.reference.invalid"));
annotated = true;
continue;
}
PsiDirectory[] directories = OsgiPsiUtil.resolvePackage(header, packageName);
if (directories.length == 0) {
holder.createErrorAnnotation(valuePart.getHighlightingRange(), JavaErrorMessages.message("cannot.resolve.package", packageName));
annotated = true;
}
}
}
}
return annotated;
}
use of org.jetbrains.lang.manifest.psi.HeaderValue in project intellij-plugins by JetBrains.
the class OsgiPsiUtil method appendToHeader.
public static void appendToHeader(@NotNull ManifestFile manifestFile, @NotNull String headerName, @NotNull String headerValue) {
Header header = manifestFile.getHeader(headerName);
if (header != null) {
HeaderValue oldValue = header.getHeaderValue();
if (oldValue != null) {
String oldText = trimTrailing(header.getText().substring(oldValue.getStartOffsetInParent(), header.getTextLength()));
if (!oldText.isEmpty())
oldText += ",\n ";
headerValue = oldText + headerValue;
}
header.replace(createHeader(manifestFile.getProject(), headerName, headerValue));
} else {
addHeader(manifestFile, createHeader(manifestFile.getProject(), headerName, headerValue));
}
}
Aggregations