use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap in project intellij-community by JetBrains.
the class LiteralConstructorReference method inferConversionType.
@Nullable
private PsiClassType inferConversionType() {
final GrListOrMap listOrMap = getElement();
final PsiClassType conversionType = getTargetConversionType(listOrMap);
if (conversionType == null)
return null;
if (listOrMap.isEmpty()) {
PsiType unboxed = TypesUtil.unboxPrimitiveTypeWrapper(conversionType);
if (PsiType.BOOLEAN.equals(unboxed) || PsiType.CHAR.equals(unboxed)) {
return null;
}
}
final PsiType type = listOrMap.getType();
final PsiType ownType = type instanceof PsiClassType ? ((PsiClassType) type).rawType() : type;
if (ownType != null && TypesUtil.isAssignableWithoutConversions(conversionType.rawType(), ownType, listOrMap))
return null;
final PsiClass resolved = conversionType.resolve();
if (resolved != null) {
if (InheritanceUtil.isInheritor(resolved, CommonClassNames.JAVA_UTIL_SET))
return null;
if (InheritanceUtil.isInheritor(resolved, CommonClassNames.JAVA_UTIL_LIST))
return null;
}
return conversionType;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap in project intellij-community by JetBrains.
the class GrVariableBaseImpl method getInitializerGroovy.
@Override
@Nullable
public GrExpression getInitializerGroovy() {
final PsiElement parent = getParent();
if (parent instanceof GrVariableDeclaration && ((GrVariableDeclaration) parent).isTuple()) {
final GrVariableDeclaration tuple = (GrVariableDeclaration) parent;
final GrExpression initializer = tuple.getTupleInitializer();
if (initializer instanceof GrListOrMap) {
final GrListOrMap listOrMap = (GrListOrMap) initializer;
final GrExpression[] initializers = listOrMap.getInitializers();
final int varNumber = ArrayUtil.indexOf(tuple.getVariables(), this);
if (initializers.length < varNumber + 1)
return null;
return initializers[varNumber];
}
}
return GroovyPsiElementImpl.findExpressionChild(this);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap in project intellij-community by JetBrains.
the class GrSplitDeclarationIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
if (!(element instanceof GrVariableDeclaration))
return;
GrVariableDeclaration declaration = (GrVariableDeclaration) element;
GrVariable[] variables = declaration.getVariables();
if (variables.length == 1) {
processSingleVar(project, declaration, variables[0]);
} else if (variables.length > 1) {
if (!declaration.isTuple() || declaration.getTupleInitializer() instanceof GrListOrMap) {
processMultipleVars(project, declaration);
} else {
processTuple(project, declaration);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap 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.auxiliary.GrListOrMap 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