use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class GrListOrMapImpl method deleteChildInternal.
@Override
public void deleteChildInternal(@NotNull ASTNode child) {
final PsiElement psi = child.getPsi();
if (psi instanceof GrExpression || psi instanceof GrNamedArgument) {
PsiElement prev = PsiUtil.getPrevNonSpace(psi);
PsiElement next = PsiUtil.getNextNonSpace(psi);
if (prev != null && prev.getNode() != null && prev.getNode().getElementType() == GroovyTokenTypes.mCOMMA) {
super.deleteChildInternal(prev.getNode());
} else if (next instanceof LeafPsiElement && next.getNode() != null && next.getNode().getElementType() == GroovyTokenTypes.mCOMMA) {
super.deleteChildInternal(next.getNode());
}
}
super.deleteChildInternal(child);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class GrArgumentListImpl method addNamedArgument.
@Override
public GrNamedArgument addNamedArgument(final GrNamedArgument namedArgument) {
final GrNamedArgument[] namedArguments = getNamedArguments();
final GrExpression[] args = getExpressionArguments();
PsiElement anchor = null;
final int namedCount = namedArguments.length;
final int exprCount = args.length;
if (namedCount > 0) {
anchor = namedArguments[namedCount - 1];
} else if (exprCount > 0) {
anchor = args[exprCount - 1];
}
if (anchor != null) {
anchor = PsiUtil.getNextNonSpace(anchor);
} else {
anchor = getRightParen();
}
addBefore(namedArgument, anchor);
return namedArgument;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class GrArgumentListImpl method deleteChildInternal.
@Override
public void deleteChildInternal(@NotNull ASTNode child) {
PsiElement element = child.getPsi();
if (element instanceof GrExpression || element instanceof GrNamedArgument) {
ASTNode prev = TreeUtil.skipElementsBack(child.getTreePrev(), TokenSets.WHITE_SPACES_OR_COMMENTS);
if (prev != null && prev.getElementType() == GroovyTokenTypes.mCOMMA) {
final ASTNode pprev = prev.getTreePrev();
if (pprev != null && PsiImplUtil.isWhiteSpaceOrNls(pprev)) {
super.deleteChildInternal(pprev);
}
super.deleteChildInternal(prev);
} else {
ASTNode next = TreeUtil.skipElements(child.getTreeNext(), TokenSets.WHITE_SPACES_OR_COMMENTS);
if (next != null && next.getElementType() == GroovyTokenTypes.mCOMMA) {
final ASTNode nnext = next.getTreeNext();
if (nnext != null && PsiImplUtil.isWhiteSpaceOrNls(nnext)) {
super.deleteChildInternal(nnext);
}
super.deleteChildInternal(next);
}
}
}
super.deleteChildInternal(child);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class MyPredicate method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull final Project project, Editor editor) throws IncorrectOperationException {
final GrListOrMap map = (GrListOrMap) element;
final GrNamedArgument[] namedArguments = map.getNamedArguments();
LOG.assertTrue(map.getInitializers().length == 0);
final PsiFile file = map.getContainingFile();
final String packageName = file instanceof GroovyFileBase ? ((GroovyFileBase) file).getPackageName() : "";
final CreateClassDialog dialog = new CreateClassDialog(project, GroovyBundle.message("create.class.family.name"), "", packageName, GrCreateClassKind.CLASS, true, ModuleUtilCore.findModuleForPsiElement(element));
dialog.show();
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE)
return;
boolean replaceReturnType = checkForReturnFromMethod(map);
boolean variableDeclaration = checkForVariableDeclaration(map);
final GrParameter methodParameter = checkForMethodParameter(map);
final String qualifiedClassName = dialog.getClassName();
final String selectedPackageName = StringUtil.getPackageName(qualifiedClassName);
final String shortName = StringUtil.getShortName(qualifiedClassName);
final GrTypeDefinition typeDefinition = createClass(project, namedArguments, selectedPackageName, shortName);
final PsiClass generatedClass = CreateClassActionBase.createClassByType(dialog.getTargetDirectory(), typeDefinition.getName(), PsiManager.getInstance(project), map, GroovyTemplates.GROOVY_CLASS, true);
final PsiClass replaced = (PsiClass) generatedClass.replace(typeDefinition);
replaceMapWithClass(project, map, replaced, replaceReturnType, variableDeclaration, methodParameter);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class MyPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrListOrMap))
return false;
final GrListOrMap map = (GrListOrMap) element;
final GrNamedArgument[] namedArguments = map.getNamedArguments();
final GrExpression[] initializers = map.getInitializers();
if (initializers.length != 0)
return false;
for (GrNamedArgument argument : namedArguments) {
final GrArgumentLabel label = argument.getLabel();
final GrExpression expression = argument.getExpression();
if (label == null || expression == null)
return false;
if (label.getName() == null)
return false;
}
return true;
}
Aggregations