Search in sources :

Example 1 with GroovyStaticTypeCheckVisitor

use of org.jetbrains.plugins.groovy.codeInspection.type.GroovyStaticTypeCheckVisitor in project intellij-community by JetBrains.

the class GrAnnotatorImpl method annotate.

@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (FileIndexFacade.getInstance(element.getProject()).isInLibrarySource(element.getContainingFile().getVirtualFile()))
        return;
    if (element instanceof GroovyPsiElement) {
        final GroovyAnnotator annotator = new GroovyAnnotator(holder);
        ((GroovyPsiElement) element).accept(annotator);
        if (PsiUtil.isCompileStatic(element)) {
            final GroovyStaticTypeCheckVisitor typeCheckVisitor = myTypeCheckVisitorThreadLocal.get();
            assert typeCheckVisitor != null;
            typeCheckVisitor.accept((GroovyPsiElement) element, holder);
        }
    } else if (element instanceof PsiComment) {
        String text = element.getText();
        if (text.startsWith("/*") && !(text.endsWith("*/"))) {
            TextRange range = element.getTextRange();
            holder.createErrorAnnotation(TextRange.create(range.getEndOffset() - 1, range.getEndOffset()), GroovyBundle.message("doc.end.expected"));
        }
    } else {
        final PsiElement parent = element.getParent();
        if (parent instanceof GrMethod) {
            if (element.equals(((GrMethod) parent).getNameIdentifierGroovy()) && ((GrMethod) parent).getReturnTypeElementGroovy() == null) {
                GroovyAnnotator.checkMethodReturnType((GrMethod) parent, element, holder);
            }
        } else if (parent instanceof GrField) {
            final GrField field = (GrField) parent;
            if (element.equals(field.getNameIdentifierGroovy())) {
                final GrAccessorMethod[] getters = field.getGetters();
                for (GrAccessorMethod getter : getters) {
                    GroovyAnnotator.checkMethodReturnType(getter, field.getNameIdentifierGroovy(), holder);
                }
                final GrAccessorMethod setter = field.getSetter();
                if (setter != null) {
                    GroovyAnnotator.checkMethodReturnType(setter, field.getNameIdentifierGroovy(), holder);
                }
            }
        }
    }
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) PsiComment(com.intellij.psi.PsiComment) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GroovyStaticTypeCheckVisitor(org.jetbrains.plugins.groovy.codeInspection.type.GroovyStaticTypeCheckVisitor) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Aggregations

TextRange (com.intellij.openapi.util.TextRange)1 PsiComment (com.intellij.psi.PsiComment)1 PsiElement (com.intellij.psi.PsiElement)1 GroovyStaticTypeCheckVisitor (org.jetbrains.plugins.groovy.codeInspection.type.GroovyStaticTypeCheckVisitor)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)1 GrAccessorMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1