Search in sources :

Example 1 with Clause

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;
}
Also used : HeaderValue(org.jetbrains.lang.manifest.psi.HeaderValue) PsiDirectory(com.intellij.psi.PsiDirectory) Clause(org.osmorc.manifest.lang.psi.Clause) HeaderValuePart(org.jetbrains.lang.manifest.psi.HeaderValuePart)

Example 2 with Clause

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;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) TextRange(com.intellij.openapi.util.TextRange) Clause(org.osmorc.manifest.lang.psi.Clause) Directive(org.osmorc.manifest.lang.psi.Directive)

Example 3 with Clause

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"));
}
Also used : HeaderValue(org.jetbrains.lang.manifest.psi.HeaderValue) Header(org.jetbrains.lang.manifest.psi.Header) Clause(org.osmorc.manifest.lang.psi.Clause) ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile)

Example 4 with Clause

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);
    }
}
Also used : HeaderValue(org.jetbrains.lang.manifest.psi.HeaderValue) Header(org.jetbrains.lang.manifest.psi.Header) AssignmentExpression(org.osmorc.manifest.lang.psi.AssignmentExpression) Clause(org.osmorc.manifest.lang.psi.Clause)

Aggregations

Clause (org.osmorc.manifest.lang.psi.Clause)4 HeaderValue (org.jetbrains.lang.manifest.psi.HeaderValue)3 PsiDirectory (com.intellij.psi.PsiDirectory)2 Header (org.jetbrains.lang.manifest.psi.Header)2 TextRange (com.intellij.openapi.util.TextRange)1 HeaderValuePart (org.jetbrains.lang.manifest.psi.HeaderValuePart)1 ManifestFile (org.jetbrains.lang.manifest.psi.ManifestFile)1 AssignmentExpression (org.osmorc.manifest.lang.psi.AssignmentExpression)1 Directive (org.osmorc.manifest.lang.psi.Directive)1