Search in sources :

Example 1 with SyntheticElement

use of com.intellij.psi.SyntheticElement in project intellij-community by JetBrains.

the class GrPackageInspection method getElementToHighlight.

@Nullable
private static PsiElement getElementToHighlight(GroovyFile file) {
    GrPackageDefinition packageDefinition = file.getPackageDefinition();
    if (packageDefinition != null)
        return packageDefinition;
    PsiClass[] classes = file.getClasses();
    for (PsiClass aClass : classes) {
        if (!(aClass instanceof SyntheticElement) && aClass instanceof GrTypeDefinition) {
            return ((GrTypeDefinition) aClass).getNameIdentifierGroovy();
        }
    }
    GrTopStatement[] statements = file.getTopStatements();
    if (statements.length > 0) {
        GrTopStatement first = statements[0];
        if (first instanceof GrNamedElement)
            return ((GrNamedElement) first).getNameIdentifierGroovy();
        return first;
    }
    return null;
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrNamedElement(org.jetbrains.plugins.groovy.lang.psi.GrNamedElement) PsiClass(com.intellij.psi.PsiClass) GrPackageDefinition(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition) SyntheticElement(com.intellij.psi.SyntheticElement) GrTopStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.GrTopStatement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiClass (com.intellij.psi.PsiClass)1 SyntheticElement (com.intellij.psi.SyntheticElement)1 Nullable (org.jetbrains.annotations.Nullable)1 GrNamedElement (org.jetbrains.plugins.groovy.lang.psi.GrNamedElement)1 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)1 GrTopStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.GrTopStatement)1 GrPackageDefinition (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition)1