354 questions
46
votes
1
answer
8k
views
Eclipse : transform static method invocation to a static import
Is there a way to transform automatically this static method invocation (Arrays.asList):
import java.util.Arrays;
import java.util.List;
public class StaticImport {
public static void main(...
34
votes
6
answers
14k
views
How to refactor a static inner class to a top level class in Eclipse?
I am having trouble finding the correct refactor option for the following scenario:
I have code like this (in Outer.java):
public class Outer {
// ... class stuff
public static class Inner ...
30
votes
3
answers
3k
views
R language aware code reformatting/refactoring tools?
Recently I've found myself working with R code that is all over the map in terms of coding style - multiple authors and individual authors who aren't rigorous about sticking to a single structure. ...
27
votes
2
answers
11k
views
Automated refactoring to add parameter names to method calls
I am in the middle of a big refactoring.
I have dozens of methods, which are called via positional parameters. Now I would like to have them called via named parameters. The methods exist in several, ...
23
votes
12
answers
2k
views
Java source refactoring of 7000 references
I need to change the signature of a method used all over the codebase.
Specifically, the method void log(String) will take two additional arguments (Class c, String methodName), which need to be ...
21
votes
6
answers
8k
views
C / C++ packages to understand code for refactoring
I am about to starting to work on a project which involves refactoring and modifying existing code which is in c & c++. The code is a bloated one and is in huge volume. Of course since the code ...
20
votes
5
answers
6k
views
Are there any open source command line tools to refactor java code? [closed]
I use vim as my editor but I would like to get some of the same power of the IDE's for java when it comes to refactoring. Are there any commandline tools for refactoring java? I could probably hack ...
19
votes
3
answers
10k
views
Refactor Pro versus Visual Assist X for C++ Development [closed]
There are two major refactoring tools which can be installed for Visual Studio that provide C++ support. The full versions of both tools are $250, and they seem to offer similar functionality. They ...
18
votes
5
answers
4k
views
Auto generify non-generic interface implementation
I have interface
public interface ObjectBuilder<E> {
E buildObject();
}
Also, the project has a lot of classes that implement non-generic version of the interface.
class MyClassBuilder ...
18
votes
5
answers
22k
views
How to detect dead or unused code in Angular?
I and my team are working on an angular application from more than a year now. As part of our code refactoring process we want to delete unused or dead code from our repo.
Is there any technique or ...
17
votes
1
answer
2k
views
Simple Custom Refactoring in IntelliJ
This question is a follow-up for this.
Say I have some class Foo.
class Foo {
protected String x = "x";
public String getX() {
return x;
}
}
I have a program that uses ...
17
votes
2
answers
5k
views
Xcode: How to refactor/rename method and ADD (or REMOVE) its PARAMETERS?
Is Xcode 5 able to change method's signature? As far as I can tell no, but I'd like to be shown wrong.
If I either try to add (or remove) a method's parameter, I am welcomed by the Needs 1 fewer (...
16
votes
3
answers
30k
views
Getting clang-tidy to fix header files
I'm in the process of moving a project currently compiling with gcc to clang,
and have a bunch of warnings that gcc didn't generate (-Winconsistent-missing-override). clang-tidy works for fixing these ...
16
votes
4
answers
5k
views
Automatically split (refactor) .h into header and implementation (h+cpp)
When writing C++ code, I often start by writing full 'implementation' code in my header files, then later need to refactor the implementation into a .cpp file.
This is great, but I find this process ...
15
votes
3
answers
7k
views
Is there way for extracting string resources in Android project in IntelliJ IDE?
When I'm working on Android project I would like to use some magic shortcut that would extract my string to strings.xml and also allow me to change the key. Is there any?
If there isn't, is there a ...
15
votes
3
answers
10k
views
Automatic regenerate designer files
Recently I've been making some improvements to a lot of the controls we use, for example give properties default values and making buttons private instead of protected.
By making this kind of ...
14
votes
1
answer
5k
views
Moving function/method to class
Using pycharm, I wish to refactor methods into a class. (Staticmethod would do)
Current:
import math
class Solver(object):
def __init__(self, a, b, c):
self.a = a
self.b = b
...
13
votes
4
answers
19k
views
Intellij Idea How to add interface implementation to classes?
For example I have many classes than implement my interface. After adding new method definition in the interface, how can I fast-add blank interface implementations for all that classes?
13
votes
5
answers
9k
views
Python: Good way to get function and all dependencies in a single file? [closed]
I'm working on a big Python code base that grows and grows and grows. It's not a single application - more of a bunch of experiments that share some common code.
Every so often, I want to make a ...
13
votes
3
answers
18k
views
Python refactoring fails in Visual Studio Code
I switched to Visual Studio Code for Python programming recently. Below is my Python configuration in Visual Studio Code settings:
"python.pythonPath": "/Users/hzhang/.virtualenvs/env-2.7/bin/python",...
13
votes
4
answers
4k
views
Tool to parse C++ source and move in-header inline methods to the .cpp source file? [closed]
The source code of our application is hundreds of thousands of line, thousands of files, and in places very old - the app was first written in 1995 or 1996. Over the past few years my team has ...
12
votes
3
answers
7k
views
Is there a tool for Scala to clean all the unused imports from all the code files? [closed]
I believe my source code files feature many imports that are not used in the code (as I have a bad habit of copying them from existing to new files). When coding C# in Visual Studio (or, maybe, it's a ...
12
votes
3
answers
2k
views
How can I implement my own type of extern?
In our product, we have things called "services" which are the basic means of communication between different parts of the product (and especially between languages—an in-house language, C, Python and ...
12
votes
1
answer
706
views
Is there a way to refactor C++11 code into C++ code that can be compiled by a less capable compiler?
This has implications on code portability of C++11 code in general. I am talking about having a new code generation stage akin to the C/C++ preprocessor stage wherein we can make the generated C++ ...
11
votes
2
answers
5k
views
Is there a command line tool to Optimize Imports on Java project?
I'm looking for a tool that will automate the process of optimizing the imports on a code base. This tool is available in most IDEs (IntelliJ for instance) which removes unused imports and expands ...
11
votes
1
answer
2k
views
Refactor class method to property using Pycharm
I have the following class:
class Dogs(object):
def __init__(self):
self.names = []
self.breeds = set()
def number(self):
return len(self.names)
I want to change ...
11
votes
2
answers
1k
views
TypeScript Compiler API loses formatting during transformation
I have to modify around 1 000 of typescript files in a specific way: I need to replace all StringLiteral and JsxText tokens with a CallExpression to a translation function for internationalization ...
10
votes
10
answers
7k
views
Automatically deleting unused local variables from C source code
I want to delete unused local variables from C file.
Example:
int fun(int a , int b)
{
int c,sum=0;
sum=a + b;
return sum;
}
Here the unused variable is 'c'.
I will externally have a list of ...
10
votes
1
answer
23k
views
Python Black Code Formatter - Is there any way to apply automatic black formatting before commiting project to Github
Recently I started to use Black code formatter for my projects and sometimes it can be hard to track did I formatted all my changed files or not.
Let's assume that my project contains 20 different ...
10
votes
1
answer
15k
views
Is there an option to remove unused references on save in Visual Studio 2022?
Is there an option to remove and sort usings automatically on save for the current document? This used to be provided by the Power Commands for Visual Studio extension. Is this available somewhere in ...
10
votes
6
answers
19k
views
How to move a method from a class to another class when two classes are not at all related
I am trying to re factor some code by breaking a class into several other classes.
to do so i want to move some methods already existing in my old class to new class.
But these methods are being ...
10
votes
1
answer
2k
views
Applying a Typescript refactoring programmatically
VS Code has a 'Convert namespace import to named imports' refactoring. As far as I understand, the refactoring is defined in the Typescript codebase itself, so it's not specific to VS Code.
I need to ...
10
votes
6
answers
5k
views
Refactoring to move a private field from one class to its helper class?
EDIT : I submitted an Eclipse enhancement request for this refactoring.
Is there a way to move a private field from one class to its helper class? The below chicken-scratch UML shows what I'm doing ...
10
votes
3
answers
2k
views
Resharper find pattern and replace - how to insert strings
We have a sanity check method
void IsNotNull<T>(T obj){...}
invocation
IsNotNull(obj);
I want to replace this to invoke the other overload that takes a second param of type string (message)
...
10
votes
1
answer
1k
views
Is there a way I can define a custom refactoring in Visual Studio Code?
It is possible to define custom snippets of code that VS Code can auto complete. These can even use place-holders so that one can fill in the blanks as required.
/* Before */
//=
/* After (for ...
9
votes
1
answer
13k
views
Name Can Be Simplified - Visual Studio
Is there a way to do all the lightbulb-action for a whole Solution and with a button or a shortcut?
Or to add a using for a term which could be simplyfied but is not shown through a lightbulb?
I have ...
9
votes
3
answers
2k
views
How to automate Java code refactoring using a script with instructions?
How to refactor this class programmatically via Java code/Groovy plugin?
Let's say, I need to:
Rename foo.method2 to foo.method3
Rename myMethod to yourMethod
Change the imported package org.you.core....
9
votes
1
answer
1k
views
Update namespace and imports of other files after moving class
Does anyone know if it's possible to configure VSCode to have the following occur after moving a file to another locations?
Update the namespace of the class/trait.
Update the imports of all other ...
9
votes
1
answer
626
views
Clang-Format: recombine string literals
Is there a way to get clang-format to turn this:
function_name("a very very " | <-- column limit
"very very " |
"long string"); ...
9
votes
1
answer
1k
views
Renaming a class file no longer prompts to rename all occurrences
It used to be that when I renamed a class file (maybe also others) in VS2012, it prompted me to renamed everything, then did a nice refactor after renaming the class to the new file name. It suddenly ...
8
votes
8
answers
10k
views
Refactor foreach to for loop
I have a foreach loop in Java (simplified version here)
List<String> names = getNames();
for(String name:names) {
doSomething(name);
}
Is there an automated way to refactor this to a ...
8
votes
3
answers
3k
views
Automated-refactoring tool to find similar duplicate source code for Java/Javascript? [closed]
I'm looking for a tool to find duplicate or similar code of Java/Javascript. I can't tell the exact definition of "similar", but I wish the tool is smart enough and give me advices to refactor the ...
8
votes
1
answer
2k
views
Android Studio - Flutter Plugin - Moving method to another file by refactoring
Why I cannot (?) move a method from one Dart file to another using Android Studio and Flutter Plugin? My file is getting big and I decided to refactor it by separated some Widget build methods to ...
8
votes
1
answer
1k
views
IntelliJ like 'Extract Property' to extract maven artifact versions to properties in eclipse
IntelliJ provides Extract Property refactoring which can be used to extract maven artifact versions to properties in pom.xml.
Extract Property refactoring creates a new property definition in the ...
7
votes
7
answers
2k
views
Programming Language Properties that facilitate refactoring?
What are common traits/properties of programming languages that facilitate (simplify) the development of widely automated source code analysis and re-engineering (transformation) tools?
I am mostly ...
7
votes
3
answers
2k
views
Visual Studio : hotkey/way to automatically sort functions in .h to be consistent with .cpp
I want to make order of functions in header .h to be consistent with the order of functions in source file .cpp.
Example
B.h
class B{
void f2(); //<--- wrong order
void f1();
};
B.cpp
...
7
votes
3
answers
8k
views
Renaming variables in JavaScript
I've been stuck with the unpleasant task of "unminifying" a minified JavaScript code file. Using JSBeautifier, the resulting file is about 6000 lines long.
Ordinarily, the variable and parameter ...
7
votes
2
answers
2k
views
Opposite of Extract Method refactoring
Is there a way to perform the opposite of the "Extract Method" refactor in Visual Studio?
I have a legacy codebase that has ~50 very short, private functions that are only used once each, and I have ...
7
votes
2
answers
5k
views
IntelliJ Idea: automatically remove unnecessary "throws" declarations
Often after refactoring throws sections become unnecessary. IntelliJ highlights them with grey showing that they can be removed, but I'd like to remove them automatically (just like unused imports get ...
7
votes
4
answers
3k
views
C++ Refactoring - Move method to implementation file [closed]
I have lots of header files with long method implementation inside.
Is there An automatic way of doing that?
One-by-one can take a lot of time...
Thanks.