use of org.osmorc.manifest.lang.psi.Clause 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.osmorc.manifest.lang.psi.Clause in project intellij-plugins by JetBrains.
the class ExportPackageParser method annotate.
@Override
public boolean annotate(@NotNull Header header, @NotNull AnnotationHolder holder) {
if (super.annotate(header, holder)) {
return true;
}
boolean annotated = false;
for (HeaderValue value : header.getHeaderValues()) {
if (value instanceof Clause) {
Directive uses = ((Clause) value).getDirective(Constants.USES_DIRECTIVE);
if (uses != null) {
HeaderValuePart valuePart = uses.getValueElement();
if (valuePart != null) {
String text = StringUtil.trimTrailing(valuePart.getText());
int start = StringUtil.startsWithChar(text, '"') ? 1 : 0;
int length = StringUtil.endsWithChar(text, '"') ? text.length() - 1 : text.length();
int offset = valuePart.getTextOffset();
while (start < length) {
int end = text.indexOf(',', start);
if (end < 0)
end = length;
TextRange range = new TextRange(start, end);
start = end + 1;
String packageName = range.substring(text).replaceAll("\\s", "");
if (StringUtil.isEmptyOrSpaces(packageName)) {
TextRange highlight = range.shiftRight(offset);
holder.createErrorAnnotation(highlight, ManifestBundle.message("header.reference.invalid"));
annotated = true;
continue;
}
PsiDirectory[] directories = OsgiPsiUtil.resolvePackage(header, packageName);
if (directories.length == 0) {
TextRange highlight = adjust(range, text).shiftRight(offset);
holder.createErrorAnnotation(highlight, JavaErrorMessages.message("cannot.resolve.package", packageName));
annotated = true;
}
}
}
}
}
}
return annotated;
}
use of org.osmorc.manifest.lang.psi.Clause in project intellij-plugins by JetBrains.
the class OsgiManifestPsiTest method testClauses.
public void testClauses() {
ManifestFile file = createFile("Import-Package: a.b,c.d;a=value;d:=value");
Header header = file.getHeader("Import-Package");
assertNotNull(header);
List<HeaderValue> clauses = header.getHeaderValues();
assertEquals(2, clauses.size());
Clause clause1 = (Clause) clauses.get(0), clause2 = (Clause) clauses.get(1);
assertEquals(0, clause1.getAttributes().size());
assertEquals(0, clause1.getDirectives().size());
assertEquals(1, clause2.getAttributes().size());
assertEquals(1, clause2.getDirectives().size());
assertNotNull(clause2.getAttribute("a"));
assertNull(clause2.getAttribute("b"));
assertNotNull(clause2.getDirective("d"));
assertNull(clause2.getDirective("z"));
}
use of org.osmorc.manifest.lang.psi.Clause in project intellij-plugins by JetBrains.
the class OsgiManifestPsiTest method assertAssignment.
private static void assertAssignment(ManifestFile file, boolean attribute, String name, String expected) {
List<Header> headers = file.getHeaders();
assertEquals(1, headers.size());
List<HeaderValue> clauses = headers.get(0).getHeaderValues();
assertEquals(1, clauses.size());
assertTrue(clauses.get(0) instanceof Clause);
Clause clause = (Clause) clauses.get(0);
AssignmentExpression element = attribute ? clause.getAttribute(name) : clause.getDirective(name);
if (expected != null) {
assertNotNull(element);
assertEquals(expected, element.getValue());
} else {
assertNull(element);
}
}
Aggregations