use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class RenameGroovyPropertyProcessor method prepareRenaming.
@Override
public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames) {
LOG.assertTrue(element instanceof PropertyForRename);
final List<? extends PsiElement> elementsToRename = ((PropertyForRename) element).getElementsToRename();
for (PsiElement psiElement : elementsToRename) {
if (psiElement instanceof GrField) {
allRenames.put(psiElement, newName);
} else if (psiElement instanceof GrMethod) {
if (GroovyPropertyUtils.isSimplePropertyGetter((PsiMethod) psiElement)) {
allRenames.put(psiElement, RenamePropertyUtil.getGetterNameByOldName(newName, ((PsiMethod) psiElement).getName()));
} else {
allRenames.put(psiElement, GroovyPropertyUtils.getSetterName(newName));
}
}
}
allRenames.remove(element);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GrDocParameterReferenceImpl method multiResolve.
@Override
@NotNull
public ResolveResult[] multiResolve(boolean incompleteCode) {
final String name = getName();
if (name == null)
return ResolveResult.EMPTY_ARRAY;
ArrayList<GroovyResolveResult> candidates = new ArrayList<>();
final PsiElement owner = GrDocCommentUtil.findDocOwner(this);
if (owner instanceof GrMethod) {
final GrMethod method = (GrMethod) owner;
final GrParameter[] parameters = method.getParameters();
for (GrParameter parameter : parameters) {
if (name.equals(parameter.getName())) {
candidates.add(new GroovyResolveResultImpl(parameter, true));
}
}
return candidates.toArray(new ResolveResult[candidates.size()]);
} else {
final PsiElement firstChild = getFirstChild();
if (owner instanceof GrTypeParameterListOwner && firstChild != null) {
final ASTNode node = firstChild.getNode();
if (node != null && GroovyDocTokenTypes.mGDOC_TAG_VALUE_LT.equals(node.getElementType())) {
final PsiTypeParameter[] typeParameters = ((PsiTypeParameterListOwner) owner).getTypeParameters();
for (PsiTypeParameter typeParameter : typeParameters) {
if (name.equals(typeParameter.getName())) {
candidates.add(new GroovyResolveResultImpl(typeParameter, true));
}
}
}
}
}
return ResolveResult.EMPTY_ARRAY;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class ControlFlowBuilderUtil method isCertainlyReturnStatement.
/**
* check whether statement is return (the statement which provides return value) statement of method or closure.
*
* @param st
* @return
*/
public static boolean isCertainlyReturnStatement(GrStatement st) {
final PsiElement parent = st.getParent();
if (parent instanceof GrOpenBlock) {
if (st != ArrayUtil.getLastElement(((GrOpenBlock) parent).getStatements()))
return false;
PsiElement pparent = parent.getParent();
if (pparent instanceof GrMethod) {
return true;
}
if (pparent instanceof GrBlockStatement || pparent instanceof GrCatchClause || pparent instanceof GrLabeledStatement) {
pparent = pparent.getParent();
}
if (pparent instanceof GrIfStatement || pparent instanceof GrControlStatement || pparent instanceof GrTryCatchStatement) {
return isCertainlyReturnStatement((GrStatement) pparent);
}
} else if (parent instanceof GrClosableBlock) {
return st == ArrayUtil.getLastElement(((GrClosableBlock) parent).getStatements());
} else if (parent instanceof GroovyFileBase) {
return st == ArrayUtil.getLastElement(((GroovyFileBase) parent).getStatements());
} else if (parent instanceof GrForStatement || parent instanceof GrIfStatement && st != ((GrIfStatement) parent).getCondition() || parent instanceof GrSynchronizedStatement && st != ((GrSynchronizedStatement) parent).getMonitor() || parent instanceof GrWhileStatement && st != ((GrWhileStatement) parent).getCondition() || parent instanceof GrConditionalExpression && st != ((GrConditionalExpression) parent).getCondition() || parent instanceof GrElvisExpression) {
return isCertainlyReturnStatement((GrStatement) parent);
} else if (parent instanceof GrCaseSection) {
final GrStatement[] statements = ((GrCaseSection) parent).getStatements();
final GrStatement last = ArrayUtil.getLastElement(statements);
final GrSwitchStatement switchStatement = (GrSwitchStatement) parent.getParent();
if (last instanceof GrBreakStatement && statements.length > 1 && statements[statements.length - 2] == st) {
return isCertainlyReturnStatement(switchStatement);
} else if (st == last) {
if (st instanceof GrBreakStatement || isLastStatementInCaseSection((GrCaseSection) parent, switchStatement)) {
return isCertainlyReturnStatement(switchStatement);
}
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GdkMethodUtil method processMixinToMetaclass.
public static boolean processMixinToMetaclass(GrStatementOwner run, final PsiScopeProcessor processor, ResolveState state, PsiElement lastParent, PsiElement place) {
GrStatement[] statements = run.getStatements();
for (GrStatement statement : statements) {
if (statement == lastParent)
break;
final Trinity<PsiClassType, GrReferenceExpression, PsiClass> result = getMixinTypes(statement);
if (result != null) {
final PsiClassType subjectType = result.first;
final GrReferenceExpression qualifier = result.second;
final PsiClass mixin = result.third;
for (PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(processor)) {
if (!mixin.processDeclarations(new MixinMemberContributor.MixinProcessor(each, subjectType, qualifier), state, null, place)) {
return false;
}
}
} else {
Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>> closureResult = getClosureMixins(statement);
if (closureResult != null) {
final PsiClassType subjectType = closureResult.first;
final GrReferenceExpression qualifier = closureResult.second;
final List<GrMethod> methods = closureResult.third;
final DelegatingScopeProcessor delegate = new MixinMemberContributor.MixinProcessor(processor, subjectType, qualifier);
for (GrMethod method : methods) {
ResolveUtil.processElement(delegate, method, state);
}
}
}
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GroovyPropertyUtils method generateGetterPrototype.
public static GrMethod generateGetterPrototype(PsiField field) {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(field.getProject());
String name = field.getName();
String getName = getGetterNameNonBoolean(field.getName());
try {
PsiType type = field instanceof GrField ? ((GrField) field).getDeclaredType() : field.getType();
GrMethod getter = factory.createMethod(getName, type);
if (field.hasModifierProperty(PsiModifier.STATIC)) {
PsiUtil.setModifierProperty(getter, PsiModifier.STATIC, true);
}
annotateWithNullableStuff(field, getter);
GrCodeBlock body = factory.createMethodBodyFromText("\nreturn " + name + "\n");
getter.getBlock().replace(body);
return getter;
} catch (IncorrectOperationException e) {
LOG.error(e);
return null;
}
}
Aggregations