Search in sources :

Example 1 with HeaderValue

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);
}
Also used : Project(com.intellij.openapi.project.Project) HeaderValue(org.jetbrains.lang.manifest.psi.HeaderValue) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HeaderValuePart(org.jetbrains.lang.manifest.psi.HeaderValuePart) Module(com.intellij.openapi.module.Module) Annotation(com.intellij.lang.annotation.Annotation)

Example 2 with HeaderValue

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

Example 3 with HeaderValue

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

Example 4 with HeaderValue

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;
}
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 5 with HeaderValue

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

Aggregations

HeaderValue (org.jetbrains.lang.manifest.psi.HeaderValue)7 Header (org.jetbrains.lang.manifest.psi.Header)4 HeaderValuePart (org.jetbrains.lang.manifest.psi.HeaderValuePart)3 Clause (org.osmorc.manifest.lang.psi.Clause)3 ManifestFile (org.jetbrains.lang.manifest.psi.ManifestFile)2 Annotation (com.intellij.lang.annotation.Annotation)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiFile (com.intellij.psi.PsiFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 AssignmentExpression (org.osmorc.manifest.lang.psi.AssignmentExpression)1