use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GdkMethodUtil method getClosureMixins.
private static Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>> getClosureMixins(final GrStatement statement) {
if (!(statement instanceof GrAssignmentExpression))
return null;
final GrAssignmentExpression assignment = (GrAssignmentExpression) statement;
return CachedValuesManager.getCachedValue(statement, new CachedValueProvider<Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>>>() {
@Nullable
@Override
public Result<Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>>> compute() {
Pair<PsiClassType, GrReferenceExpression> original = getTypeToMixIn(assignment);
if (original == null)
return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
final Pair<GrSignature, String> signatures = getTypeToMix(assignment);
if (signatures == null)
return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
final String name = signatures.second;
final List<GrMethod> methods = ContainerUtil.newArrayList();
final PsiClass closure = JavaPsiFacade.getInstance(statement.getProject()).findClass(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, statement.getResolveScope());
if (closure == null)
return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
signatures.first.accept(new GrSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
super.visitClosureSignature(signature);
GrMethod method = createMethod(signature, name, assignment, closure);
methods.add(method);
}
});
return Result.create(Trinity.create(original.first, original.second, methods), PsiModificationTracker.MODIFICATION_COUNT);
}
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class ResolveUtil method findDuplicate.
public static PsiNamedElement findDuplicate(@NotNull GrVariable variable) {
if (isScriptField(variable)) {
final String name = variable.getName();
final GroovyScriptClass script = (GroovyScriptClass) ((GroovyFile) variable.getContainingFile()).getScriptClass();
assert script != null;
List<GrField> duplicates = ContainerUtil.filter(script.getFields(), (GrField f) -> {
if (!(f instanceof GrScriptField))
return false;
if (!name.equals(f.getName()))
return false;
if (((GrScriptField) f).getOriginalVariable() == variable)
return false;
return true;
});
return duplicates.size() > 0 ? duplicates.get(0) : null;
} else {
PsiNamedElement duplicate = resolveExistingElement(variable, new DuplicateVariablesProcessor(variable), GrVariable.class);
final PsiElement context1 = variable.getContext();
if (duplicate == null && variable instanceof GrParameter && context1 != null) {
final PsiElement context = context1.getContext();
if (context instanceof GrClosableBlock || context instanceof GrMethod && !(context.getParent() instanceof GroovyFile) || context instanceof GrTryCatchStatement) {
duplicate = resolveExistingElement(context.getParent(), new DuplicateVariablesProcessor(variable), GrVariable.class);
}
}
if (duplicate instanceof GrLightParameter && "args".equals(duplicate.getName())) {
return null;
} else {
return duplicate;
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GroovyResolverProcessorImpl method collapseReflectedMethods.
private static List<GroovyResolveResult> collapseReflectedMethods(Collection<GroovyResolveResult> candidates) {
Set<GrMethod> visited = ContainerUtil.newHashSet();
List<GroovyResolveResult> collapsed = ContainerUtil.newArrayList();
for (GroovyResolveResult result : candidates) {
PsiElement element = result.getElement();
if (element instanceof GrReflectedMethod) {
GrMethod baseMethod = ((GrReflectedMethod) element).getBaseMethod();
if (visited.add(baseMethod)) {
collapsed.add(PsiImplUtil.reflectedToBase(result, baseMethod, (GrReflectedMethod) element));
}
} else {
collapsed.add(result);
}
}
return collapsed;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GroovyLanguageInjectionSupport method doInject.
private static boolean doInject(@NotNull String languageId, @NotNull PsiElement psiElement, @NotNull PsiLanguageInjectionHost host) {
final PsiElement target = getTopLevelInjectionTarget(psiElement);
final PsiElement parent = target.getParent();
final Project project = psiElement.getProject();
if (parent instanceof GrReturnStatement) {
final GrControlFlowOwner owner = ControlFlowUtils.findControlFlowOwner(parent);
if (owner instanceof GrOpenBlock && owner.getParent() instanceof GrMethod) {
return JavaLanguageInjectionSupport.doInjectInJavaMethod(project, (PsiMethod) owner.getParent(), -1, host, languageId);
}
} else if (parent instanceof GrMethod) {
return JavaLanguageInjectionSupport.doInjectInJavaMethod(project, (GrMethod) parent, -1, host, languageId);
} else if (parent instanceof GrAnnotationNameValuePair) {
final PsiReference ref = parent.getReference();
if (ref != null) {
final PsiElement resolved = ref.resolve();
if (resolved instanceof PsiMethod) {
return JavaLanguageInjectionSupport.doInjectInJavaMethod(project, (PsiMethod) resolved, -1, host, languageId);
}
}
} else if (parent instanceof GrArgumentList && parent.getParent() instanceof GrMethodCall) {
final PsiMethod method = ((GrMethodCall) parent.getParent()).resolveMethod();
if (method != null) {
final int index = GrInjectionUtil.findParameterIndex(target, ((GrMethodCall) parent.getParent()));
if (index >= 0) {
return JavaLanguageInjectionSupport.doInjectInJavaMethod(project, method, index, host, languageId);
}
}
} else if (parent instanceof GrAssignmentExpression) {
final GrExpression expr = ((GrAssignmentExpression) parent).getLValue();
if (expr instanceof GrReferenceExpression) {
final PsiElement element = ((GrReferenceExpression) expr).resolve();
if (element != null) {
return doInject(languageId, element, host);
}
}
} else {
if (parent instanceof PsiVariable) {
Processor<PsiLanguageInjectionHost> fixer = getAnnotationFixer(project, languageId);
if (JavaLanguageInjectionSupport.doAddLanguageAnnotation(project, (PsiModifierListOwner) parent, host, languageId, fixer))
return true;
} else if (target instanceof PsiVariable && !(target instanceof LightElement)) {
Processor<PsiLanguageInjectionHost> fixer = getAnnotationFixer(project, languageId);
if (JavaLanguageInjectionSupport.doAddLanguageAnnotation(project, (PsiModifierListOwner) target, host, languageId, fixer))
return true;
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GrFinalVariableAccessInspection method appendInitializationFromChainedConstructors.
private static void appendInitializationFromChainedConstructors(@NotNull GrMethod constructor, @NotNull List<GrField> fields, @NotNull Set<GrVariable> initializedFields) {
final List<GrMethod> chained = getChainedConstructors(constructor);
chained.remove(0);
for (GrMethod method : chained) {
final GrOpenBlock block = method.getBlock();
if (block == null)
continue;
final Instruction[] flow = buildFlowForField(block);
for (GrField field : fields) {
if (!field.hasModifierProperty(PsiModifier.STATIC) && !initializedFields.contains(field) && VariableInitializationChecker.isVariableDefinitelyInitializedCached(field, block, flow)) {
initializedFields.add(field);
}
}
}
}
Aggregations