use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter 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.params.GrParameter in project intellij-community by JetBrains.
the class ParameterToMapEntryTest method doTestImpl.
private void doTestImpl(String filePath) {
myFixture.configureByFile(filePath);
int offset = myFixture.getEditor().getCaretModel().getOffset();
final PsiFile file = myFixture.getFile();
final ConvertParameterToMapEntryIntention intention = new ConvertParameterToMapEntryIntention();
PsiElement element = file.findElementAt(offset);
while (element != null && !(element instanceof GrReferenceExpression || element instanceof GrParameter)) {
element = element.getParent();
}
Assert.assertNotNull(element);
final PsiElementPredicate condition = intention.getElementPredicate();
Assert.assertTrue(condition.satisfiedBy(element));
// Launch it!
intention.processIntention(element, myFixture.getProject(), myFixture.getEditor());
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
final String result = file.getText();
//System.out.println(result);
myFixture.checkResultByFile(filePath.replace(".groovy", ".test"), true);
// String expected = getExpectedResult(filePath);
// Assert.assertEquals(expected, result);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter 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.params.GrParameter in project intellij-community by JetBrains.
the class GrNamedArgumentSearchVisitor method find.
public static Map<String, NamedArgumentDescriptor> find(GrVariable variable) {
final GrExpression initializerGroovy = variable.getInitializerGroovy();
if (!(initializerGroovy instanceof GrClosableBlock)) {
return Collections.emptyMap();
}
final GrClosableBlock closure = (GrClosableBlock) initializerGroovy;
final GrParameter[] parameters = closure.getAllParameters();
if (parameters.length == 0)
return Collections.emptyMap();
GrParameter parameter = parameters[0];
GrNamedArgumentSearchVisitor visitor = new GrNamedArgumentSearchVisitor(parameter.getName());
closure.accept(visitor);
return visitor.getResult();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter in project intellij-community by JetBrains.
the class ControlFlowBuilder method visitClosure.
@Override
public void visitClosure(@NotNull GrClosableBlock closure) {
//do not go inside closures except gstring injections
if (closure.getParent() instanceof GrStringInjection) {
for (GrParameter parameter : closure.getAllParameters()) {
if (myPolicy.isVariableInitialized(parameter)) {
addNode(new ReadWriteVariableInstruction(parameter.getName(), parameter, ReadWriteVariableInstruction.WRITE));
}
}
addNode(new ReadWriteVariableInstruction("owner", closure.getLBrace(), ReadWriteVariableInstruction.WRITE));
super.visitClosure(closure);
return;
}
ReadWriteVariableInstruction[] reads = ControlFlowBuilderUtil.getReadsWithoutPriorWrites(closure.getControlFlow(), false);
for (ReadWriteVariableInstruction read : reads) {
PsiElement element = read.getElement();
if (!(element instanceof GrReferenceExpression) || myPolicy.isReferenceAccepted((GrReferenceExpression) element)) {
addNodeAndCheckPending(new ReadWriteVariableInstruction(read.getVariableName(), closure, ReadWriteVariableInstruction.READ));
}
}
addNodeAndCheckPending(new InstructionImpl(closure));
}
Aggregations