use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression in project intellij-community by JetBrains.
the class GroovyClassNameInsertHandler method findNewExpression.
@Nullable
private static GrNewExpression findNewExpression(@Nullable PsiElement position) {
if (position == null)
return null;
final PsiElement reference = position.getParent();
if (!(reference instanceof GrCodeReferenceElement))
return null;
PsiElement parent = reference.getParent();
while (parent instanceof GrCodeReferenceElement) parent = parent.getParent();
if (parent instanceof GrAnonymousClassDefinition)
parent = parent.getParent();
return parent instanceof GrNewExpression ? (GrNewExpression) parent : null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression in project intellij-community by JetBrains.
the class GroovyTargetElementEvaluator method getElementByReference.
@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
PsiElement sourceElement = ref.getElement();
if (sourceElement instanceof GrCodeReferenceElement) {
GrNewExpression newExpr;
if (sourceElement.getParent() instanceof GrNewExpression) {
newExpr = (GrNewExpression) sourceElement.getParent();
} else if (sourceElement.getParent().getParent() instanceof GrNewExpression) {
//anonymous class declaration
newExpr = (GrNewExpression) sourceElement.getParent().getParent();
} else {
return null;
}
final PsiMethod constructor = newExpr.resolveMethod();
final GrArgumentList argumentList = newExpr.getArgumentList();
if (constructor != null && argumentList != null && PsiImplUtil.hasNamedArguments(argumentList) && !PsiImplUtil.hasExpressionArguments(argumentList)) {
if (constructor.getParameterList().getParametersCount() == 0)
return constructor.getContainingClass();
}
return constructor;
}
if (sourceElement instanceof GrReferenceExpression) {
PsiElement resolved = ((GrReferenceExpression) sourceElement).resolve();
if (resolved instanceof GrGdkMethod || !(resolved instanceof GrRenameableLightElement)) {
return correctSearchTargets(resolved);
}
return resolved;
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression in project intellij-community by JetBrains.
the class ConvertJavaStyleArrayIntention method getElementPredicate.
@NotNull
@Override
protected PsiElementPredicate getElementPredicate() {
return new PsiElementPredicate() {
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrMethodCallExpression))
return false;
final GrExpression expression = ((GrMethodCallExpression) element).getInvokedExpression();
if (!(expression instanceof GrNewExpression))
return false;
if (((GrNewExpression) expression).getArrayCount() == 0)
return false;
if (!((GrMethodCallExpression) element).getArgumentList().getText().trim().isEmpty())
return false;
final GrClosableBlock[] closureArguments = ((GrMethodCallExpression) element).getClosureArguments();
if (closureArguments.length != 1)
return false;
final GrClosableBlock block = closureArguments[0];
if (block.getLBrace() == null || block.getRBrace() == null)
return false;
return true;
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression in project intellij-community by JetBrains.
the class GrTypeDefinitionRangeHandler method getDeclarationRange.
@NotNull
@Override
public TextRange getDeclarationRange(@NotNull GrTypeDefinition aClass) {
if (aClass instanceof GrAnonymousClassDefinition) {
GrNewExpression call = (GrNewExpression) aClass.getParent();
int startOffset = call.getTextRange().getStartOffset();
int endOffset = call.getArgumentList().getTextRange().getEndOffset();
return new TextRange(startOffset, endOffset);
} else {
final PsiModifierList modifierList = aClass.getModifierList();
int startOffset = modifierList == null ? aClass.getTextRange().getStartOffset() : modifierList.getTextRange().getStartOffset();
final GrImplementsClause implementsList = aClass.getImplementsClause();
int endOffset = implementsList == null ? aClass.getTextRange().getEndOffset() : implementsList.getTextRange().getEndOffset();
return new TextRange(startOffset, endOffset);
}
}
Aggregations