use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyFoldingBuilder method isSingleHighLevelClassBody.
private static boolean isSingleHighLevelClassBody(PsiElement element) {
if (!(element instanceof GrTypeDefinitionBody))
return false;
final PsiElement parent = element.getParent();
if (!(parent instanceof GrTypeDefinition))
return false;
final GrTypeDefinition clazz = (GrTypeDefinition) parent;
if (clazz.isAnonymous() || clazz.getContainingClass() != null)
return false;
final PsiFile file = element.getContainingFile();
return file instanceof GroovyFile && ((GroovyFile) file).getClasses().length == 1;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyFileImpl method checkIsScript.
private boolean checkIsScript() {
final GrTopStatement[] topStatements = findChildrenByClass(GrTopStatement.class);
boolean hasClassDefinitions = false;
boolean hasTopStatements = false;
for (GrTopStatement st : topStatements) {
if (st instanceof GrTypeDefinition) {
hasClassDefinitions = true;
} else if (!(st instanceof GrImportStatement || st instanceof GrPackageDefinition)) {
hasTopStatements = true;
break;
}
}
return hasTopStatements || !hasClassDefinitions;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyFileImpl method processDeclarationsNoGuess.
private boolean processDeclarationsNoGuess(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
if (myContext != null) {
if (ResolveUtil.shouldProcessProperties(classHint)) {
if (!processChildrenScopes(processor, state, lastParent, place))
return false;
}
return true;
}
boolean processClasses = ResolveUtil.shouldProcessClasses(classHint);
GrImportStatement[] importStatements = getImportStatements();
if (!processImports(processor, state, lastParent, place, importStatements, ImportKind.ALIAS, false))
return false;
GroovyScriptClass scriptClass = getScriptClass();
if (scriptClass != null && StringUtil.isJavaIdentifier(scriptClass.getName())) {
if (!(lastParent instanceof GrTypeDefinition)) {
if (!ResolveUtil.processClassDeclarations(scriptClass, processor, state, lastParent, place))
return false;
}
if (processClasses) {
if (!ResolveUtil.processElement(processor, scriptClass, state))
return false;
}
}
if (processClasses) {
for (GrTypeDefinition definition : getTypeDefinitions()) {
if (!ResolveUtil.processElement(processor, definition, state))
return false;
}
}
if (ResolveUtil.shouldProcessProperties(classHint)) {
if (!processChildrenScopes(processor, state, lastParent, place))
return false;
}
if (!processImports(processor, state, lastParent, place, importStatements, ImportKind.ALIAS, true))
return false;
if (!processImports(processor, state, lastParent, place, importStatements, ImportKind.SIMPLE, null))
return false;
if (!processDeclarationsInPackage(processor, state, lastParent, place))
return false;
if (!processImports(processor, state, lastParent, place, importStatements, ImportKind.ON_DEMAND, null))
return false;
if (!ImplicitImportsKt.processImplicitImports(processor, state, lastParent, place, this))
return false;
if (ResolveUtil.shouldProcessPackages(classHint)) {
NameHint nameHint = processor.getHint(NameHint.KEY);
String expectedName = nameHint != null ? nameHint.getName(state) : null;
final JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
if (expectedName != null) {
final PsiPackage pkg = facade.findPackage(expectedName);
if (pkg != null && !processor.execute(pkg, state)) {
return false;
}
} else {
PsiPackage defaultPackage = facade.findPackage("");
if (defaultPackage != null) {
for (PsiPackage subPackage : defaultPackage.getSubPackages(getResolveScope())) {
if (!ResolveUtil.processElement(processor, subPackage, state))
return false;
}
}
}
}
if (ResolveUtil.shouldProcessProperties(classHint)) {
if (lastParent != null && !(lastParent instanceof GrTypeDefinition) && scriptClass != null) {
if (!ResolveUtil.processElement(processor, getSyntheticArgsParameter(), state))
return false;
}
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrSuperReferenceResolver method resolveSuperExpression.
@Nullable("null if ref is not 'super' reference")
public static GroovyResolveResult[] resolveSuperExpression(@NotNull GrReferenceExpression ref) {
GrExpression qualifier = ref.getQualifier();
if (qualifier == null) {
final PsiElement parent = ref.getParent();
if (parent instanceof GrConstructorInvocation) {
return ((GrConstructorInvocation) parent).multiResolve(false);
}
PsiClass aClass = PsiUtil.getContextClass(ref);
if (aClass != null) {
return getSuperClass(aClass);
}
} else if (qualifier instanceof GrReferenceExpression) {
GroovyResolveResult result = ((GrReferenceExpression) qualifier).advancedResolve();
PsiElement resolved = result.getElement();
if (resolved instanceof PsiClass) {
PsiClass superClass = (PsiClass) resolved;
GrTypeDefinition scopeClass = PsiTreeUtil.getParentOfType(ref, GrTypeDefinition.class, true);
if (scopeClass != null && GrTraitUtil.isTrait(superClass) && scopeClass.isInheritor(superClass, false)) {
PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, scopeClass, PsiSubstitutor.EMPTY);
return new GroovyResolveResultImpl[] { new GroovyResolveResultImpl(superClass, null, null, superClassSubstitutor, true, true) };
}
if (PsiUtil.hasEnclosingInstanceInScope(superClass, ref, false)) {
return getSuperClass(superClass);
}
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrClosableBlockImpl method getOwner.
private PsiVariable getOwner() {
return CachedValuesManager.getCachedValue(this, () -> {
final GroovyPsiElement context = PsiTreeUtil.getParentOfType(this, GrTypeDefinition.class, GrClosableBlock.class, GroovyFile.class);
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
PsiType type = null;
if (context instanceof GrTypeDefinition) {
type = factory.createType((PsiClass) context);
} else if (context instanceof GrClosableBlock) {
type = GrClosureType.create((GrClosableBlock) context, true);
} else if (context instanceof GroovyFile) {
final PsiClass scriptClass = ((GroovyFile) context).getScriptClass();
if (scriptClass != null && GroovyNamesUtil.isIdentifier(scriptClass.getName()))
type = factory.createType(scriptClass);
}
if (type == null) {
type = TypesUtil.getJavaLangObject(this);
}
PsiVariable owner = new GrLightVariable(getManager(), OWNER_NAME, type, this);
return CachedValueProvider.Result.create(owner, PsiModificationTracker.MODIFICATION_COUNT);
});
}
Aggregations