use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GrAliasImportIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
GrImportStatement context;
final PsiMember resolved;
if (element instanceof GrReferenceExpression) {
GrReferenceExpression ref = (GrReferenceExpression) element;
GroovyResolveResult result = ref.advancedResolve();
context = (GrImportStatement) result.getCurrentFileResolveContext();
assert context != null;
resolved = (PsiMember) result.getElement();
} else if (element instanceof GrImportStatement) {
context = (GrImportStatement) element;
resolved = (PsiMember) context.getImportReference().resolve();
} else {
return;
}
assert resolved != null;
doRefactoring(project, context, resolved);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GrAliasImportIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
if (element instanceof GrReferenceExpression) {
GroovyResolveResult result = ((GrReferenceExpression) element).advancedResolve();
PsiElement context = result.getCurrentFileResolveContext();
if (!(context instanceof GrImportStatement))
return false;
GrImportStatement importStatement = (GrImportStatement) context;
if (!importStatement.isStatic() || importStatement.isAliasedImport())
return false;
return true;
} else if (element instanceof GrImportStatement) {
final GrImportStatement importStatement = (GrImportStatement) element;
if (!importStatement.isStatic())
return false;
if (importStatement.isOnDemand())
return false;
if (importStatement.isAliasedImport())
return false;
return true;
}
return false;
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class MoveGroovyClassHandler method preprocessUsages.
@Override
public void preprocessUsages(Collection<UsageInfo> results) {
//remove all alias-imported usages from collection
for (Iterator<UsageInfo> iterator = results.iterator(); iterator.hasNext(); ) {
UsageInfo info = iterator.next();
if (info == null) {
LOG.debug("info==null");
continue;
}
final PsiReference ref = info.getReference();
if (ref == null)
continue;
final PsiElement element = ref.getElement();
if (!(element instanceof GrReferenceElement))
continue;
final GroovyResolveResult resolveResult = ((GrReferenceElement) element).advancedResolve();
final PsiElement context = resolveResult.getCurrentFileResolveContext();
if (!(context instanceof GrImportStatement))
continue;
if (!((GrImportStatement) context).isAliasedImport())
continue;
iterator.remove();
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GrIntroduceClosureParameterProcessor method removeParametersFromCall.
private static void removeParametersFromCall(GrMethodCallExpression methodCall, GrIntroduceParameterSettings settings) {
final GroovyResolveResult resolveResult = methodCall.advancedResolve();
final PsiElement resolved = resolveResult.getElement();
LOG.assertTrue(resolved instanceof PsiMethod);
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature((PsiMethod) resolved, resolveResult.getSubstitutor());
final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, methodCall);
LOG.assertTrue(argInfos != null);
settings.parametersToRemove().forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
final List<PsiElement> args = argInfos[value].args;
for (PsiElement arg : args) {
arg.delete();
}
return true;
}
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class RenameAliasedUsagesUtil method findAliasedName.
private static String findAliasedName(Map<GroovyFile, String> map, GroovyFile containingFile, PsiElement elementToResolve) {
final String s = map.get(containingFile);
if (s != null)
return s;
final GrImportStatement[] imports = containingFile.getImportStatements();
final PsiManager manager = elementToResolve.getManager();
for (GrImportStatement anImport : imports) {
if (anImport.isAliasedImport()) {
final ResolverProcessor processor = getProcessor(elementToResolve, containingFile);
anImport.processDeclarations(processor, ResolveState.initial(), null, containingFile);
final GroovyResolveResult[] results = processor.getCandidates();
for (GroovyResolveResult result : results) {
if (manager.areElementsEquivalent(elementToResolve, result.getElement())) {
final String importedName = anImport.getImportedName();
if (importedName != null) {
map.put(containingFile, importedName);
return importedName;
}
}
}
}
}
map.put(containingFile, EMPTY_ALIAS);
return EMPTY_ALIAS;
}
Aggregations