mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
ChangeUIDAction: make it work without initializer
This commit is contained in:
@@ -37,13 +37,16 @@ public class ChangeUIDAction extends PsiElementBaseIntentionAction {
|
||||
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
|
||||
PsiField field = PsiTreeUtil.getParentOfType(element, PsiField.class);
|
||||
if (field == null) return;
|
||||
PsiExpression initializer = field.getInitializer();
|
||||
if (initializer == null) return;
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
|
||||
Application application = ApplicationManager.getApplication();
|
||||
Random random = application.isUnitTestMode() ? new Random(42) : new SecureRandom();
|
||||
PsiExpression newInitializer = factory.createExpressionFromText(Long.toString(random.nextLong()) + "L", null);
|
||||
new CommentTracker().replaceAndRestoreComments(initializer, newInitializer);
|
||||
PsiExpression initializer = field.getInitializer();
|
||||
if (initializer != null) {
|
||||
new CommentTracker().replaceAndRestoreComments(initializer, newInitializer);
|
||||
} else {
|
||||
field.setInitializer(newInitializer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Randomly change 'serialVersionUID' initializer" "true"
|
||||
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Main {
|
||||
static final long serialVersionUID = -5025562857975149833L;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Randomly change 'serialVersionUID' initializer" "true"
|
||||
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Main {
|
||||
static final long serialVersionUID<caret>;
|
||||
}
|
||||
Reference in New Issue
Block a user