Search in sources :

Example 1 with Directive

use of org.osmorc.manifest.lang.psi.Directive 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)

Aggregations

TextRange (com.intellij.openapi.util.TextRange)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 Clause (org.osmorc.manifest.lang.psi.Clause)1 Directive (org.osmorc.manifest.lang.psi.Directive)1