Unnamed: 0 int64 0 305k | body stringlengths 7 52.9k | name stringlengths 1 185 |
|---|---|---|
31,300 | PsiIdentifier () { return myNewNameIdentifier; } | getNewNameIdentifier |
31,301 | String () { return myOldName; } | getOldName |
31,302 | boolean () { return myWasVarargs; } | wasVararg |
31,303 | boolean[] () { return new boolean[0]; } | toRemoveParm |
31,304 | PsiExpression (int i, PsiCallExpression callExpression) { if (defaultValues[i] != null) return defaultValues[i]; final PsiElement valueAtCallSite = parameters.get(i).getActualValue(callExpression, PsiSubstitutor.EMPTY); return valueAtCallSite instanceof PsiExpression ? (PsiExpression)valueAtCallSite : null; } | getValue |
31,305 | void (@NotNull PsiMethod psiMethod) { if (psiMethod instanceof GrMethod) { method = (GrMethod)psiMethod; } } | updateMethod |
31,306 | Collection<PsiMethod> () { return Collections.emptyList(); } | getMethodsToPropagateParameters |
31,307 | String (@NotNull final String originalName, @NotNull final Project project) { return PsiNameHelper.getInstance(project).isIdentifier(originalName) ? originalName : GrStringUtil.getLiteralTextByValue(originalName).toString(); } | getNameWithQuotesIfNeeded |
31,308 | String () { return myName; } | getName |
31,309 | int () { return myPosition; } | getOldIndex |
31,310 | String () { return forceOptional() ? getDefaultInitializer() : myDefaultValue; } | getDefaultValue |
31,311 | String () { return myTypeWrapper != null ? myTypeWrapper.getTypeText() : ""; } | getTypeText |
31,312 | PsiExpression (PsiCallExpression callExpression) { return JavaPsiFacade.getElementFactory(callExpression.getProject()).createExpressionFromText(getDefaultValue(), callExpression); } | getValue |
31,313 | boolean () { return getTypeText().endsWith("...") || getTypeText().endsWith("[]"); } | isVarargType |
31,314 | boolean () { return myUseAnySingleVariable; } | isUseAnySingleVariable |
31,315 | void (boolean useAnyVar) { myUseAnySingleVariable = useAnyVar; } | setUseAnySingleVariable |
31,316 | boolean () { return !getDefaultInitializer().isEmpty(); } | isOptional |
31,317 | String () { return myDefaultInitializer; } | getDefaultInitializer |
31,318 | boolean () { return getTypeText().isEmpty(); } | hasNoType |
31,319 | boolean () { return myPosition < 0 && StringUtil.isEmpty(myDefaultValue); } | forceOptional |
31,320 | void (String newName) { myName = StringUtil.notNullize(newName); } | setName |
31,321 | void (@Nullable PsiType type) { myTypeWrapper = type == null ? null : CanonicalTypes.createTypeWrapper(type); } | setType |
31,322 | void (@Nullable String initializer) { myDefaultInitializer = StringUtil.notNullize(initializer); } | setInitializer |
31,323 | void (@Nullable String defaultValue) { myDefaultValue = StringUtil.notNullize(defaultValue); } | setDefaultValue |
31,324 | UsageInfo[] () { ArrayList<UsageInfo> result = new ArrayList<>(); final PsiMethod method = myChangeInfo.getMethod(); findSimpleUsages(method, result); final UsageInfo[] usageInfos = result.toArray(UsageInfo.EMPTY_ARRAY); return UsageViewUtil.removeDuplicatedUsages(usageInfos); } | findUsages |
31,325 | void (final PsiMethod method, final ArrayList<UsageInfo> result) { PsiMethod[] overridingMethods = findSimpleUsagesWithoutParameters(method, result, true, true, true); //findUsagesInCallers(result); todo //Parameter name changes are not propagated findParametersUsage(method, result, overridingMethods); } | findSimpleUsages |
31,326 | void (final ArrayList<UsageInfo> usages) { if (myChangeInfo instanceof JavaChangeInfoImpl) { JavaChangeInfoImpl changeInfo = (JavaChangeInfoImpl)myChangeInfo; for (PsiMethod caller : changeInfo.propagateParametersMethods) { usages.add(new CallerUsageInfo(caller, true, changeInfo.propagateExceptionsMethods.contains(caller))); } for (PsiMethod caller : changeInfo.propagateExceptionsMethods) { usages.add(new CallerUsageInfo(caller, changeInfo.propagateParametersMethods.contains(caller), true)); } Set<PsiMethod> merged = new HashSet<PsiMethod>(); merged.addAll(changeInfo.propagateParametersMethods); merged.addAll(changeInfo.propagateExceptionsMethods); for (final PsiMethod method : merged) { findSimpleUsagesWithoutParameters(method, usages, changeInfo.propagateParametersMethods.contains(method), changeInfo.propagateExceptionsMethods.contains(method), false); } } } | findUsagesInCallers |
31,327 | void (final GrMethod method, final ArrayList<UsageInfo> result, boolean isOriginal) { if (!GroovyLanguage.INSTANCE.equals(method.getLanguage())) return; final PsiParameter[] parameters = method.getParameterList().getParameters(); final Set<PsiParameter> deletedOrRenamedParameters = new HashSet<>(); if (isOriginal) { ContainerUtil.addAll(deletedOrRenamedParameters, parameters); for (ParameterInfo parameterInfo : myChangeInfo.getNewParameters()) { if (parameterInfo.getOldIndex() >= 0) { final PsiParameter parameter = parameters[parameterInfo.getOldIndex()]; if (parameterInfo.getName().equals(parameter.getName())) { deletedOrRenamedParameters.remove(parameter); } } } } final GrOpenBlock block = method.getBlock(); for (ParameterInfo parameterInfo : myChangeInfo.getNewParameters()) { final int oldParameterIndex = parameterInfo.getOldIndex(); final String newName = parameterInfo.getName(); if (oldParameterIndex >= 0) { if (isOriginal) { //Name changes take place only in primary method final PsiParameter parameter = parameters[oldParameterIndex]; if (!newName.equals(parameter.getName())) { final GrUnresolvableLocalCollisionDetector.CollidingVariableVisitor collidingVariableVisitor = new GrUnresolvableLocalCollisionDetector.CollidingVariableVisitor() { @Override public void visitCollidingVariable(final PsiVariable collidingVariable) { if (!deletedOrRenamedParameters.contains(collidingVariable)) { result.add(new RenamedParameterCollidesWithLocalUsageInfo(parameter, collidingVariable, method)); } } }; if (block != null) { GrUnresolvableLocalCollisionDetector.visitLocalsCollisions(parameter, newName, block, collidingVariableVisitor); } } } } else { final GrUnresolvableLocalCollisionDetector.CollidingVariableVisitor variableVisitor = new GrUnresolvableLocalCollisionDetector.CollidingVariableVisitor() { @Override public void visitCollidingVariable(PsiVariable collidingVariable) { if (!deletedOrRenamedParameters.contains(collidingVariable)) { result.add(new NewParameterCollidesWithLocalUsageInfo(collidingVariable, collidingVariable, method)); } } }; if (block != null) { GrUnresolvableLocalCollisionDetector.visitLocalsCollisions(method, newName, block, variableVisitor); } } } } | detectLocalsCollisionsInMethod |
31,328 | void (final PsiVariable collidingVariable) { if (!deletedOrRenamedParameters.contains(collidingVariable)) { result.add(new RenamedParameterCollidesWithLocalUsageInfo(parameter, collidingVariable, method)); } } | visitCollidingVariable |
31,329 | void (PsiVariable collidingVariable) { if (!deletedOrRenamedParameters.contains(collidingVariable)) { result.add(new NewParameterCollidesWithLocalUsageInfo(collidingVariable, collidingVariable, method)); } } | visitCollidingVariable |
31,330 | void (final PsiMethod method, ArrayList<UsageInfo> result, PsiMethod[] overriders) { if (!GroovyLanguage.INSTANCE.equals(method.getLanguage())) return; PsiParameter[] parameters = method.getParameterList().getParameters(); for (ParameterInfo info : myChangeInfo.getNewParameters()) { if (info.getOldIndex() >= 0) { PsiParameter parameter = parameters[info.getOldIndex()]; if (!info.getName().equals(parameter.getName())) { addParameterUsages(parameter, result, info); for (PsiMethod overrider : overriders) { if (!GroovyLanguage.INSTANCE.equals(overrider.getLanguage())) continue; PsiParameter parameter1 = overrider.getParameterList().getParameters()[info.getOldIndex()]; if (parameter.getName().equals(parameter1.getName())) { addParameterUsages(parameter1, result, info); } } } } } } | findParametersUsage |
31,331 | PsiMethod[] (final PsiMethod method, final ArrayList<UsageInfo> result, boolean isToModifyArgs, boolean isToThrowExceptions, boolean isOriginal) { GlobalSearchScope projectScope = GlobalSearchScope.projectScope(method.getProject()); PsiMethod[] overridingMethods = OverridingMethodsSearch.search(method).toArray(PsiMethod.EMPTY_ARRAY); for (PsiMethod overridingMethod : overridingMethods) { if (GroovyLanguage.INSTANCE.equals(overridingMethod.getLanguage())) { result.add(new OverriderUsageInfo(overridingMethod, method, isOriginal, isToModifyArgs, isToThrowExceptions)); } } boolean needToChangeCalls = !myChangeInfo.isGenerateDelegate() && (myChangeInfo.isNameChanged() || myChangeInfo.isParameterSetOrOrderChanged() || myChangeInfo.isExceptionSetOrOrderChanged() || myChangeInfo.isVisibilityChanged()/*for checking inaccessible*/); if (needToChangeCalls) { PsiReference[] refs = MethodReferencesSearch.search(method, projectScope, true).toArray(PsiReference.EMPTY_ARRAY); for (PsiReference ref : refs) { PsiElement element = ref.getElement(); if (!GroovyLanguage.INSTANCE.equals(element.getLanguage())) continue; //everything else should be found by java ChangeSignatureUsageProvider provider = Objects.requireNonNull(ChangeSignatureUsageProviders.findProvider(GroovyLanguage.INSTANCE)); ContainerUtil.addIfNotNull(result, provider.createUsageInfo(myChangeInfo, ref, method, isToModifyArgs, isToThrowExceptions)); } } else if (myChangeInfo.isParameterTypesChanged()) { PsiReference[] refs = MethodReferencesSearch.search(method, projectScope, true).toArray(PsiReference.EMPTY_ARRAY); for (PsiReference reference : refs) { final PsiElement element = reference.getElement(); if (element instanceof GrDocTagValueToken) { result.add(new UsageInfo(reference)); } } } // Conflicts if (method instanceof GrMethod) { detectLocalsCollisionsInMethod((GrMethod)method, result, isOriginal); } for (final PsiMethod overridingMethod : overridingMethods) { if (overridingMethod instanceof GrMethod) { detectLocalsCollisionsInMethod((GrMethod)overridingMethod, result, isOriginal); } } return overridingMethods; } | findSimpleUsagesWithoutParameters |
31,332 | void (PsiParameter parameter, ArrayList<UsageInfo> results, ParameterInfo info) { for (PsiReference psiReference : ReferencesSearch.search(parameter)) { PsiElement parmRef = psiReference.getElement(); UsageInfo usageInfo = new ChangeSignatureParameterUsageInfo(parmRef, parameter.getName(), info.getName()); results.add(usageInfo); } } | addParameterUsages |
31,333 | String () { return RefactoringBundle.message("there.is.already.a.0.in.the.1.it.will.conflict.with.the.renamed.parameter", RefactoringUIUtil.getDescription(myCollidingElement, true), RefactoringUIUtil.getDescription(myMethod, true)); } | getDescription |
31,334 | boolean (PsiMethod caller, JavaChangeInfo info) { /*if (myChangeInfo instanceof JavaChangeInfoImpl) { //todo propagate methods return myChangeInfo.isExceptionSetOrOrderChanged() && !((JavaChangeInfoImpl)myChangeInfo).propagateExceptionsMethods.contains(caller); } else {*/ return info.isExceptionSetOrOrderChanged(); } } | needToCatchExceptions |
31,335 | String (@NotNull PsiField field) { return PropertyUtilBase.suggestSetterName(field); } | suggestSetterName |
31,336 | String (@NotNull PsiField field) { return PropertyUtilBase.suggestGetterName(field); } | suggestGetterName |
31,337 | PsiMethod (@NotNull PsiField field, @NotNull String methodName, boolean isGetter) { PsiMethod prototype = isGetter ? GroovyPropertyUtils.generateGetterPrototype(field) : GroovyPropertyUtils.generateSetterPrototype(field); try { prototype.setName(methodName); return prototype; } catch (IncorrectOperationException e) { return null; } } | generateMethodPrototype |
31,338 | EncapsulateFieldUsageInfo (@NotNull EncapsulateFieldsDescriptor descriptor, @NotNull FieldDescriptor fieldDescriptor, @NotNull PsiReference reference) { if (!(reference instanceof GrReferenceExpression ref)) return null; boolean findSet = descriptor.isToEncapsulateSet(); boolean findGet = descriptor.isToEncapsulateGet(); if (findGet && JavaEncapsulateFieldHelper.isUsedInExistingAccessor(descriptor.getTargetClass(), fieldDescriptor.getGetterPrototype(), ref)) { return null; } if (findSet && JavaEncapsulateFieldHelper.isUsedInExistingAccessor(descriptor.getTargetClass(), fieldDescriptor.getSetterPrototype(), ref)) { return null; } if (!findGet) { if (!PsiUtil.isAccessedForWriting(ref)) return null; } if (!findSet || fieldDescriptor.getField().hasModifierProperty(PsiModifier.FINAL)) { if (!PsiUtil.isAccessedForReading(ref)) return null; } /*if (!descriptor.isToUseAccessorsWhenAccessible()) { PsiModifierList newModifierList = JavaEncapsulateFieldHelper.createNewModifierList(descriptor); PsiClass accessObjectClass = getAccessObject(ref); final PsiResolveHelper helper = JavaPsiFacade.getInstance(((GrReferenceExpression)reference).getProject()).getResolveHelper(); if (helper.isAccessible(fieldDescriptor.getField(), newModifierList, ref, accessObjectClass, null)) { return null; } }*/ return new EncapsulateFieldUsageInfo(ref, fieldDescriptor); } | createUsage |
31,339 | PsiClass (@NotNull GrReferenceExpression ref) { GrExpression qualifier = ref.getQualifierExpression(); if (qualifier != null) { return (PsiClass)PsiUtil.getAccessObjectClass(qualifier).getElement(); } return null; } | getAccessObject |
31,340 | boolean (@NotNull EncapsulateFieldUsageInfo usage, @NotNull EncapsulateFieldsDescriptor descriptor, PsiMethod setter, PsiMethod getter) { final PsiElement element = usage.getElement(); if (!(element instanceof GrReferenceExpression expr)) return false; final FieldDescriptor fieldDescriptor = usage.getFieldDescriptor(); PsiField field = fieldDescriptor.getField(); boolean processGet = descriptor.isToEncapsulateGet(); boolean processSet = descriptor.isToEncapsulateSet() && !field.hasModifierProperty(PsiModifier.FINAL); if (!processGet && !processSet) return true; final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(descriptor.getTargetClass().getProject()); try { if (!descriptor.isToUseAccessorsWhenAccessible()) { PsiModifierList newModifierList = JavaEncapsulateFieldHelper.createNewModifierList(descriptor); PsiClass accessObjectClass = getAccessObject(expr); final PsiResolveHelper helper = JavaPsiFacade.getInstance((expr).getProject()).getResolveHelper(); if (helper.isAccessible(fieldDescriptor.getField(), newModifierList, expr, accessObjectClass, null)) { GroovyResolveResult[] results = expr.multiResolve(false); if (ContainerUtil.or(results, it -> it.isValidResult() && it.getElement() instanceof PsiMethod)) { addMemberOperator(expr, field); } return true; } } final PsiElement parent = expr.getParent(); if (parent instanceof GrAssignmentExpression && expr.equals(((GrAssignmentExpression)parent).getLValue())) { GrAssignmentExpression assignment = (GrAssignmentExpression)parent; if (assignment.getRValue() != null) { PsiElement opSign = assignment.getOperationToken(); if (!assignment.isOperatorAssignment()) { if (!processSet || (checkSetterIsSimple(field, setter) && checkFieldIsInaccessible(field, expr))) return true; final GrExpression setterArgument = assignment.getRValue(); GrMethodCallExpression methodCall = createSetterCall(fieldDescriptor, setterArgument, expr, descriptor.getTargetClass(), setter); if (methodCall != null) { tryToSimplify((GrMethodCallExpression)assignment.replaceWithExpression(methodCall, true)); } //TODO: check if value is used!!! } else { // Q: side effects of qualifier??! if (checkAccessorsAreSimpleAndFieldIsInaccessible(field, setter, getter, expr)) { return true; } String opName = opSign.getText(); LOG.assertTrue(StringUtil.endsWithChar(opName, '=')); opName = opName.substring(0, opName.length() - 1); GrExpression getExpr = expr; if (processGet) { final GrExpression getterCall = createGetterCall(fieldDescriptor, expr, descriptor.getTargetClass(), getter); if (getterCall != null) { getExpr = getterCall; } } @NonNls String text = "a" + opName + "b"; GrBinaryExpression binExpr = (GrBinaryExpression)factory.createExpressionFromText(text, expr); tryToSimplify((GrMethodCallExpression)binExpr.getLeftOperand().replaceWithExpression(getExpr, true)); binExpr.getRightOperand().replaceWithExpression(assignment.getRValue(), true); GrExpression setExpr; if (processSet) { setExpr = createSetterCall(fieldDescriptor, binExpr, expr, descriptor.getTargetClass(), setter); } else { text = "a = b"; GrAssignmentExpression newAssignment = (GrAssignmentExpression)factory.createExpressionFromText(text, null); newAssignment.getLValue().replaceWithExpression(expr, true); newAssignment.getRValue().replaceWithExpression(binExpr, true); setExpr = newAssignment; } tryToSimplify((GrMethodCallExpression)assignment.replaceWithExpression(setExpr, true)); //TODO: check if value is used!!! } } } else if (parent instanceof GrUnaryExpression && (((GrUnaryExpression)parent).getOperationTokenType() == GroovyTokenTypes.mINC || ((GrUnaryExpression)parent).getOperationTokenType() == GroovyTokenTypes.mDEC)) { if (checkAccessorsAreSimpleAndFieldIsInaccessible(field, setter, getter, expr)) { return true; } IElementType sign = ((GrUnaryExpression)parent).getOperationTokenType(); GrExpression getExpr = expr; if (processGet) { final GrExpression getterCall = createGetterCall(fieldDescriptor, expr, descriptor.getTargetClass(), getter); if (getterCall != null) { getExpr = getterCall; } } @NonNls String text = sign == GroovyTokenTypes.mINC ? "a+1" : "a-1"; GrBinaryExpression binExpr = (GrBinaryExpression)factory.createExpressionFromText(text, parent); tryToSimplify((GrMethodCallExpression)binExpr.getLeftOperand().replaceWithExpression(getExpr, true)); GrExpression setExpr; if (processSet) { setExpr = createSetterCall(fieldDescriptor, binExpr, expr, descriptor.getTargetClass(), setter); } else { text = "a = b"; GrAssignmentExpression assignment = (GrAssignmentExpression)factory.createExpressionFromText(text, null); assignment.getLValue().replaceWithExpression(expr, true); assignment.getRValue().replaceWithExpression(binExpr, true); setExpr = assignment; } tryToSimplify((GrMethodCallExpression)((GrUnaryExpression)parent).replaceWithExpression(setExpr, true)); } else { if (!processGet || (checkGetterIsSimple(field, getter) && checkFieldIsInaccessible(field, expr))) return true; GrExpression methodCall = createGetterCall(fieldDescriptor, expr, descriptor.getTargetClass(), getter); if (methodCall != null) { tryToSimplify(((GrMethodCallExpression)expr.replaceWithExpression(methodCall, true))); } } } catch (IncorrectOperationException e) { LOG.error(e); } return true; } | processUsage |
31,341 | void (@NotNull GrReferenceExpression ref, @NotNull PsiField field) { GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(ref.getProject()); GrExpression qualifier = ref.getQualifier(); if (qualifier == null) { PsiClass parentClass = PsiTreeUtil.getParentOfType(ref, PsiClass.class); PsiClass containingClass = findContainingClass(ref, field); GrReferenceExpression thisRef = !ref.getManager().areElementsEquivalent(parentClass, containingClass) ? factory.createThisExpression(containingClass) : factory.createThisExpression(null); ref.setQualifier(thisRef); } ref.getNode().addLeaf(GroovyTokenTypes.mAT, "@", ref.getDotToken().getNode().getTreeNext()); } | addMemberOperator |
31,342 | PsiClass (@NotNull GrReferenceExpression ref, @NotNull PsiField field) { PsiElement context = ref; while (true) { PsiClass aClass = PsiUtil.getContextClass(context); if (aClass == null) return null; PsiManager manager = context.getManager(); PsiField found = aClass.findFieldByName(field.getName(), true); if (manager.areElementsEquivalent(found, field)) { return aClass; } if (context instanceof GroovyScriptClass) return null; if (context.getParent() instanceof GroovyFile) return null; context = aClass.getParent(); } } | findContainingClass |
31,343 | boolean (@NotNull PsiField field, @Nullable PsiMethod setter, @Nullable PsiMethod getter, @NotNull GrReferenceExpression place) { return (setter == null || checkSetterIsSimple(field, setter)) && (getter == null || checkGetterIsSimple(field, getter)) && checkFieldIsInaccessible(field, place); } | checkAccessorsAreSimpleAndFieldIsInaccessible |
31,344 | boolean (@NotNull PsiField field, @NotNull PsiMethod setter) { final String nameBySetter = GroovyPropertyUtils.getPropertyNameBySetterName(setter.getName()); return field.getName().equals(nameBySetter); } | checkSetterIsSimple |
31,345 | boolean (@NotNull PsiField field, @NotNull PsiMethod getter) { final String nameByGetter = GroovyPropertyUtils.getPropertyNameByGetterName(getter.getName(), true); return field.getName().equals(nameByGetter); } | checkGetterIsSimple |
31,346 | boolean (PsiField field, @NotNull GrReferenceExpression place) { PsiResolveHelper helper = JavaPsiFacade.getInstance(field.getProject()).getResolveHelper(); return helper.isAccessible(field, place, getAccessObject(place)); } | checkFieldIsInaccessible |
31,347 | void (@NotNull GrMethodCallExpression methodCall) { if (JavaStylePropertiesUtil.isPropertyAccessor(methodCall)) { JavaStylePropertiesUtil.fixJavaStyleProperty(methodCall); } } | tryToSimplify |
31,348 | GrStatement (@Nullable GrStatementOwner declarationOwner, @NotNull ExtractInfoHelper helper) { GrStatement realStatement; if (declarationOwner != null && !isSingleExpression(helper.getStatements()) && helper.getStringPartInfo() == null) { // Replace set of statements final GrStatement[] newStatement = createResultStatement(helper); // add call statement final GrStatement[] statements = helper.getStatements(); LOG.assertTrue(statements.length > 0); realStatement = null; for (GrStatement statement : newStatement) { realStatement = declarationOwner.addStatementBefore(statement, statements[0]); JavaCodeStyleManager.getInstance(realStatement.getProject()).shortenClassReferences(realStatement); } LOG.assertTrue(realStatement != null); // remove old statements removeOldStatements(declarationOwner, helper); PsiImplUtil.removeNewLineAfter(realStatement); } else { GrExpression oldExpr; if (helper.getStringPartInfo() != null) { oldExpr = helper.getStringPartInfo().replaceLiteralWithConcatenation("xyz"); } else { oldExpr = (GrExpression)helper.getStatements()[0]; } // Expression call replace GrExpression methodCall = createMethodCall(helper); realStatement = oldExpr.replaceWithExpression(methodCall, true); JavaCodeStyleManager.getInstance(realStatement.getProject()).shortenClassReferences(realStatement); } return realStatement; } | replaceStatement |
31,349 | boolean (List<VariableInfo> toAdd, VariableInfo[] outputVars) { if (toAdd.size() != outputVars.length) return false; Set<String> names = new HashSet<>(); for (VariableInfo info : toAdd) { names.add(info.getName()); } for (VariableInfo var : outputVars) { if (!names.contains(var.getName())) return false; } return true; } | varsAreEqual |
31,350 | GrStatement[] (final VariableInfo[] infos, GrMethodCallExpression callExpression, final Project project) { GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project); StringBuilder tuple = new StringBuilder(); tuple.append("def ("); for (VariableInfo info : infos) { final PsiType type = info.getType(); if (type != null) { final PsiType unboxed = TypesUtil.unboxPrimitiveTypeWrapper(type); tuple.append(unboxed.getCanonicalText()); tuple.append(' '); } tuple.append(info.getName()); tuple.append(","); } StringUtil.trimEnd(tuple, ","); tuple.append(")="); tuple.append(callExpression.getText()); return new GrStatement[]{factory.createStatementFromText(tuple)}; } | createTupleDeclaration |
31,351 | List<GrStatement> (List<VariableInfo> varInfos, Project project, @Nullable GrExpression initializer) { List<GrStatement> result = new ArrayList<>(); if (varInfos.isEmpty()) return result; GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project); boolean distinctDeclaration = haveDifferentTypes(varInfos); if (distinctDeclaration) { for (VariableInfo info : varInfos) { result.add(factory.createVariableDeclaration(ArrayUtilRt.EMPTY_STRING_ARRAY, "", info.getType(), info.getName())); } } else { String[] names = new String[varInfos.size()]; for (int i = 0, mustAddLength = varInfos.size(); i < mustAddLength; i++) { names[i] = varInfos.get(i).getName(); } result.add(factory.createVariableDeclaration(ArrayUtilRt.EMPTY_STRING_ARRAY, initializer, varInfos.get(0).getType(), names)); } return result; } | generateVarDeclarations |
31,352 | boolean (List<VariableInfo> varInfos) { if (varInfos.size() < 2) return true; Set<String> diffTypes = new HashSet<>(); for (VariableInfo info : varInfos) { final PsiType t = info.getType(); diffTypes.add(t == null ? null : TypesUtil.unboxPrimitiveTypeWrapper(t).getCanonicalText()); } return diffTypes.size() > 1; } | haveDifferentTypes |
31,353 | GrStatement (VariableInfo[] infos, GrMethodCallExpression callExpression, final Project project) { StringBuilder text = new StringBuilder(); if (infos.length > 1) text.append('('); for (VariableInfo info : infos) { text.append(info.getName()).append(", "); } if (infos.length > 1) { text.replace(text.length() - 2, text.length(), ") ="); } else { text.replace(text.length() - 2, text.length(), " = "); } text.append(callExpression.getText()); return GroovyPsiElementFactory.getInstance(project).createExpressionFromText(text.toString()); } | createAssignment |
31,354 | List<VariableInfo> (GrStatement @NotNull [] statements, VariableInfo @NotNull [] vars) { Map<String, VariableInfo> names = new HashMap<>(); for (VariableInfo var : vars) { names.put(var.getName(), var); } List<VariableInfo> result = new ArrayList<>(); for (GrStatement statement : statements) { if (statement instanceof GrVariableDeclaration declaration) { for (GrVariable variable : declaration.getVariables()) { final VariableInfo removed = names.remove(variable.getName()); if (removed != null) { result.add(removed); } } } } for (String varName : names.keySet()) { if (ResolveUtil.resolveProperty(statements[statements.length - 1], varName) == null) { result.add(names.get(varName)); } } return result; } | mustAddVariableDeclaration |
31,355 | TextRange (ExtractInfoHelper helper) { final StringPartInfo stringPartInfo = helper.getStringPartInfo(); if (stringPartInfo != null) { return stringPartInfo.getRange(); } else { final GrStatement[] statements = helper.getStatements(); int start = statements[0].getTextRange().getStartOffset(); int end = statements[statements.length - 1].getTextRange().getEndOffset(); return new TextRange(start, end); } } | getRangeOfRefactoring |
31,356 | Collection<GrVariable> (ExtractInfoHelper helper) { final Collection<GrVariable> result = new HashSet<>(); final TextRange range = getRangeOfRefactoring(helper); final int start = range.getStartOffset(); final int end = range.getEndOffset(); final GroovyRecursiveElementVisitor visitor = new GroovyRecursiveElementVisitor() { @Override public void visitReferenceExpression(@NotNull GrReferenceExpression ref) { final PsiElement resolved = ref.resolve(); if ((resolved instanceof GrParameter || PsiUtil.isLocalVariable(resolved)) && resolved.isPhysical()) { final int offset = resolved.getTextRange().getStartOffset(); //var is declared outside of selected code if (offset < start || end <= offset) { result.add((GrVariable)resolved); } } } }; final GrStatement[] statements = helper.getStatements(); for (GrStatement statement : statements) { statement.accept(visitor); } return result; } | collectUsedLocalVarsOrParamsDeclaredOutside |
31,357 | void (@NotNull GrReferenceExpression ref) { final PsiElement resolved = ref.resolve(); if ((resolved instanceof GrParameter || PsiUtil.isLocalVariable(resolved)) && resolved.isPhysical()) { final int offset = resolved.getTextRange().getStartOffset(); //var is declared outside of selected code if (offset < start || end <= offset) { result.add((GrVariable)resolved); } } } | visitReferenceExpression |
31,358 | GrMethod (ExtractMethodInfoHelper helper) { StringBuilder buffer = new StringBuilder(); //Add signature PsiType type = helper.getOutputType(); final PsiPrimitiveType outUnboxed = PsiPrimitiveType.getUnboxedType(type); if (outUnboxed != null) type = outUnboxed; String modifier = getModifierString(helper); String typeText = getTypeString(helper, false, modifier); buffer.append(modifier); buffer.append(typeText); appendName(buffer, helper.getName()); buffer.append("("); for (String param : getParameterString(helper, true)) { buffer.append(param); } buffer.append(") { \n"); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(helper.getProject()); generateBody(helper, PsiTypes.voidType().equals(type), buffer, helper.isForceReturn()); buffer.append("\n}"); String methodText = buffer.toString(); return factory.createMethodFromText(methodText, helper.getContext()); } | createMethod |
31,359 | void (@NotNull final StringBuilder buffer, @NotNull final String name) { if (GroovyNamesUtil.isIdentifier(name)) { buffer.append(name); } else { buffer.append("'"); buffer.append(GrStringUtil.escapeSymbolsForString(name, true, false)); buffer.append("'"); } } | appendName |
31,360 | void (ExtractInfoHelper helper, boolean isVoid, StringBuilder buffer, boolean forceReturn) { VariableInfo[] outputInfos = helper.getOutputVariableInfos(); ParameterInfo[] infos = helper.getParameterInfos(); Set<String> declaredVars = new HashSet<>(); for (ParameterInfo info : infos) { declaredVars.add(info.getName()); } for (VariableInfo info : mustAddVariableDeclaration(helper.getStatements(), outputInfos)) { declaredVars.add(info.getName()); } List<VariableInfo> genDecl = new ArrayList<>(); final Collection<GrVariable> outside = collectUsedLocalVarsOrParamsDeclaredOutside(helper); for (final GrVariable variable : outside) { if (!declaredVars.contains(variable.getName())) { genDecl.add(new VariableInfo() { @NotNull @Override public String getName() { return variable.getName(); } @Override public PsiType getType() { return variable.getDeclaredType(); } }); } } final List<GrStatement> statements = generateVarDeclarations(genDecl, helper.getProject(), null); for (GrStatement statement : statements) { buffer.append(statement.getText()).append('\n'); } final StringPartInfo stringPartInfo = helper.getStringPartInfo(); if (!isSingleExpression(helper.getStatements()) && stringPartInfo == null) { for (PsiElement element : helper.getInnerElements()) { buffer.append(element.getText()); } //append return statement if (!isVoid && outputInfos.length > 0) { buffer.append('\n'); if (forceReturn) { buffer.append("return "); } if (outputInfos.length > 1) buffer.append('['); for (VariableInfo info : outputInfos) { buffer.append(info.getName()).append(", "); } buffer.delete(buffer.length() - 2, buffer.length()); if (outputInfos.length > 1) buffer.append(']'); } } else { GrExpression expr = stringPartInfo != null ? stringPartInfo.createLiteralFromSelected() : (GrExpression)PsiUtil.skipParentheses(helper.getStatements()[0], false); boolean addReturn = !isVoid && forceReturn && !PsiUtil.isVoidMethodCall(expr); if (addReturn) { buffer.append("return "); final GrExpression methodCall = ApplicationStatementUtil.convertToMethodCallExpression(expr); buffer.append(methodCall.getText()); } else { buffer.append(expr != null ? expr.getText() : ""); } } } | generateBody |
31,361 | String () { return variable.getName(); } | getName |
31,362 | PsiType () { return variable.getDeclaredType(); } | getType |
31,363 | String[] (ExtractInfoHelper helper, boolean useCanonicalText) { int i = 0; ParameterInfo[] infos = helper.getParameterInfos(); int number = 0; for (ParameterInfo info : infos) { if (info.passAsParameter) number++; } ArrayList<String> params = new ArrayList<>(); for (ParameterInfo info : infos) { if (info.passAsParameter) { PsiType paramType = info.type; final PsiPrimitiveType unboxed = PsiPrimitiveType.getUnboxedType(paramType); if (unboxed != null) paramType = unboxed; String paramTypeText; if (paramType == null || paramType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) || paramType.equals(PsiTypes.nullType())) { paramTypeText = ""; } else { paramTypeText = (useCanonicalText ? paramType.getCanonicalText() : paramType.getPresentableText()) + " "; } params.add(paramTypeText + info.getName() + (i < number - 1 ? ", " : "")); i++; } } return ArrayUtilRt.toStringArray(params); } | getParameterString |
31,364 | String (@NotNull ExtractMethodInfoHelper helper, boolean forPresentation, @NotNull String modifier) { if (!helper.specifyType()) { return modifier.isEmpty() ? "def " : ""; } PsiType type = helper.getOutputType(); final PsiPrimitiveType unboxed = PsiPrimitiveType.getUnboxedType(type); if (unboxed != null) type = unboxed; final String returnType = StringUtil.notNullize(forPresentation ? type.getPresentableText() : type.getCanonicalText()); if (StringUtil.isEmptyOrSpaces(returnType) || "null".equals(returnType)) { return modifier.isEmpty() ? "def " : ""; } else { return returnType + " "; } } | getTypeString |
31,365 | boolean (GrStatement[] statements) { return statements.length == 1 && statements[0] instanceof GrExpression && !(statements[0].getParent() instanceof GrVariableDeclarationOwner && statements[0] instanceof GrAssignmentExpression); } | isSingleExpression |
31,366 | GrMethodCallExpression (ExtractInfoHelper helper) { StringBuilder buffer = new StringBuilder(); appendName(buffer, helper.getName()); buffer.append("("); int number = 0; for (ParameterInfo info : helper.getParameterInfos()) { if (info.passAsParameter) number++; } int i = 0; String[] argumentNames = helper.getArgumentNames(); for (String argName : argumentNames) { if (!argName.isEmpty()) { buffer.append(argName); if (i < number - 1) { buffer.append(","); } i++; } } buffer.append(")"); String callText = buffer.toString(); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(helper.getProject()); GrExpression expr = factory.createExpressionFromText(callText); LOG.assertTrue(expr instanceof GrMethodCallExpression, callText); return ((GrMethodCallExpression)expr); } | createMethodCall |
31,367 | int (@NotNull GrStatement statement) { if (statement instanceof GrVariableDeclaration) { GrVariable[] variables = ((GrVariableDeclaration)statement).getVariables(); if (variables.length > 0) { GrExpression initializer = variables[0].getInitializerGroovy(); if (initializer != null) { return initializer.getTextOffset(); } } } else if (statement instanceof GrAssignmentExpression) { GrExpression value = ((GrAssignmentExpression)statement).getRValue(); if (value != null) { return value.getTextOffset(); } } return statement.getTextOffset(); } | getCaretOffset |
31,368 | String (ExtractMethodInfoHelper helper) { String visibility = helper.getVisibility(); LOG.assertTrue(visibility != null && !visibility.isEmpty()); final StringBuilder builder = new StringBuilder(); builder.append(visibility); builder.append(" "); if (helper.isStatic()) { builder.append("static "); } return builder.toString(); } | getModifierString |
31,369 | PsiType (VariableInfo[] outputInfos, GrStatement[] statements, ArrayList<GrStatement> returnStatements, boolean hasReturnValue, StringPartInfo stringPartInfo) { if (stringPartInfo != null) { return stringPartInfo.getLiteral().getType(); } PsiType outputType = PsiTypes.voidType(); if (outputInfos.length > 0) { if (outputInfos.length == 1) { outputType = outputInfos[0].getType(); } else { outputType = JavaPsiFacade.getElementFactory(myProject).createTypeFromText(CommonClassNames.JAVA_UTIL_LIST, getContext()); } } else if (ExtractUtil.isSingleExpression(statements)) { outputType = ((GrExpression)statements[0]).getType(); } else if (hasReturnValue) { assert !returnStatements.isEmpty(); List<PsiType> types = new ArrayList<>(returnStatements.size()); for (GrStatement statement : returnStatements) { if (statement instanceof GrReturnStatement) { GrExpression returnValue = ((GrReturnStatement)statement).getReturnValue(); if (returnValue != null) { types.add(returnValue.getType()); } } else if (statement instanceof GrExpression) { types.add(((GrExpression)statement).getType()); } } outputType = TypesUtil.getLeastUpperBoundNullable(types, getContext().getManager()); } return outputType; } | inferOutputType |
31,370 | Project () { return myProject; } | getProject |
31,371 | PsiType () { return myOutputType; } | getOutputType |
31,372 | boolean () { return myHasReturnValue; } | hasReturnValue |
31,373 | String () { throw new UnsupportedOperationException(); } | getName |
31,374 | PsiElement () { return myStatements.length > 0 ? myStatements[0] : myStringPartInfo.getLiteral(); } | getContext |
31,375 | boolean () { return false; } | isForceReturn |
31,376 | StringPartInfo () { return myStringPartInfo; } | getStringPartInfo |
31,377 | GrVariable () { return myVariable; } | getVar |
31,378 | void (ExtractInfoHelper helper) { super.init(helper.getParameterInfos(), helper.getProject(), helper.getContext()); } | init |
31,379 | TypeSelector (Project project, VariableData data, PsiElement[] scopeElements) { final PsiType type = data.type; return new TypeSelector(type != null ? type : PsiType.getJavaLangObject(PsiManager.getInstance(project), scopeElements[0].getResolveScope()), project); } | createSelector |
31,380 | Project () { return myInitialInfo.getProject(); } | getProject |
31,381 | PsiType () { return myInitialInfo.getOutputType(); } | getOutputType |
31,382 | StringPartInfo () { return myInitialInfo.getStringPartInfo(); } | getStringPartInfo |
31,383 | GrVariable () { return myInitialInfo.getVar(); } | getVar |
31,384 | boolean () { return myInitialInfo.hasReturnValue(); } | hasReturnValue |
31,385 | PsiElement () { return myInitialInfo.getContext(); } | getContext |
31,386 | boolean () { return myInitialInfo.isForceReturn(); } | isForceReturn |
31,387 | int () { return myPosition; } | getPosition |
31,388 | void (int position) { myPosition = position; } | setPosition |
31,389 | boolean (GrStatement[] statements) { final GrStatement statement0 = statements[0]; PsiElement returnFrom = PsiTreeUtil.getParentOfType(statement0, GrMethod.class, GrClosableBlock.class, GroovyFile.class); if (returnFrom instanceof GrMethod) { returnFrom = ((GrMethod)returnFrom).getBlock(); } LOG.assertTrue(returnFrom instanceof GrStatementOwner); final GrStatement[] blockStatements = ((GrStatementOwner)returnFrom).getStatements(); final GrStatement lastFromBlock = ArrayUtil.getLastElement(blockStatements); final GrStatement lastStatement = ArrayUtil.getLastElement(statements); return statement0.getManager().areElementsEquivalent(lastFromBlock, lastStatement); } | isLastStatementOfMethodOrClosure |
31,390 | GrStatement[] (PsiElement[] elements) { ArrayList<GrStatement> statementList = new ArrayList<>(); for (PsiElement element : elements) { if (element instanceof GrStatement) { statementList.add(((GrStatement)element)); } } return statementList.toArray(GrStatement.EMPTY_ARRAY); } | getStatementsByElements |
31,391 | PsiElement[] (PsiFile file, int startOffset, int endOffset, boolean forceStatements) { GrExpression expr = PsiImplUtil.findElementInRange(file, startOffset, endOffset, GrExpression.class); if (!forceStatements && expr != null) return new PsiElement[]{expr}; if (expr == null) { return GroovyRefactoringUtil.findStatementsInRange(file, startOffset, endOffset, true); } if (expr.getParent() instanceof GrMethodCallExpression) { expr = ((GrExpression)expr.getParent()); } return new PsiElement[]{expr}; } | getElementsInOffset |
31,392 | boolean (GrStatement statement, Collection<GrStatement> returnStatements) { if (statement instanceof GrReturnStatement) return true; if (statement instanceof GrIfStatement) { boolean checked = GroovyInlineMethodUtil.checkTailIfStatement(((GrIfStatement)statement), returnStatements); return checked && returnStatements.isEmpty(); } if (statement instanceof GrExpression) { return returnStatements.contains(statement); } return false; } | isReturnStatement |
31,393 | GrParameterListOwner () { return myOwner; } | getToReplaceIn |
31,394 | PsiElement () { return myToSearchFor; } | getToSearchFor |
31,395 | String () { return myName; } | getName |
31,396 | boolean () { return myFinal; } | declareFinal |
31,397 | IntList () { return myToRemove; } | parametersToRemove |
31,398 | int () { return myReplaceFieldsWithGetters; } | replaceFieldsWithGetters |
31,399 | boolean () { return false; } | removeLocalVariable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.