use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement in project intellij-community by JetBrains.
the class GroovyChangeUtilSupport method encodeInformation.
@Override
public void encodeInformation(final TreeElement element, final ASTNode original, final Map<Object, Object> encodingState) {
if (original instanceof CompositeElement) {
if (original.getElementType() == GroovyElementTypes.REFERENCE_ELEMENT || original.getElementType() == GroovyElementTypes.REFERENCE_EXPRESSION) {
PsiElement psi = original.getPsi();
Project project = psi.getProject();
if (!PsiUtil.isThisOrSuperRef(psi) && project.isInitialized() && !DumbService.isDumb(project)) {
final GroovyResolveResult result = ((GrReferenceElement) psi).advancedResolve();
if (result != null) {
final PsiElement target = result.getElement();
if (target instanceof PsiClass || (target instanceof PsiMethod || target instanceof PsiField) && ((PsiMember) target).hasModifierProperty(PsiModifier.STATIC) && result.getCurrentFileResolveContext() instanceof GrImportStatement) {
element.putCopyableUserData(REFERENCED_MEMBER_KEY, (PsiMember) target);
}
}
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement in project intellij-community by JetBrains.
the class GroovyFoldingBuilder method processImports.
private static void processImports(final List<FoldingDescriptor> descriptors, GrImportStatement[] imports) {
if (imports.length < 2)
return;
PsiElement first = imports[0];
while (first != null) {
PsiElement marker = first;
PsiElement next = first.getNextSibling();
while (next instanceof GrImportStatement || next instanceof LeafPsiElement) {
if (next instanceof GrImportStatement)
marker = next;
next = next.getNextSibling();
}
if (marker != first) {
int start = first.getTextRange().getStartOffset();
int end = marker.getTextRange().getEndOffset();
int tail = "import ".length();
if (start + tail < end && !JavaFoldingBuilderBase.hasErrorElementsNearby(first.getContainingFile(), start, end)) {
FoldingDescriptor descriptor = new FoldingDescriptor(first.getNode(), new TextRange(start + tail, end));
// imports are often added/removed automatically, so we enable autoupdate of folded region for foldings even if it's collapsed
descriptor.setCanBeRemovedWhenCollapsed(true);
descriptors.add(descriptor);
}
}
while (!(next instanceof GrImportStatement) && next != null) next = next.getNextSibling();
first = next;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement in project intellij-community by JetBrains.
the class ControlFlowBuilderUtil method findClassByText.
private static boolean findClassByText(GrReferenceExpression ref) {
final String text = ref.getText();
final int i = text.indexOf('<');
String className = i == -1 ? text : text.substring(0, i);
PsiClass[] names = PsiShortNamesCache.getInstance(ref.getProject()).getClassesByName(className, ref.getResolveScope());
if (names.length > 0)
return true;
PsiFile file = ref.getContainingFile();
if (file instanceof GroovyFile) {
GrImportStatement[] imports = ((GroovyFile) file).getImportStatements();
for (GrImportStatement anImport : imports) {
if (className.equals(anImport.getImportedName()))
return true;
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement 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.toplevel.imports.GrImportStatement 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;
}
Aggregations