Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
32,000
GrReferenceExpression () { GrMethodCall methodCall = myMethodCall.getElement(); if (methodCall == null) return null; return getMethodExpression(methodCall); }
getMethodExpression
32,001
GrReferenceExpression (@NotNull GrMethodCall call) { GrExpression result = call.getInvokedExpression(); return result instanceof GrReferenceExpression ? (GrReferenceExpression)result : null; }
getMethodExpression
32,002
boolean (@NotNull Project project, Editor editor, PsiFile file) { myCandidates = null; if (!file.getManager().isInProject(file)) return false; GrReferenceExpression invokedExpression = getMethodExpression(); if (invokedExpression == null || invokedExpression.getQualifierExpression() != null) return false; return !getCandidates().isEmpty(); }
isAvailable
32,003
List<PsiMethod> () { PsiShortNamesCache cache = PsiShortNamesCache.getInstance(myMethodCall.getProject()); GrMethodCall element = myMethodCall.getElement(); LOG.assertTrue(element != null); GrReferenceExpression reference = getMethodExpression(element); LOG.assertTrue(reference != null); GrArgumentList argumentList = element.getArgumentList(); String name = reference.getReferenceName(); ArrayList<PsiMethod> list = new ArrayList<>(); if (name == null) return list; GlobalSearchScope scope = element.getResolveScope(); PsiMethod[] methods = cache.getMethodsByNameIfNotMoreThan(name, scope, 20); List<PsiMethod> applicableList = new ArrayList<>(); for (PsiMethod method : methods) { ProgressManager.checkCanceled(); if (JavaCompletionUtil.isInExcludedPackage(method, false)) continue; if (!method.hasModifierProperty(PsiModifier.STATIC)) continue; PsiFile file = method.getContainingFile(); if (file instanceof PsiClassOwner //do not show methods from default package && !((PsiClassOwner)file).getPackageName().isEmpty() && PsiUtil.isAccessible(element, method)) { list.add(method); if (PsiUtil.isApplicable(PsiUtil.getArgumentTypes(element, true), method, PsiSubstitutor.EMPTY, element, false)) { applicableList.add(method); } } } List<PsiMethod> result = applicableList.isEmpty() ? list : applicableList; result.sort(new PsiProximityComparator(argumentList)); return result; }
getMethodsToImport
32,004
PsiElementPredicate () { return new PsiElementPredicate() { @Override public boolean satisfiedBy(@NotNull PsiElement element) { return true; } }; }
getElementPredicate
32,005
boolean (@NotNull PsiElement element) { return true; }
satisfiedBy
32,006
void (final PsiMethod toImport) { CommandProcessor.getInstance().executeCommand(toImport.getProject(), () -> WriteAction.run(() -> { try { GrReferenceExpression expression = getMethodExpression(); if (expression != null) { expression.bindToElementViaStaticImport(toImport); } } catch (IncorrectOperationException e) { LOG.error(e); } }), getText(), this); }
doImport
32,007
void (Editor editor) { JBPopupFactory.getInstance() .createPopupChooserBuilder(getCandidates()) .setRenderer(new MethodCellRenderer(true)) .setTitle(QuickFixBundle.message("static.import.method.choose.method.to.import")) .setMovable(true) .setItemChosenCallback((selectedValue) -> { LOG.assertTrue(selectedValue.isValid()); doImport(selectedValue); }) .createPopup() .showInBestPositionFor(editor); }
chooseAndImport
32,008
List<PsiMethod> () { List<PsiMethod> result = myCandidates; if (result == null) { result = getMethodsToImport(); myCandidates = result; } return result; }
getCandidates
32,009
IntentionPreviewInfo (@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) { PsiClass targetClass = myFix.getTargetClass(); final CreateFieldFix fix = new CreateFieldFix(targetClass); String name = getFieldName(); if (name == null) { return IntentionPreviewInfo.EMPTY; } PsiField representation = fix.getFieldRepresentation(targetClass.getProject(), ArrayUtilRt.EMPTY_STRING_ARRAY, name, targetClass, true); PsiElement parent = representation == null ? null : representation.getParent(); if (parent == null) { return IntentionPreviewInfo.EMPTY; } String className = targetClass.getName(); String classKind; if (targetClass.isInterface()) { classKind = "interface"; } else if (targetClass.isEnum()) { classKind = "enum"; } else if (targetClass.isAnnotationType()) { classKind = "@interface"; } else if (targetClass.isRecord()) { classKind = "record"; } else if (targetClass instanceof GrTypeDefinition && ((GrTypeDefinition)targetClass).isTrait()) { classKind = "trait"; } else { classKind = "class"; } return new IntentionPreviewInfo.CustomDiff(GroovyFileType.GROOVY_FILE_TYPE, classKind + " " + className, "", parent.getText()); }
generatePreview
32,010
String () { GrNamedArgument namedArgument = myNamedArgumentPointer.getElement(); if (namedArgument == null) return null; final GrArgumentLabel label = namedArgument.getLabel(); assert label != null; return label.getName(); }
getFieldName
32,011
TypeConstraint[] (@NotNull GrNamedArgument namedArgument) { final GrExpression expression = namedArgument.getExpression(); PsiType type = null; if (expression != null) { type = expression.getType(); } if (type != null) { return new TypeConstraint[]{SupertypeConstraint.create(type, type)}; } else { return TypeConstraint.EMPTY_ARRAY; } }
calculateTypeConstrains
32,012
String () { return GroovyBundle.message("create.field.from.usage", getFieldName()); }
getName
32,013
String () { return GroovyBundle.message("intention.family.name.create.field"); }
getFamilyName
32,014
PsiClass () { return myTargetClass; }
getTargetClass
32,015
String () { return GroovyBundle.message("create.variable.from.usage.family.name"); }
getFamilyName
32,016
String () { return GroovyBundle.message("create.variable.from.usage", myRefExpression.getReferenceName()); }
getText
32,017
boolean (@NotNull Project project, Editor editor, PsiFile file) { return myOwner.isValid() && myRefExpression.isValid(); }
isAvailable
32,018
Editor (Project project, PsiFile targetFile, PsiElement element) { TextRange range = element.getTextRange(); int textOffset = range.getStartOffset(); VirtualFile vFile = targetFile.getVirtualFile(); assert vFile != null; OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile, textOffset); return FileEditorManager.getInstance(project).openTextEditor(descriptor, true); }
positionCursor
32,019
IntentionPreviewInfo (@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { TypeConstraint[] constraints = GroovyExpectedTypesProvider.calculateTypeConstraints(myRefExpression); PsiType type = constraints.length == 0 || constraints[0].getType().equals(PsiTypes.voidType()) ? JavaPsiFacade.getInstance(project).getElementFactory().createTypeByFQClassName("java.lang.Object", GlobalSearchScope.allScope(project)) : constraints[0].getType(); GrVariableDeclaration declaration = GroovyPsiElementFactory.getInstance(project) .createVariableDeclaration(ArrayUtilRt.EMPTY_STRING_ARRAY, "", type, myRefExpression.getReferenceName()); return new IntentionPreviewInfo.CustomDiff(GroovyFileType.GROOVY_FILE_TYPE, "", declaration.getText()); }
generatePreview
32,020
PsiElementPredicate () { return new PsiElementPredicate() { @Override public boolean satisfiedBy(@NotNull PsiElement element) { return myRefExpression.isValid() && myOwner.isValid(); } }; }
getElementPredicate
32,021
boolean (@NotNull PsiElement element) { return myRefExpression.isValid() && myOwner.isValid(); }
satisfiedBy
32,022
GrStatement (PsiFile file, int offset) { PsiElement element = file.findElementAt(offset); if (element == null && offset > 0) element = file.findElementAt(offset - 1); while (element != null) { if (myOwner.equals(element.getParent())) return element instanceof GrStatement ? (GrStatement)element : null; element = element.getParent(); } return null; }
findAnchor
32,023
PsiType[] () { final GrReferenceExpression ref = getRefExpr(); assert PsiUtil.isLValue(ref); PsiType initializer = TypeInferenceHelper.getInitializerTypeFor(ref); if (initializer == null || initializer == PsiTypes.nullType()) { initializer = TypesUtil.getJavaLangObject(ref); } return new PsiType[]{initializer}; }
getArgumentTypes
32,024
String () { return GroovyPropertyUtils.getSetterName(getRefExpr().getReferenceName()); }
getMethodName
32,025
String () { String packName = StringUtil.isEmptyOrSpaces(myPackageName) ? "default package" : myPackageName; return GroovyBundle.message("move.to.correct.dir", packName); }
getName
32,026
IntentionPreviewInfo (@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) { PsiFile file = previewDescriptor.getPsiElement().getContainingFile(); Icon fileIcon = JetgroovyIcons.Groovy.GroovyFile; Icon dirIcon = AllIcons.Nodes.Folder; HtmlBuilder builder = new HtmlBuilder() .append(HtmlChunk.icon("file", fileIcon)) .nbsp() .append(file.getName()) .append(" ").append(HtmlChunk.htmlEntity("&rarr;")).append(" ") .append(HtmlChunk.icon("dir", dirIcon)) .nbsp() .append(myPackageName.replace(".", FileSystems.getDefault().getSeparator())); //NON-NLS return new IntentionPreviewInfo.Html(builder.wrapWith("p")); }
generatePreview
32,027
String () { return GroovyBundle.message("move.to.correct.dir.family.name"); }
getFamilyName
32,028
boolean () { return false; }
startInWriteAction
32,029
String () { String referenceName = myRefElement.getReferenceName(); return switch (getType()) { case TRAIT -> GroovyBundle.message("create.trait", referenceName); case ENUM -> GroovyBundle.message("create.enum", referenceName); case CLASS -> GroovyBundle.message("create.class.text", referenceName); case INTERFACE -> GroovyBundle.message("create.interface.text", referenceName); case ANNOTATION -> GroovyBundle.message("create.annotation.text", referenceName); case RECORD -> GroovyBundle.message("create.record.text", referenceName); }; }
getText
32,030
IntentionPreviewInfo (@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { String name = myRefElement.getReferenceName(); if (name == null) { return IntentionPreviewInfo.EMPTY; } PsiFile containingFile = myRefElement.getContainingFile(); if (!(containingFile instanceof GroovyFileBase)) { return IntentionPreviewInfo.EMPTY; } String packageName = ((GroovyFileBase)containingFile).getPackageName(); String prefix = packageName.isEmpty() ? "" : "package " + packageName + "\n\n"; String template = prefix + "%s " + name + " {\n}" ; String newClassPrefix = switch (myType) { case CLASS -> "class"; case INTERFACE -> "interface"; case TRAIT -> "trait"; case ENUM -> "enum"; case ANNOTATION -> "@interface"; case RECORD -> "record"; }; return new IntentionPreviewInfo.CustomDiff(GroovyFileType.GROOVY_FILE_TYPE, name + ".groovy", "", String.format(template, newClassPrefix)); }
generatePreview
32,031
String () { return GroovyBundle.message("create.class.family.name"); }
getFamilyName
32,032
boolean (@NotNull Project project, Editor editor, PsiFile file) { return myRefElement.isValid() && ModuleUtilCore.findModuleForPsiElement(myRefElement) != null; }
isAvailable
32,033
boolean () { return false; }
startInWriteAction
32,034
GrCreateClassKind () { return myType; }
getType
32,035
GrTypeDefinition (@NotNull final PsiDirectory directory, @NotNull final String name, @NotNull final PsiManager manager, @Nullable final PsiElement contextElement, @NotNull final String templateName, boolean allowReformatting) { return WriteAction.compute(() -> { try { GrTypeDefinition targetClass = null; try { PsiFile file = GroovyTemplatesFactory.createFromTemplate(directory, name, name + ".groovy", templateName, allowReformatting); for (PsiElement element : file.getChildren()) { if (element instanceof GrTypeDefinition) { targetClass = ((GrTypeDefinition)element); break; } } if (targetClass == null) { throw new IncorrectOperationException(GroovyBundle.message("no.class.in.file.template")); } } catch (final IncorrectOperationException e) { ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog( GroovyBundle.message("cannot.create.class.error.text", name, e.getLocalizedMessage()), GroovyBundle.message("cannot.create.class.error.title"))); return null; } PsiModifierList modifiers = targetClass.getModifierList(); if (contextElement != null && !JavaPsiFacade.getInstance(manager.getProject()).getResolveHelper().isAccessible(targetClass, contextElement, null) && modifiers != null) { modifiers.setModifierProperty(PsiModifier.PUBLIC, true); } return targetClass; } catch (IncorrectOperationException e) { LOG.error(e); return null; } }); }
createClassByType
32,036
PsiDirectory (@NotNull Project project, @NotNull String qualifier, @NotNull String name, @Nullable Module module, @DialogTitle @NotNull String title) { CreateClassDialog dialog = new CreateClassDialog(project, title, name, qualifier, getType(), false, module) { @Override protected boolean reportBaseInSourceSelectionInTest() { return true; } }; dialog.show(); if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return null; return dialog.getTargetDirectory(); }
getTargetDirectory
32,037
boolean () { return true; }
reportBaseInSourceSelectionInTest
32,038
PsiElementPredicate () { return new PsiElementPredicate() { @Override public boolean satisfiedBy(@NotNull PsiElement element) { return myRefElement.isValid(); } }; }
getElementPredicate
32,039
boolean (@NotNull PsiElement element) { return myRefElement.isValid(); }
satisfiedBy
32,040
IntentionPreviewInfo (@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { PsiFile containingFile = ref.getContainingFile(); if (!(containingFile instanceof GroovyFile)) { return IntentionPreviewInfo.EMPTY; } String fileName = containingFile.getName(); GrImportStatement[] imports = ((GroovyFile)containingFile).getImportStatements(); StringBuilder builder = new StringBuilder(); for (GrImportStatement importStmt : imports) { builder.append(importStmt.getText()); builder.append("\n"); } String before = builder.toString(); builder.append("import package1.package2.").append(ref.getReferenceName()); String after = builder.toString(); return new IntentionPreviewInfo.CustomDiff(GroovyFileType.GROOVY_FILE_TYPE, fileName, before, after); }
generatePreview
32,041
String (@NotNull GrReferenceElement<?> reference) { return reference.getReferenceName(); }
getReferenceName
32,042
PsiElement (@NotNull GrReferenceElement<?> reference) { return reference.getReferenceNameElement(); }
getReferenceNameElement
32,043
boolean (@NotNull GrReferenceElement<?> reference) { return reference.getTypeArguments().length > 0; }
hasTypeParameters
32,044
String (@NotNull GrReferenceElement<?> referenceElement) { return referenceElement.getCanonicalText(); }
getQualifiedName
32,045
boolean (@NotNull GrReferenceElement<?> reference) { return reference.getQualifier() != null; }
isQualified
32,046
boolean (@NotNull PsiFile psiFile, @NotNull String name) { if (!(psiFile instanceof GroovyFile)) return false; final GrImportStatement[] importStatements = ((GroovyFile)psiFile).getImportStatements(); for (GrImportStatement importStatement : importStatements) { final GrCodeReferenceElement importReference = importStatement.getImportReference(); if (importReference == null || importReference.resolve() != null) { continue; } if (importStatement.isOnDemand() || Comparing.strEqual(importStatement.getImportedName(), name)) { return true; } } return false; }
hasUnresolvedImportWhichCanImport
32,047
Collection<PsiClass> (@NotNull Collection<PsiClass> candidates, @NotNull GrReferenceElement<?> referenceElement) { PsiElement typeElement = referenceElement.getParent(); if (typeElement instanceof GrTypeElement) { PsiElement decl = typeElement.getParent(); if (decl instanceof GrVariableDeclaration) { GrVariable[] vars = ((GrVariableDeclaration)decl).getVariables(); if (vars.length == 1) { PsiExpression initializer = vars[0].getInitializer(); if (initializer != null) { PsiType type = initializer.getType(); if (type != null) { return filterAssignableFrom(type, candidates); } } } } if (decl instanceof GrParameter) { return filterBySuperMethods((PsiParameter)decl, candidates); } } return super.filterByContext(candidates, referenceElement); }
filterByContext
32,048
String (@NotNull GrReferenceElement<?> referenceElement) { if (referenceElement.getParent() instanceof GrReferenceElement) { return ((GrReferenceElement<?>)referenceElement.getParent()).getReferenceName(); } return super.getRequiredMemberName(referenceElement); }
getRequiredMemberName
32,049
boolean (@NotNull PsiMember member, @NotNull GrReferenceElement<?> referenceElement) { return true; }
isAccessible
32,050
boolean (@NotNull Editor editor) { // Lines below are required to prevent the "Add import" popup appearing two times in a row // Similar issue is in com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase.calcClassesToImport if (!ref.isValid()) { return false; } PsiFile containingFile = ref.getContainingFile(); if (containingFile instanceof GroovyFile) { List<PsiClass> alreadyImportedClasses = ContainerUtil.map(((GroovyFile)containingFile).getImportStatements(), GrImportStatement::resolveTargetClass); for (PsiClass classToImport : getClassesToImport()) { if (alreadyImportedClasses.contains(classToImport)) { return false; } } } return super.showHint(editor); }
showHint
32,051
void (@NotNull PsiReference reference, @NotNull PsiClass targetClass) { PsiElement referringElement = reference.getElement(); if (referringElement.getParent() instanceof GrMethodCall && referringElement instanceof GrReferenceExpression && PsiUtil.isNewified(referringElement)) { handleNewifiedClass(referringElement, targetClass); } else { super.bindReference(reference, targetClass); } }
bindReference
32,052
void (@NotNull PsiElement referringElement, @NotNull PsiClass targetClass) { PsiFile file = referringElement.getContainingFile(); if (file instanceof GroovyFile) { ((GroovyFile)file).importClass(targetClass); } }
handleNewifiedClass
32,053
boolean (@NotNull PsiFile containingFile, @NotNull PsiClass classToImport) { GrImportStatement[] importList = ((GroovyFile)containingFile).getImportStatements(); if (importList == null) return false; String classQualifiedName = classToImport.getQualifiedName(); String packageName = classQualifiedName == null ? "" : StringUtil.getPackageName(classQualifiedName); boolean result = false; for (GrImportStatement statement : importList) { GrCodeReferenceElement importRef = statement.getImportReference(); if (importRef == null) continue; String canonicalText = importRef.getCanonicalText(); // rely on the optimization: no resolve while getting import statement canonical text if (statement.isOnDemand()) { if (canonicalText.equals(packageName)) { result = true; break; } } else { if (canonicalText.equals(classQualifiedName)) { result = true; break; } } } return result; }
isClassMaybeImportedAlready
32,054
IntentionPreviewInfo (@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { int offset = editor.getCaretModel().getOffset(); PsiMethod method = PsiTreeUtil.getParentOfType(file.findElementAt(offset), PsiMethod.class); if (method == null) { return IntentionPreviewInfo.EMPTY; } PsiMethod copy = ((PsiMethod)method.copy()); PsiParameterList list = copy.getParameterList(); list.add(GroovyPsiElementFactory.getInstance(project).createParameter(myName, PsiType.getJavaLangObject(PsiManager.getInstance(project), file.getResolveScope()))); return new IntentionPreviewInfo.CustomDiff(GroovyFileType.GROOVY_FILE_TYPE, method.getText(), copy.getText()); }
generatePreview
32,055
String () { return GroovyBundle.message("create.parameter.from.usage.family.name"); }
getFamilyName
32,056
String () { return GroovyBundle.message("create.parameter.from.usage", myName); }
getText
32,057
JBPopup () { return myEnclosingMethodsPopup; }
get
32,058
boolean (PsiElement element) { return element instanceof GrExpression; }
isStopElement
32,059
PsiElementPredicate () { return new PsiElementPredicate() { @Override public boolean satisfiedBy(@NotNull PsiElement element) { return element instanceof GrReferenceExpression; } }; }
getElementPredicate
32,060
boolean (@NotNull PsiElement element) { return element instanceof GrReferenceExpression; }
satisfiedBy
32,061
void (@NotNull final GrReferenceExpression ref, @NotNull final Editor editor, final Project project) { PsiElement place = ref; final List<GrMethod> scopes = new ArrayList<>(); while (true) { final GrMethod parent = PsiTreeUtil.getParentOfType(place, GrMethod.class); if (parent == null) break; scopes.add(parent); place = parent; } if (scopes.size() == 1) { final GrMethod owner = scopes.get(0); final PsiMethod toSearchFor = SuperMethodWarningUtil.checkSuperMethod(owner); if (toSearchFor == null) return; //if it is null, refactoring was canceled showDialog(toSearchFor, ref, project); } else if (scopes.size() > 1) { myEnclosingMethodsPopup = MethodOrClosureScopeChooser.create(scopes, editor, this, (owner, element) -> { if (owner != null) { showDialog((PsiMethod)owner, ref, project); } return null; }); myEnclosingMethodsPopup.showInBestPositionFor(editor); } }
findScope
32,062
void (@NotNull PsiMethod method, @NotNull GrReferenceExpression ref, @NotNull Project project) { final String name = ref.getReferenceName(); final List<PsiType> types = GroovyExpectedTypesProvider.getDefaultExpectedTypes(ref); PsiType unboxed = types.isEmpty() ? null : TypesUtil.unboxPrimitiveTypeWrapper(types.get(0)); @NotNull final PsiType type = unboxed != null ? unboxed : PsiType.getJavaLangObject(ref.getManager(), ref.getResolveScope()); if (method instanceof GrMethod) { GrMethodDescriptor descriptor = new GrMethodDescriptor((GrMethod)method); GrChangeSignatureDialog dialog = new GrChangeSignatureDialog(project, descriptor, true, ref); List<GrParameterInfo> parameters = dialog.getParameters(); parameters.add(createParameterInfo(name, type)); dialog.setParameterInfos(parameters); dialog.show(); } else { JavaChangeSignatureDialog dialog = new JavaChangeSignatureDialog(project, method, false, ref); final List<ParameterInfoImpl> parameterInfos = new ArrayList<>(Arrays.asList(ParameterInfoImpl.fromMethod(method))); ParameterInfoImpl parameterInfo = ParameterInfoImpl.createNew() .withName(name) .withType(type) .withDefaultValue(PsiTypesUtil.getDefaultValueOfType(type)); if (!method.isVarArgs()) { parameterInfos.add(parameterInfo); } else { parameterInfos.add(parameterInfos.size() - 1, parameterInfo); } dialog.setParameterInfos(parameterInfos); dialog.show(); } }
showDialog
32,063
GrParameterInfo (String name, PsiType type) { String notNullName = name != null ? name : ""; String defaultValueText = GroovyToJavaGenerator.getDefaultValueText(type.getCanonicalText()); return new GrParameterInfo(notNullName, defaultValueText, "", type, NEW_PARAMETER, false); }
createParameterInfo
32,064
boolean () { return false; }
startInWriteAction
32,065
IntentionAction (final GrNewExpression expression) { return new CreateClassActionBase(GrCreateClassKind.CLASS, expression.getReferenceElement()) { @Override protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException { final PsiFile file = element.getContainingFile(); if (!(file instanceof GroovyFileBase groovyFile)) return; final PsiManager manager = myRefElement.getManager(); final String qualifier = ReadAction.compute(() -> groovyFile instanceof GroovyFile ? groovyFile.getPackageName() : ""); final String name = ReadAction.compute(() -> myRefElement.getReferenceName()); assert name != null; final Module module = ReadAction.compute(() -> ModuleUtilCore.findModuleForPsiElement(file)); PsiDirectory targetDirectory = getTargetDirectory(project, qualifier, name, module, getText()); if (targetDirectory == null) return; final GrTypeDefinition targetClass = createClassByType(targetDirectory, name, manager, myRefElement, GroovyTemplates.GROOVY_CLASS, true); if (targetClass == null) return; PsiType[] argTypes = getArgTypes(myRefElement); if (argTypes != null && argTypes.length > 0) { generateConstructor(myRefElement, name, argTypes, targetClass, project); bindRef(targetClass, myRefElement); } else { bindRef(targetClass, myRefElement); IntentionUtils.positionCursor(project, targetClass.getContainingFile(), targetClass); } } }; }
createClassFromNewAction
32,066
void (@NotNull PsiElement refElement, @NotNull String name, PsiType @NotNull [] argTypes, @NotNull GrTypeDefinition targetClass, @NotNull Project project) { WriteAction.run(() -> { ChooseTypeExpression[] paramTypesExpressions = new ChooseTypeExpression[argTypes.length]; String[] paramTypes = new String[argTypes.length]; String[] paramNames = new String[argTypes.length]; for (int i = 0; i < argTypes.length; i++) { PsiType argType = argTypes[i]; if (argType == null) argType = TypesUtil.getJavaLangObject(refElement); paramTypes[i] = "Object"; paramNames[i] = "o" + i; TypeConstraint[] constraints = {SupertypeConstraint.create(argType)}; paramTypesExpressions[i] = new ChooseTypeExpression(constraints, refElement.getManager(), targetClass.getResolveScope()); } GrMethod method = GroovyPsiElementFactory.getInstance(project).createConstructorFromText(name, paramTypes, paramNames, "{\n}"); method = (GrMethod)targetClass.addBefore(method, null); final PsiElement context = PsiTreeUtil.getParentOfType(refElement, PsiMethod.class, PsiClass.class, PsiFile.class); createTemplateForMethod(paramTypesExpressions, method, targetClass, TypeConstraint.EMPTY_ARRAY, true, context); }); }
generateConstructor
32,067
IntentionAction (final GrReferenceElement refElement, GrCreateClassKind type) { return new CreateClassActionBase(type, refElement) { @Override protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException { final PsiFile file = element.getContainingFile(); if (!(file instanceof GroovyFileBase groovyFile)) return; PsiElement qualifier = myRefElement.getQualifier(); if (qualifier == null || qualifier instanceof GrReferenceElement && ((GrReferenceElement<?>)qualifier).resolve() instanceof PsiPackage) { createTopLevelClass(project, groovyFile); } else { createInnerClass(project, editor, qualifier); } } private void createInnerClass(Project project, final Editor editor, PsiElement qualifier) { PsiElement resolved = resolveQualifier(qualifier); if (!(resolved instanceof PsiClass)) return; JVMElementFactory factory = JVMElementFactories.getFactory(resolved.getLanguage(), project); if (factory == null) return; String name = myRefElement.getReferenceName(); PsiClass template = createTemplate(factory, name); if (template == null) { ApplicationManager.getApplication().invokeLater(() -> { if (editor != null && editor.getComponent().isDisplayable()) { HintManager.getInstance().showErrorHint(editor, GroovyBundle.message("cannot.create.class")); } }); return; } if (!FileModificationService.getInstance().preparePsiElementForWrite(resolved)) return; WriteAction.run(() -> { PsiClass added = (PsiClass)resolved.add(template); PsiModifierList modifierList = added.getModifierList(); if (modifierList != null) { modifierList.setModifierProperty(PsiModifier.STATIC, true); } IntentionUtils.positionCursor(project, added.getContainingFile(), added); }); } @Nullable private static PsiElement resolveQualifier(@NotNull PsiElement qualifier) { if (qualifier instanceof GrCodeReferenceElement) { return ((GrCodeReferenceElement)qualifier).resolve(); } else if (qualifier instanceof GrExpression) { PsiType type = ((GrExpression)qualifier).getType(); if (type instanceof PsiClassType) { return ((PsiClassType)type).resolve(); } else if (qualifier instanceof GrReferenceExpression) { final PsiElement resolved = ((GrReferenceExpression)qualifier).resolve(); if (resolved instanceof PsiClass || resolved instanceof PsiPackage) { return resolved; } } } return null; } @Nullable private PsiClass createTemplate(JVMElementFactory factory, String name) { return switch (getType()) { case ENUM -> factory.createEnum(name); case TRAIT -> { if (factory instanceof GroovyPsiElementFactory groovyFactory) { yield groovyFactory.createTrait(name); } yield null; } case CLASS -> factory.createClass(name); case INTERFACE -> factory.createInterface(name); case ANNOTATION -> factory.createAnnotationType(name); case RECORD -> { if (factory instanceof GroovyPsiElementFactory groovyFactory) { yield groovyFactory.createRecord(name); } yield null; } }; } private void createTopLevelClass(@NotNull Project project, @NotNull GroovyFileBase file) { final String pack = getPackage(file); final PsiManager manager = PsiManager.getInstance(project); final String name = myRefElement.getReferenceName(); assert name != null; final Module module = ModuleUtilCore.findModuleForPsiElement(file); PsiDirectory targetDirectory = getTargetDirectory(project, pack, name, module, getText()); if (targetDirectory == null) return; String templateName = getTemplateName(getType()); final PsiClass targetClass = createClassByType(targetDirectory, name, manager, myRefElement, templateName, true); if (targetClass == null) return; bindRef(targetClass, myRefElement); IntentionUtils.positionCursor(project, targetClass.getContainingFile(), targetClass); } @NotNull private String getPackage(@NotNull PsiClassOwner file) { final PsiElement qualifier = myRefElement.getQualifier(); if (qualifier instanceof GrReferenceElement) { final PsiElement resolved = ((GrReferenceElement<?>)qualifier).resolve(); if (resolved instanceof PsiPackage) { return ((PsiPackage)resolved).getQualifiedName(); } } return file instanceof GroovyFile ? file.getPackageName() : ""; } @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { if (!super.isAvailable(project, editor, file)) return false; final PsiElement qualifier = myRefElement.getQualifier(); if (qualifier != null && resolveQualifier(qualifier) == null) { return false; } return true; } }; }
createClassFixAction
32,068
void (Project project, final Editor editor, PsiElement qualifier) { PsiElement resolved = resolveQualifier(qualifier); if (!(resolved instanceof PsiClass)) return; JVMElementFactory factory = JVMElementFactories.getFactory(resolved.getLanguage(), project); if (factory == null) return; String name = myRefElement.getReferenceName(); PsiClass template = createTemplate(factory, name); if (template == null) { ApplicationManager.getApplication().invokeLater(() -> { if (editor != null && editor.getComponent().isDisplayable()) { HintManager.getInstance().showErrorHint(editor, GroovyBundle.message("cannot.create.class")); } }); return; } if (!FileModificationService.getInstance().preparePsiElementForWrite(resolved)) return; WriteAction.run(() -> { PsiClass added = (PsiClass)resolved.add(template); PsiModifierList modifierList = added.getModifierList(); if (modifierList != null) { modifierList.setModifierProperty(PsiModifier.STATIC, true); } IntentionUtils.positionCursor(project, added.getContainingFile(), added); }); }
createInnerClass
32,069
PsiElement (@NotNull PsiElement qualifier) { if (qualifier instanceof GrCodeReferenceElement) { return ((GrCodeReferenceElement)qualifier).resolve(); } else if (qualifier instanceof GrExpression) { PsiType type = ((GrExpression)qualifier).getType(); if (type instanceof PsiClassType) { return ((PsiClassType)type).resolve(); } else if (qualifier instanceof GrReferenceExpression) { final PsiElement resolved = ((GrReferenceExpression)qualifier).resolve(); if (resolved instanceof PsiClass || resolved instanceof PsiPackage) { return resolved; } } } return null; }
resolveQualifier
32,070
PsiClass (JVMElementFactory factory, String name) { return switch (getType()) { case ENUM -> factory.createEnum(name); case TRAIT -> { if (factory instanceof GroovyPsiElementFactory groovyFactory) { yield groovyFactory.createTrait(name); } yield null; } case CLASS -> factory.createClass(name); case INTERFACE -> factory.createInterface(name); case ANNOTATION -> factory.createAnnotationType(name); case RECORD -> { if (factory instanceof GroovyPsiElementFactory groovyFactory) { yield groovyFactory.createRecord(name); } yield null; } }; }
createTemplate
32,071
void (@NotNull Project project, @NotNull GroovyFileBase file) { final String pack = getPackage(file); final PsiManager manager = PsiManager.getInstance(project); final String name = myRefElement.getReferenceName(); assert name != null; final Module module = ModuleUtilCore.findModuleForPsiElement(file); PsiDirectory targetDirectory = getTargetDirectory(project, pack, name, module, getText()); if (targetDirectory == null) return; String templateName = getTemplateName(getType()); final PsiClass targetClass = createClassByType(targetDirectory, name, manager, myRefElement, templateName, true); if (targetClass == null) return; bindRef(targetClass, myRefElement); IntentionUtils.positionCursor(project, targetClass.getContainingFile(), targetClass); }
createTopLevelClass
32,072
String (@NotNull PsiClassOwner file) { final PsiElement qualifier = myRefElement.getQualifier(); if (qualifier instanceof GrReferenceElement) { final PsiElement resolved = ((GrReferenceElement<?>)qualifier).resolve(); if (resolved instanceof PsiPackage) { return ((PsiPackage)resolved).getQualifiedName(); } } return file instanceof GroovyFile ? file.getPackageName() : ""; }
getPackage
32,073
boolean (@NotNull Project project, Editor editor, PsiFile file) { if (!super.isAvailable(project, editor, file)) return false; final PsiElement qualifier = myRefElement.getQualifier(); if (qualifier != null && resolveQualifier(qualifier) == null) { return false; } return true; }
isAvailable
32,074
void (@NotNull final PsiClass targetClass, @NotNull final GrReferenceElement ref) { ApplicationManager.getApplication().runWriteAction(() -> { final PsiElement newRef = ref.bindToElement(targetClass); JavaCodeStyleManager.getInstance(targetClass.getProject()).shortenClassReferences(newRef); }); }
bindRef
32,075
String (GrCreateClassKind createClassKind) { return switch (createClassKind) { case TRAIT -> GroovyTemplates.GROOVY_TRAIT; case ENUM -> GroovyTemplates.GROOVY_ENUM; case CLASS -> GroovyTemplates.GROOVY_CLASS; case INTERFACE -> GroovyTemplates.GROOVY_INTERFACE; case ANNOTATION -> GroovyTemplates.GROOVY_ANNOTATION; case RECORD -> GroovyTemplates.GROOVY_RECORD; }; }
getTemplateName
32,076
ActionUpdateThread () { return ActionUpdateThread.EDT; }
getActionUpdateThread
32,077
void (@NotNull AnActionEvent e) { final DynamicToolWindowWrapper toolWindow = DynamicToolWindowWrapper.getInstance(e.getProject()); toolWindow.deleteRow(); }
actionPerformed
32,078
void (@NotNull AnActionEvent e) { final Project project = e.getProject(); if (project == null) { e.getPresentation().setEnabled(false); return; } final TreePath[] paths = DynamicToolWindowWrapper.getInstance(project).getTreeTable().getTree().getSelectionPaths(); e.getPresentation().setEnabled(paths != null); }
update
32,079
String () { return GroovyBundle.message("add.dynamic.method.0", mySignature); }
getText
32,080
String (final PsiType[] argTypes) { StringBuilder builder = new StringBuilder().append(myReferenceExpression.getReferenceName()); builder.append("("); for (int i = 0; i < argTypes.length; i++) { PsiType type = argTypes[i]; if (i > 0) { builder.append(", "); } if (type == null) { builder.append("Object"); } else { builder.append(type.getPresentableText()); } } builder.append(")"); return builder.toString(); }
calcSignature
32,081
IntentionPreviewInfo (@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { return new IntentionPreviewInfo.CustomDiff(GroovyFileType.GROOVY_FILE_TYPE, "Dynamic namespace", "", "Object " + myReferenceExpression.getReferenceName() + "()"); }
generatePreview
32,082
String () { return GroovyBundle.message("add.dynamic.element"); }
getFamilyName
32,083
boolean (@NotNull Project project, Editor editor, PsiFile psiFile) { return myReferenceExpression.isValid() && !isInStaticCompilationContext(myReferenceExpression); }
isAvailable
32,084
boolean () { return false; }
startInWriteAction
32,085
GrReferenceExpression () { return myReferenceExpression; }
getReferenceExpression
32,086
String () { return myContainingClassName; }
getContainingClassName
32,087
PsiClass () { return JavaPsiFacade.getInstance(getProject()).findClass(myContainingClassName, ProjectScope.getAllScope(getProject())); }
getContainingClassElement
32,088
GrDynamicImplicitMethod () { return new GrDynamicImplicitMethod(myManager, getName(), getContainingClassName(), hasModifierProperty(PsiModifier.STATIC), new ArrayList<>((Collection<? extends ParamInfo>)myParamInfos), myReturnType); }
copy
32,089
boolean () { return true; }
isValid
32,090
PsiFile () { final PsiClass psiClass = getContainingClassElement(); if (psiClass == null) return null; return psiClass.getContainingFile(); }
getContainingFile
32,091
PsiClass () { return ReadAction.compute(() -> { try { final GrTypeElement typeElement = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(myContainingClassName); return typeElement.getType() instanceof PsiClassType type ? type.resolve() : null; } catch (IncorrectOperationException e) { LOG.error(e); return null; } }); }
getContainingClass
32,092
String () { return "DynamicMethod:" + getName(); }
toString
32,093
SearchScope () { return GlobalSearchScope.projectScope(getProject()); }
getUseScope
32,094
void (boolean requestFocus) { DynamicToolWindowWrapper.getInstance(getProject()).getToolWindow().activate(() -> { DynamicToolWindowWrapper toolWindowWrapper = DynamicToolWindowWrapper.getInstance(getProject()); final TreeTable treeTable = toolWindowWrapper.getTreeTable(); final ListTreeTableModelOnColumns model = toolWindowWrapper.getTreeTableModel(); Object root = model.getRoot(); if (!(root instanceof DefaultMutableTreeNode treeRoot)) return; DefaultMutableTreeNode desiredNode; JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject()); final PsiClassType fqClassName = facade.getElementFactory().createTypeByFQClassName(myContainingClassName, ProjectScope.getAllScope(getProject())); final PsiClass psiClass = fqClassName.resolve(); if (psiClass == null) return; PsiClass trueClass = null; DMethodElement methodElement = null; final GrParameter[] parameters = getParameters(); List<String> parameterTypes = new ArrayList<>(); for (GrParameter parameter : parameters) { final String type = parameter.getType().getCanonicalText(); parameterTypes.add(type); } for (PsiClass aSuper : PsiUtil.iterateSupers(psiClass, true)) { methodElement = DynamicManager.getInstance(getProject()).findConcreteDynamicMethod(aSuper.getQualifiedName(), getName(), ArrayUtilRt.toStringArray(parameterTypes)); if (methodElement != null) { trueClass = aSuper; break; } } if (trueClass == null) return; final DefaultMutableTreeNode classNode = TreeUtil.findNodeWithObject(treeRoot, new DClassElement(getProject(), trueClass.getQualifiedName())); if (classNode == null) return; desiredNode = TreeUtil.findNodeWithObject(classNode, methodElement); if (desiredNode == null) return; final TreePath path = TreeUtil.getPathFromRoot(desiredNode); treeTable.getTree().expandPath(path); treeTable.getTree().setSelectionPath(path); treeTable.getTree().fireTreeExpanded(path); // ToolWindowManager.getInstance(myProject).getFocusManager().requestFocus(treeTable, true); treeTable.revalidate(); treeTable.repaint(); }, true); }
navigate
32,095
boolean () { return false; }
canNavigateToSource
32,096
boolean () { return true; }
canNavigate
32,097
boolean () { return true; }
isWritable
32,098
String () { return getName(); }
getPresentableText
32,099
Icon (boolean open) { return JetgroovyIcons.Groovy.Method; }
getIcon