Skip to content

Commit

Permalink
fix bugs of pattern load
Browse files Browse the repository at this point in the history
  • Loading branch information
luyaor committed Mar 28, 2020
1 parent cfffdda commit 7d8567d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 84 deletions.
34 changes: 1 addition & 33 deletions src/main/java/GlobalSearch.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
import com.intellij.codeInsight.completion.AllClassesGetter;
import com.intellij.codeInsight.completion.PlainPrefixMatcher;
import com.intellij.diff.DiffContentFactory;
import com.intellij.diff.DiffManagerImpl;
import com.intellij.diff.DiffRequestPanel;
import com.intellij.diff.chains.DiffRequestChain;
import com.intellij.diff.chains.DiffRequestProducer;
import com.intellij.diff.chains.SimpleDiffRequestChain;
import com.intellij.diff.contents.DiffContent;
import com.intellij.diff.impl.CacheDiffRequestChainProcessor;
import com.intellij.diff.impl.DiffRequestProcessor;
import com.intellij.diff.requests.DiffRequest;
import com.intellij.diff.requests.SimpleDiffRequest;
import com.intellij.diff.tools.simple.SimpleDiffViewer;
import com.intellij.diff.util.DiffUserDataKeys;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diff.SimpleContent;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.components.JBScrollBar;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.Processor;
import com.intellij.diff.DiffManager;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class GlobalSearch extends AnActionWithInit {

Expand All @@ -51,7 +19,7 @@ public void actionPerformed(AnActionEvent e) {

CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);

MultiTransViewer viewer = new MultiTransViewer(project);
TransListViewer viewer = new TransListViewer(project);

psiFile.acceptChildren(new JavaRecursiveElementVisitor() {
@Override
Expand Down
15 changes: 1 addition & 14 deletions src/main/java/MultiApplyAction.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.table.JBTable;
import mfix.tools.Transformer;
import com.intellij.openapi.util.Pair;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public class MultiApplyAction extends AnActionWithInit {
Expand All @@ -41,7 +28,7 @@ public void actionPerformed(AnActionEvent e) {
return;
}

MultiTransViewer viewer = new MultiTransViewer(project);
TransListViewer viewer = new TransListViewer(project);
for (String p : candidates) {
PsiMethod targetMethod = str2PsiMethod(p);
codeStyleManager.reformat(targetMethod);
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/PatternLoadAction.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiElement;
import com.intellij.ui.components.JBScrollPane;
import mfix.tools.Transformer;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class PatternLoadAction extends AnActionWithInit {

@Override
public void actionPerformed(AnActionEvent e) {
GenpatService applicationService = ServiceManager.getService(GenpatService.class);
MultiTransViewer viewer = new MultiTransViewer(project);
TransListViewer viewer = new TransListViewer(project);
for (Transformer trans : applicationService.getState().transList) {
try {
viewer.addTrans(trans);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/TraceAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ public void actionPerformed(AnActionEvent e) {
return;
}

// ApplyAction.transformer.loadPatternSrc(psiCurrentUnit.getText(), psiFile.getText(), classPath);
Transformer newTrans = new Transformer();

newTrans.loadPatternSrc(methodTransPsi2Genpat((PsiMethod) psiCurrentUnit), psiFile.getText(), classPath);
PsiElement newUnit;
PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
String inputStr, outputStr;
try {
inputStr = changeEditor(project, "JAVA", psiCurrentUnit.getText());
String inputStr = changeEditor(project, "JAVA", psiCurrentUnit.getText());
newUnit = factory.createMethodFromText(inputStr, null);
if (!(newUnit instanceof PsiMethod)) {
throw new Exception("Input is not a method!");
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/TraceInIDEEnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ public void actionPerformed(AnActionEvent e) {
return;
}

ApplyAction.transformer.loadPatternTar(methodTransPsi2Genpat((PsiMethod) psiCurrentUnit), psiFile.getText(), classPath);
ApplyAction.transformer.extractPattern();
Transformer newTrans = new Transformer();
newTrans.loadPatternSrc(methodTransPsi2Genpat((PsiMethod) TraceInIDEStart.startPsiElement), TraceInIDEStart.startText, classPath);
newTrans.loadPatternTar(methodTransPsi2Genpat((PsiMethod) psiCurrentUnit), psiFile.getText(), classPath);
newTrans.extractPattern();

ServiceManager.getService(GenpatService.class).addTrans(newTrans);
ApplyAction.setTransformer(newTrans);

Messages.showMessageDialog(project, "Trace Finish!", "GenPat-Plugin", Messages.getInformationIcon());
}
}
7 changes: 5 additions & 2 deletions src/main/java/TraceInIDEStart.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import mfix.tools.Transformer;

public class TraceInIDEStart extends AnActionWithInit {
static PsiElement startPsiElement;
static String startText;

@Override
public void actionPerformed(AnActionEvent e) {
Expand All @@ -16,7 +19,7 @@ public void actionPerformed(AnActionEvent e) {

Messages.showMessageDialog(project, "Trace Start!", "GenPat-Plugin", Messages.getInformationIcon());

ApplyAction.transformer = new Transformer();
ApplyAction.transformer.loadPatternSrc(methodTransPsi2Genpat((PsiMethod) psiCurrentUnit), psiFile.getText(), classPath);
startPsiElement = psiCurrentUnit;
startText = psiFile.getText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class MultiTransViewer extends JPanel
implements ListSelectionListener {

public class TransListViewer extends JPanel implements ListSelectionListener {
Project curProject;
private int curIndex;
private JPanel mainPanel;
Expand Down Expand Up @@ -54,12 +54,13 @@ public void addMatchedElement(Pair<PsiElement, PsiElement> matchedElement) {

public void addTrans(Transformer trans) {
transformerList.add(trans);
String transName = "#" + diffList.size();
listModel.addElement(transName);
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = dateformat.format(System.currentTimeMillis());
listModel.addElement(dateStr);
addDiff(trans.getBeforeChangeCode(), trans.getAfterChangeCode());
}

public MultiTransViewer(Project project) {
public TransListViewer(Project project) {
curProject = project;
diffList = new Vector<>();
matchedElementList = new ArrayList<>();
Expand All @@ -80,12 +81,15 @@ public MultiTransViewer(Project project) {
DialogBuilder diffBuilder = new DialogBuilder(curProject);
diffPanel = DiffManager.getInstance().createRequestPanel(curProject, diffBuilder, diffBuilder.getWindow());
showDiff.add(diffPanel.getComponent());
showDiff.setPreferredSize(new Dimension(1000,300));

JScrollPane pictureScrollPane = new JScrollPane(showDiff);
JScrollPane diffScrollPane = new JScrollPane(showDiff);

//Create a split pane with the two scroll panes in it.
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listScrollPane, pictureScrollPane);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listScrollPane, diffScrollPane);

splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(100);

mainPanel = new JPanel();
mainPanel.add(splitPane);
Expand Down
24 changes: 11 additions & 13 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,26 @@
<group id="genpat.GroupedActions" text="GenPat" popup="true">
<add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="genpat.GroupedActions"/>

<!-- <action id="genpat-PatternLoadAction" class="PatternLoadAction" text="LoadPattern">-->
<!-- </action>-->

<!-- <action id="genpat.TraceInIDEStartAction" class="TraceInIDEStart" text="Local Trace Start">-->
<!-- <keyboard-shortcut keymap="$default" first-keystroke="shift alt OPEN_BRACKET"/>-->
<!-- </action>-->

<!-- <action id="genpat.TraceInIDEEndAction" class="TraceInIDEEnd" text="Local Trace End">-->
<!-- <keyboard-shortcut keymap="$default" first-keystroke="shift alt CLOSE_BRACKET"/>-->
<!-- </action>-->

<action id="genpat.GlobalSearch" class="GlobalSearch" text="Global Search">
</action>

<action id="genpat.PatternLoadAction" class="PatternLoadAction" text="Pattern Load">
</action>

<action id="genpat.PatternListCleanAction" class="PatternListCleanAction" text="Clean Pattern List">
</action>

<action id="genpat.TraceInIDEStartAction" class="TraceInIDEStart" text="Local Trace Start">
<keyboard-shortcut keymap="$default" first-keystroke="shift alt OPEN_BRACKET"/>
</action>

<action id="genpat.TraceInIDEEndAction" class="TraceInIDEEnd" text="Local Trace End">
<keyboard-shortcut keymap="$default" first-keystroke="shift alt CLOSE_BRACKET"/>
</action>

</group>

<action id="genpat.MultiApplyAction" class="MultiApplyAction" text="MultiApplyAction" description="TODO">
<action id="genpat.MultiApplyAction" class="MultiApplyAction" text="MultiApplyAction">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
</action>

Expand All @@ -57,7 +55,7 @@
<keyboard-shortcut keymap="$default" first-keystroke="shift alt EQUALS"/>
</action>

<action id="genpat.TraceAction" class="TraceAction" text="Trace" description="TODO">
<action id="genpat.TraceAction" class="TraceAction" text="Trace">
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
<keyboard-shortcut keymap="$default" first-keystroke="shift alt MINUS"/>
</action>
Expand Down

0 comments on commit 7d8567d

Please sign in to comment.