use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GrStubFileElementType method getBuilder.
@Override
public StubBuilder getBuilder() {
return new DefaultStubBuilder() {
@NotNull
@Override
protected StubElement createStubForFile(@NotNull final PsiFile file) {
if (file instanceof GroovyFile) {
return new GrFileStub((GroovyFile) file);
}
return super.createStubForFile(file);
}
@Override
public boolean skipChildProcessingWhenBuildingStubs(@NotNull ASTNode parent, @NotNull ASTNode node) {
IElementType childType = node.getElementType();
IElementType parentType = parent.getElementType();
if (childType == GroovyElementTypes.PARAMETER && parentType != GroovyElementTypes.PARAMETERS_LIST) {
return true;
}
if (childType == GroovyElementTypes.PARAMETERS_LIST && !(parent.getPsi() instanceof GrMethod)) {
return true;
}
if (childType == GroovyElementTypes.MODIFIERS) {
if (parentType == GroovyElementTypes.CLASS_INITIALIZER) {
return true;
}
if (parentType == GroovyElementTypes.VARIABLE_DEFINITION && !GroovyElementTypes.VARIABLE_DEFINITION.shouldCreateStub(parent)) {
return true;
}
}
return false;
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GrVariableDeclarationElementType method shouldCreateStub.
@Override
public boolean shouldCreateStub(ASTNode node) {
PsiElement parent = SharedImplUtil.getParent(node);
if (parent instanceof GrTypeDefinitionBody) {
// store fields
return true;
}
if (PsiTreeUtil.getParentOfType(parent, GrTypeDefinition.class) != null) {
// do not store variable declarations within classes, as they are not scripts
return false;
}
PsiElement psi = node.getPsi();
if (!(psi instanceof GrVariableDeclaration) || ((GrVariableDeclaration) psi).getModifierList().getRawAnnotations().length == 0) {
// store only annotated declarations
return false;
}
PsiFile file = psi.getContainingFile();
return file instanceof GroovyFile && ((GroovyFile) file).isScript();
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class ResolveUtil method resolveLabelTargets.
@NotNull
public static Pair<GrStatement, GrLabeledStatement> resolveLabelTargets(@Nullable String labelName, @Nullable PsiElement element, boolean isBreak) {
if (element == null)
return new Pair<>(null, null);
if (labelName == null) {
do {
element = element.getContext();
if (element == null || element instanceof GrClosableBlock || element instanceof GrMember || element instanceof GroovyFile) {
return new Pair<>(null, null);
}
} while (!(element instanceof GrLoopStatement) && !(isBreak && element instanceof GrSwitchStatement));
return new Pair<>(((GrStatement) element), null);
}
GrStatement statement = null;
do {
PsiElement last = element;
element = element.getContext();
if (element == null || element instanceof GrMember || element instanceof GroovyFile)
break;
if (element instanceof GrStatement && !(element instanceof GrClosableBlock)) {
statement = (GrStatement) element;
}
PsiElement sibling = element;
while (sibling != null) {
final GrLabeledStatement labelStatement = findLabelStatementIn(sibling, last, labelName);
if (labelStatement != null) {
return Pair.create(statement, labelStatement);
}
sibling = sibling.getPrevSibling();
}
if (element instanceof GrClosableBlock)
break;
} while (true);
return new Pair<>(null, null);
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GrMainCompletionProvider method completeStaticMembers.
static StaticMemberProcessor completeStaticMembers(CompletionParameters parameters) {
final PsiElement position = parameters.getPosition();
final PsiElement originalPosition = parameters.getOriginalPosition();
final StaticMemberProcessor processor = new StaticMemberProcessor(position) {
@NotNull
@Override
protected LookupElement createLookupElement(@NotNull PsiMember member, @NotNull PsiClass containingClass, boolean shouldImport) {
shouldImport |= originalPosition != null && PsiTreeUtil.isAncestor(containingClass, originalPosition, false);
return createGlobalMemberElement(member, containingClass, shouldImport);
}
@Override
protected LookupElement createLookupElement(@NotNull List<PsiMethod> overloads, @NotNull PsiClass containingClass, boolean shouldImport) {
shouldImport |= originalPosition != null && PsiTreeUtil.isAncestor(containingClass, originalPosition, false);
return new JavaGlobalMemberLookupElement(overloads, containingClass, QualifiedMethodInsertHandler.INSTANCE, StaticImportInsertHandler.INSTANCE, shouldImport);
}
@Override
protected boolean isAccessible(PsiMember member) {
boolean result = super.isAccessible(member);
if (!result && member instanceof GrField) {
GrAccessorMethod[] getters = ((GrField) member).getGetters();
return getters.length > 0 && super.isAccessible(getters[0]);
}
return result;
}
};
final PsiFile file = position.getContainingFile();
if (file instanceof GroovyFile) {
for (GrImportStatement statement : ((GroovyFile) file).getImportStatements()) {
if (statement.isStatic()) {
GrCodeReferenceElement importReference = statement.getImportReference();
if (importReference != null) {
if (!statement.isOnDemand()) {
importReference = importReference.getQualifier();
}
if (importReference != null) {
final PsiElement target = importReference.resolve();
if (target instanceof PsiClass) {
processor.importMembersOf((PsiClass) target);
}
}
}
}
}
}
return processor;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GroovyDocumentationProvider method generateClassInfo.
private static String generateClassInfo(PsiClass aClass) {
StringBuilder buffer = new StringBuilder();
GroovyFile file = (GroovyFile) aClass.getContainingFile();
String packageName = file.getPackageName();
if (!packageName.isEmpty()) {
buffer.append(packageName).append("\n");
}
final String classString = aClass.isInterface() ? "interface" : aClass instanceof PsiTypeParameter ? "type parameter" : aClass.isEnum() ? "enum" : "class";
buffer.append(classString).append(" ").append(aClass.getName());
JavaDocumentationProvider.generateTypeParameters(aClass, buffer);
JavaDocumentationProvider.writeExtends(aClass, buffer, aClass.getExtendsListTypes());
JavaDocumentationProvider.writeImplements(aClass, buffer, aClass.getImplementsListTypes());
return buffer.toString();
}
Aggregations