use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement in project intellij-community by JetBrains.
the class GroovyMoveClassToInnerHandler method filterUsagesInImportStatements.
private static void filterUsagesInImportStatements(final List<UsageInfo> usages, final List<PsiElement> importStatements) {
for (Iterator<UsageInfo> iterator = usages.iterator(); iterator.hasNext(); ) {
UsageInfo usage = iterator.next();
PsiElement element = usage.getElement();
if (element == null)
continue;
GrImportStatement stmt = PsiTreeUtil.getParentOfType(element, GrImportStatement.class);
if (stmt != null) {
importStatements.add(stmt);
iterator.remove();
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement in project intellij-community by JetBrains.
the class GroovyCodeFragment method importsToString.
/**
* @return list of imports in format "qname[:imported_name](,qname[:imported_name])*"
*/
@Override
public String importsToString() {
if (myPseudoImports.isEmpty())
return "";
StringBuilder buffer = new StringBuilder();
for (Map.Entry<String, GrImportStatement> entry : myPseudoImports.entrySet()) {
final String importedName = entry.getKey();
final GrImportStatement anImport = entry.getValue();
//buffer.append(anImport.isStatic() ? "+" : "-");
final String qname = anImport.getImportReference().getClassNameText();
buffer.append(qname);
buffer.append(':').append(importedName);
buffer.append(',');
}
for (GrImportStatement anImport : myOnDemandImports) {
//buffer.append(anImport.isStatic() ? "+" : "-");
String packName = anImport.getImportReference().getClassNameText();
buffer.append(packName);
buffer.append(',');
}
buffer.deleteCharAt(buffer.length() - 1);
return buffer.toString();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement in project intellij-community by JetBrains.
the class GroovyFileImpl method buildDeclarationCache.
@NotNull
private MostlySingularMultiMap<String, ResultWithContext> buildDeclarationCache() {
MostlySingularMultiMap<String, ResultWithContext> results = new MostlySingularMultiMap<>();
processDeclarationsNoGuess(new BaseScopeProcessor() {
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (element instanceof PsiNamedElement) {
PsiElement context = state.get(ClassHint.RESOLVE_CONTEXT);
String name = getDeclarationName((PsiNamedElement) element, context);
if (name != null) {
results.add(name, new ResultWithContext((PsiNamedElement) element, context));
}
}
return true;
}
private String getDeclarationName(@NotNull PsiNamedElement element, @Nullable PsiElement context) {
String name = context instanceof GrImportStatement ? ((GrImportStatement) context).getImportedName() : null;
return name != null ? name : element.getName();
}
}, ResolveState.initial(), null, this);
return results;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement in project intellij-community by JetBrains.
the class GroovyFileImpl method addImportForClass.
@Override
public GrImportStatement addImportForClass(@NotNull PsiClass aClass) {
try {
// Calculating position
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(getProject());
String qname = aClass.getQualifiedName();
if (qname != null) {
GrImportStatement importStatement = factory.createImportStatementFromText(qname, false, false, null);
return addImport(importStatement);
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement in project intellij-community by JetBrains.
the class GrAliasImportIntention method doRefactoring.
private static void doRefactoring(@NotNull Project project, @NotNull GrImportStatement importStatement, @NotNull PsiMember member) {
if (member instanceof GrAccessorMethod && !importStatement.isOnDemand() && !importStatement.getImportedName().equals(member.getName())) {
member = ((GrAccessorMethod) member).getProperty();
}
final GroovyFileBase file = (GroovyFileBase) importStatement.getContainingFile();
final List<UsageInfo> usages = findUsages(member, file);
GrImportStatement templateImport = createTemplateImport(project, importStatement, member, file);
if (ApplicationManager.getApplication().isUnitTestMode()) {
if (!importStatement.isOnDemand()) {
importStatement.delete();
}
updateRefs(usages, member.getName(), templateImport);
} else {
runTemplate(project, importStatement, member, file, usages, templateImport);
}
}
Aggregations