mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tostring inspection moved to analysis
This commit is contained in:
-78
@@ -15,22 +15,13 @@
|
||||
*/
|
||||
package org.jetbrains.generate.tostring;
|
||||
|
||||
import com.intellij.codeInsight.generation.PsiElementClassMember;
|
||||
import com.intellij.codeInsight.generation.PsiFieldMember;
|
||||
import com.intellij.codeInsight.generation.PsiMethodMember;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.generate.tostring.config.FilterPattern;
|
||||
import org.jetbrains.generate.tostring.exception.GenerateCodeException;
|
||||
import org.jetbrains.generate.tostring.exception.PluginException;
|
||||
import org.jetbrains.generate.tostring.psi.PsiAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -125,73 +116,4 @@ public class GenerateToStringUtils {
|
||||
}
|
||||
return availableMethods.toArray(new PsiMethod[availableMethods.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles any exception during the executing on this plugin.
|
||||
*
|
||||
* @param project PSI project
|
||||
* @param e the caused exception.
|
||||
* @throws RuntimeException is thrown for severe exceptions
|
||||
*/
|
||||
public static void handleException(Project project, Exception e) throws RuntimeException {
|
||||
log.info(e);
|
||||
|
||||
if (e instanceof GenerateCodeException) {
|
||||
// code generation error - display velocity error in error dialog so user can identify problem quicker
|
||||
Messages.showMessageDialog(project, "Velocity error generating code - see IDEA log for more details (stacktrace should be in idea.log):\n" + e.getMessage(), "Warning", Messages.getWarningIcon());
|
||||
} else if (e instanceof PluginException) {
|
||||
// plugin related error - could be recoverable.
|
||||
Messages.showMessageDialog(project, "A PluginException was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Warning", Messages.getWarningIcon());
|
||||
} else if (e instanceof RuntimeException) {
|
||||
// unknown error (such as NPE) - not recoverable
|
||||
Messages.showMessageDialog(project, "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Error", Messages.getErrorIcon());
|
||||
throw (RuntimeException) e; // throw to make IDEA alert user
|
||||
} else {
|
||||
// unknown error (such as NPE) - not recoverable
|
||||
Messages.showMessageDialog(project, "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Error", Messages.getErrorIcon());
|
||||
throw new RuntimeException(e); // rethrow as runtime to make IDEA alert user
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines the two lists into one list of members.
|
||||
*
|
||||
* @param filteredFields fields to be included in the dialog
|
||||
* @param filteredMethods methods to be included in the dialog
|
||||
* @return the combined list
|
||||
*/
|
||||
public static PsiElementClassMember[] combineToClassMemberList(PsiField[] filteredFields, PsiMethod[] filteredMethods) {
|
||||
PsiElementClassMember[] members = new PsiElementClassMember[filteredFields.length + filteredMethods.length];
|
||||
|
||||
// first add fields
|
||||
for (int i = 0; i < filteredFields.length; i++) {
|
||||
members[i] = new PsiFieldMember(filteredFields[i]);
|
||||
}
|
||||
|
||||
// then add methods
|
||||
for (int i = 0; i < filteredMethods.length; i++) {
|
||||
members[filteredFields.length + i] = new PsiMethodMember(filteredMethods[i]);
|
||||
}
|
||||
|
||||
return members;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the list of {@link PsiElementClassMember} to {PsiMember} objects.
|
||||
*
|
||||
* @param classMemberList list of {@link PsiElementClassMember}
|
||||
* @return a list of {PsiMember} objects.
|
||||
*/
|
||||
public static List<PsiMember> convertClassMembersToPsiMembers(@Nullable List<PsiElementClassMember> classMemberList) {
|
||||
if (classMemberList == null || classMemberList.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<PsiMember> psiMemberList = new ArrayList<PsiMember>();
|
||||
|
||||
for (PsiElementClassMember classMember : classMemberList) {
|
||||
psiMemberList.add(classMember.getElement());
|
||||
}
|
||||
|
||||
return psiMemberList;
|
||||
}
|
||||
}
|
||||
-1
@@ -18,7 +18,6 @@ package org.jetbrains.generate.tostring.config;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
-1
@@ -19,7 +19,6 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.generate.tostring.psi.PsiAdapter;
|
||||
|
||||
-1
@@ -18,7 +18,6 @@ package org.jetbrains.generate.tostring.config;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
-3
@@ -20,7 +20,6 @@ import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.ui.RegExFormatter;
|
||||
import com.intellij.codeInspection.ui.RegExInputVerifier;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
@@ -29,11 +28,9 @@ import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.generate.tostring.GenerateToStringContext;
|
||||
import org.jetbrains.generate.tostring.GenerateToStringUtils;
|
||||
import org.jetbrains.generate.tostring.util.StringUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.Document;
|
||||
import java.awt.*;
|
||||
import java.util.regex.Pattern;
|
||||
+3
-4
@@ -17,12 +17,12 @@ package org.jetbrains.generate.tostring.inspection;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.generate.tostring.GenerateToStringActionHandler;
|
||||
import org.jetbrains.generate.tostring.GenerateToStringActionHandlerImpl;
|
||||
|
||||
/**
|
||||
* Quick fix to run Generate toString() to fix any code inspection problems.
|
||||
@@ -31,8 +31,6 @@ public class GenerateToStringQuickFix implements LocalQuickFix {
|
||||
|
||||
public static final GenerateToStringQuickFix INSTANCE = new GenerateToStringQuickFix();
|
||||
|
||||
private final GenerateToStringActionHandler myHandler = new GenerateToStringActionHandlerImpl();
|
||||
|
||||
private GenerateToStringQuickFix() {}
|
||||
|
||||
public static GenerateToStringQuickFix getInstance() {
|
||||
@@ -57,6 +55,7 @@ public class GenerateToStringQuickFix implements LocalQuickFix {
|
||||
if (clazz == null) {
|
||||
return; // no class to fix
|
||||
}
|
||||
myHandler.executeActionQuickFix(project, clazz);
|
||||
GenerateToStringActionHandler handler = ServiceManager.getService(GenerateToStringActionHandler.class);
|
||||
handler.executeActionQuickFix(project, clazz);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -101,7 +101,7 @@ public class GenerateToStringActionHandlerImpl extends EditorWriteActionHandler
|
||||
dialog.show();
|
||||
|
||||
if (DialogWrapper.OK_EXIT_CODE == dialog.getExitCode()) {
|
||||
Collection<PsiMember> selectedMembers = GenerateToStringUtils.convertClassMembersToPsiMembers(dialog.getSelectedElements());
|
||||
Collection<PsiMember> selectedMembers = GenerationUtil.convertClassMembersToPsiMembers(dialog.getSelectedElements());
|
||||
|
||||
final TemplateResource template = header.getSelectedTemplate();
|
||||
TemplatesManager.getInstance().setDefaultTemplate(template);
|
||||
@@ -139,7 +139,7 @@ public class GenerateToStringActionHandlerImpl extends EditorWriteActionHandler
|
||||
filteredMethods = PsiMethod.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
return GenerateToStringUtils.combineToClassMemberList(filteredFields, filteredMethods);
|
||||
return GenerationUtil.combineToClassMemberList(filteredFields, filteredMethods);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -343,7 +343,7 @@ public class GenerateToStringWorker {
|
||||
new GenerateToStringWorker(clazz, editor, insertAtOverride).execute(selectedMembers, template);
|
||||
}
|
||||
catch (Exception e) {
|
||||
GenerateToStringUtils.handleException(clazz.getProject(), e);
|
||||
GenerationUtil.handleException(clazz.getProject(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.generate.tostring;
|
||||
|
||||
import com.intellij.codeInsight.generation.PsiElementClassMember;
|
||||
import com.intellij.codeInsight.generation.PsiFieldMember;
|
||||
import com.intellij.codeInsight.generation.PsiMethodMember;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.generate.tostring.exception.GenerateCodeException;
|
||||
import org.jetbrains.generate.tostring.exception.PluginException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GenerationUtil {
|
||||
private static final Logger log = Logger.getInstance("#org.jetbrains.generate.tostring.GenerationUtil");
|
||||
|
||||
/**
|
||||
* Handles any exception during the executing on this plugin.
|
||||
*
|
||||
* @param project PSI project
|
||||
* @param e the caused exception.
|
||||
* @throws RuntimeException is thrown for severe exceptions
|
||||
*/
|
||||
public static void handleException(Project project, Exception e) throws RuntimeException {
|
||||
log.info(e);
|
||||
|
||||
if (e instanceof GenerateCodeException) {
|
||||
// code generation error - display velocity error in error dialog so user can identify problem quicker
|
||||
Messages.showMessageDialog(project,
|
||||
"Velocity error generating code - see IDEA log for more details (stacktrace should be in idea.log):\n" +
|
||||
e.getMessage(), "Warning", Messages.getWarningIcon());
|
||||
} else if (e instanceof PluginException) {
|
||||
// plugin related error - could be recoverable.
|
||||
Messages.showMessageDialog(project, "A PluginException was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Warning", Messages.getWarningIcon());
|
||||
} else if (e instanceof RuntimeException) {
|
||||
// unknown error (such as NPE) - not recoverable
|
||||
Messages.showMessageDialog(project, "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Error", Messages.getErrorIcon());
|
||||
throw (RuntimeException) e; // throw to make IDEA alert user
|
||||
} else {
|
||||
// unknown error (such as NPE) - not recoverable
|
||||
Messages.showMessageDialog(project, "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + e.getMessage(), "Error", Messages.getErrorIcon());
|
||||
throw new RuntimeException(e); // rethrow as runtime to make IDEA alert user
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines the two lists into one list of members.
|
||||
*
|
||||
* @param filteredFields fields to be included in the dialog
|
||||
* @param filteredMethods methods to be included in the dialog
|
||||
* @return the combined list
|
||||
*/
|
||||
public static PsiElementClassMember[] combineToClassMemberList(PsiField[] filteredFields, PsiMethod[] filteredMethods) {
|
||||
PsiElementClassMember[] members = new PsiElementClassMember[filteredFields.length + filteredMethods.length];
|
||||
|
||||
// first add fields
|
||||
for (int i = 0; i < filteredFields.length; i++) {
|
||||
members[i] = new PsiFieldMember(filteredFields[i]);
|
||||
}
|
||||
|
||||
// then add methods
|
||||
for (int i = 0; i < filteredMethods.length; i++) {
|
||||
members[filteredFields.length + i] = new PsiMethodMember(filteredMethods[i]);
|
||||
}
|
||||
|
||||
return members;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the list of {@link com.intellij.codeInsight.generation.PsiElementClassMember} to {PsiMember} objects.
|
||||
*
|
||||
* @param classMemberList list of {@link com.intellij.codeInsight.generation.PsiElementClassMember}
|
||||
* @return a list of {PsiMember} objects.
|
||||
*/
|
||||
public static List<PsiMember> convertClassMembersToPsiMembers(@Nullable List<PsiElementClassMember> classMemberList) {
|
||||
if (classMemberList == null || classMemberList.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<PsiMember> psiMemberList = new ArrayList<PsiMember>();
|
||||
|
||||
for (PsiElementClassMember classMember : classMemberList) {
|
||||
psiMemberList.add(classMember.getElement());
|
||||
}
|
||||
|
||||
return psiMemberList;
|
||||
}
|
||||
}
|
||||
@@ -1517,6 +1517,8 @@
|
||||
|
||||
<applicationService serviceInterface="org.jetbrains.generate.tostring.template.TemplatesManager"
|
||||
serviceImplementation="org.jetbrains.generate.tostring.template.TemplatesManager"/>
|
||||
<applicationService serviceInterface="org.jetbrains.generate.tostring.GenerateToStringActionHandler"
|
||||
serviceImplementation="org.jetbrains.generate.tostring.GenerateToStringActionHandlerImpl"/>
|
||||
<applicationService serviceInterface="org.jetbrains.generate.tostring.GenerateToStringContext"
|
||||
serviceImplementation="org.jetbrains.generate.tostring.GenerateToStringContext"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user