Here are the examples of the java api com.intellij.openapi.project.Project taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4284 Examples
19
Source : NotificationHelper.java
with GNU General Public License v2.0
from zhilepeng
with GNU General Public License v2.0
from zhilepeng
public static Notification showError(@Nullable Project project, String replacedle, String content) {
return showError(project, replacedle, null, content);
}
19
Source : NotificationHelper.java
with GNU General Public License v2.0
from zhilepeng
with GNU General Public License v2.0
from zhilepeng
public static Notification showInfo(@Nullable Project project, String content) {
return showInfo(project, null, null, content);
}
19
Source : NotificationHelper.java
with GNU General Public License v2.0
from zhilepeng
with GNU General Public License v2.0
from zhilepeng
public static Notification showWarn(@Nullable Project project, String content) {
return showWarn(project, null, null, content);
}
19
Source : NotificationHelper.java
with GNU General Public License v2.0
from zhilepeng
with GNU General Public License v2.0
from zhilepeng
public static Notification showWarn(@Nullable Project project, String replacedle, String content) {
return showWarn(project, replacedle, null, content);
}
19
Source : NotificationHelper.java
with GNU General Public License v2.0
from zhilepeng
with GNU General Public License v2.0
from zhilepeng
public static Notification showWarn(@Nullable Project project, String replacedle, String subreplacedle, String content) {
return show(project, replacedle, subreplacedle, content, NotificationType.WARNING);
}
19
Source : NotificationHelper.java
with GNU General Public License v2.0
from zhilepeng
with GNU General Public License v2.0
from zhilepeng
public static Notification showError(@Nullable Project project, String content) {
return showError(project, null, null, content);
}
19
Source : NotificationHelper.java
with GNU General Public License v2.0
from zhilepeng
with GNU General Public License v2.0
from zhilepeng
public static Notification showInfo(@Nullable Project project, String replacedle, String content) {
return showInfo(project, replacedle, null, content);
}
19
Source : GenCodeRequest.java
with Apache License 2.0
from zhengjunbase
with Apache License 2.0
from zhengjunbase
public void setProject(Project project) {
this.project = project;
}
19
Source : SpringHelper.java
with GNU Affero General Public License v3.0
from ZhangYuanSheng1217
with GNU Affero General Public License v3.0
from ZhangYuanSheng1217
@NotNull
public static List<Request> getSpringRequestByModule(@NotNull Project project, @NotNull Module module) {
List<Request> moduleList = new ArrayList<>(0);
List<PsiClreplaced> controllers = getAllControllerClreplaced(project, module);
if (controllers.isEmpty()) {
return moduleList;
}
for (PsiClreplaced controllerClreplaced : controllers) {
moduleList.addAll(getRequests(controllerClreplaced));
}
return moduleList;
}
19
Source : RequestUtil.java
with GNU Affero General Public License v3.0
from ZhangYuanSheng1217
with GNU Affero General Public License v3.0
from ZhangYuanSheng1217
/**
* 获取所有的Request
*
* @param project project
* @return map-{key: moduleName, value: itemRequestList}
*/
@NotNull
public static Map<String, List<Request>> getAllRequests(@NotNull Project project) {
return getAllRequests(project, false);
}
19
Source : ToolWindowServiceImpl.java
with GNU Affero General Public License v3.0
from ZhangYuanSheng1217
with GNU Affero General Public License v3.0
from ZhangYuanSheng1217
/**
* @author ZhangYuanSheng
* @version 1.0
*/
public clreplaced ToolWindowServiceImpl implements ToolWindowService {
private final Project project;
public ToolWindowServiceImpl(Project project) {
this.project = project;
}
@Override
public JComponent getContent() {
return new RightToolWindow(project);
}
}
19
Source : ToolWindowListenerImpl.java
with GNU Affero General Public License v3.0
from ZhangYuanSheng1217
with GNU Affero General Public License v3.0
from ZhangYuanSheng1217
/**
* @author ZhangYuanSheng
* @version 1.0
*/
public clreplaced ToolWindowListenerImpl implements ToolWindowManagerListener {
private final Project project;
public ToolWindowListenerImpl(Project project) {
this.project = project;
}
@SuppressWarnings("MissingRecentApi")
@Override
public void toolWindowShown(@NotNull String id, @NotNull ToolWindow toolWindow) {
if (Constants.Application.NAME.equals(id)) {
MessageBus bus = project.getMessageBus();
RefreshServiceTreeTopic publisher = bus.syncPublisher(RefreshServiceTreeTopic.TOPIC);
publisher.refresh();
}
}
}
19
Source : WithLibraryAction.java
with GNU Affero General Public License v3.0
from ZhangYuanSheng1217
with GNU Affero General Public License v3.0
from ZhangYuanSheng1217
private RightToolWindow getToolWindow(@Nullable Project project) {
if (toolWindow != null) {
return toolWindow;
}
return (toolWindow = RestfulToolWindowFactory.getToolWindow(project));
}
19
Source : PsiUtils.java
with MIT License
from zgqq
with MIT License
from zgqq
public static PsiClreplaced searchPsiClreplaced(PsiJavaFile data, Project project, PsiClreplaced targetClreplaced, PsiElement typePsi) {
final PsiClreplaced[] clreplacedesByName = PsiShortNamesCache.getInstance(project).getClreplacedesByName(typePsi.getText(), GlobalSearchScope.projectScope(project));
String fullname = data.getPackageName() + "." + typePsi.getText();
ConsoleUtils.log("Searching fullname " + fullname);
if (clreplacedesByName != null && clreplacedesByName.length > 0) {
for (PsiClreplaced psiClreplaced : clreplacedesByName) {
ConsoleUtils.log("Matching clreplaced " + psiClreplaced.getQualifiedName());
if (psiClreplaced.getQualifiedName().equals(fullname)) {
targetClreplaced = psiClreplaced;
}
}
}
return targetClreplaced;
}
19
Source : JumpHookAction.java
with MIT License
from zgqq
with MIT License
from zgqq
private ChainActionEvent createActionEvent(AnActionEvent e) {
Editor newEditor = getEditorFrom(e);
Project eventProject = getEventProject(e);
Runnable selectedHook = createRunnable(e);
return new ChainActionEvent(e, selectedHook, newEditor, eventProject);
}
19
Source : CreateRedisFieldAction.java
with MIT License
from zgqq
with MIT License
from zgqq
private PsiClreplaced getPsiClreplaced(PsiJavaFile data, Project project, PsiElement dotField) {
PsiClreplaced targetClreplaced = null;
PsiElement typePsi = data.findElementAt(dotField.getTextRange().getStartOffset() - 1);
ConsoleUtils.log("typeClreplaced", typePsi);
PsiImportStatementBase singleImportStatement = data.getImportList().findSingleImportStatement(typePsi.getText());
if (singleImportStatement == null) {
targetClreplaced = searchPsiClreplaced(data, project, targetClreplaced, typePsi);
} else {
targetClreplaced = (PsiClreplaced) singleImportStatement.resolve();
}
return targetClreplaced;
}
19
Source : TomcatSettingsEditor.java
with Apache License 2.0
from zengkid
with Apache License 2.0
from zengkid
/**
* Author : zengkid
* Date : 2/16/2017
* Time : 3:15 PM
*/
public clreplaced TomcatSettingsEditor extends SettingsEditor<TomcatRunConfiguration> {
private final Project project;
private final RunnerSetting runnerSetting;
public TomcatSettingsEditor(TomcatRunConfiguration tomcatRunConfiguration, Project project) {
runnerSetting = new RunnerSetting(project);
this.project = project;
super.resetFrom(tomcatRunConfiguration);
}
@Override
protected void resetEditorFrom(TomcatRunConfiguration tomcatRunConfiguration) {
TomcatInfo tomcatInfo = tomcatRunConfiguration.getTomcatInfo();
if (tomcatInfo != null) {
runnerSetting.getTomcatField().getComboBox().setSelectedItem(tomcatInfo);
}
String docBase = tomcatRunConfiguration.getDocBase();
if (docBase != null && !"".equals(docBase.trim())) {
runnerSetting.getDocBaseField().setText(docBase);
runnerSetting.getDocBaseField().getTextField().setText(docBase);
}
String contextPath = tomcatRunConfiguration.getContextPath();
if (contextPath != null && !"".equals(contextPath.trim())) {
runnerSetting.getContextPathField().setText(contextPath);
}
String port = tomcatRunConfiguration.getPort();
if (port != null && !"".equals(port.trim())) {
runnerSetting.getPortField().setText(port);
}
String adminPort = tomcatRunConfiguration.getAdminPort();
if (adminPort != null && !"".equals(adminPort.trim())) {
runnerSetting.getAdminPort().setText(adminPort);
}
String vmOptions = tomcatRunConfiguration.getVmOptions();
if (vmOptions != null && !"".equals(vmOptions.trim())) {
runnerSetting.getVmOptons().setText(vmOptions);
}
Map<String, String> envOptions = tomcatRunConfiguration.getEnvOptions();
if (envOptions != null && !envOptions.isEmpty()) {
runnerSetting.getEnvOptions().setEnvs(envOptions);
}
Boolean preplacedParentEnvs = tomcatRunConfiguration.getPreplacedParentEnvironmentVariables();
if (preplacedParentEnvs != null) {
runnerSetting.getEnvOptions().setPreplacedParentEnvs(preplacedParentEnvs);
}
}
@Override
protected void applyEditorTo(TomcatRunConfiguration tomcatRunConfiguration) throws ConfigurationException {
TomcatInfo selectedItem = (TomcatInfo) runnerSetting.getTomcatField().getComboBox().getSelectedItem();
if (selectedItem != null) {
tomcatRunConfiguration.setTomcatInfo(selectedItem);
}
tomcatRunConfiguration.setDocBase(runnerSetting.getDocBaseField().getText());
tomcatRunConfiguration.setModule(runnerSetting.getModule());
tomcatRunConfiguration.setContextPath(runnerSetting.getContextPathField().getText());
tomcatRunConfiguration.setPort(runnerSetting.getPortField().getText());
tomcatRunConfiguration.setAdminPort(runnerSetting.getAdminPort().getText());
tomcatRunConfiguration.setVmOptions(runnerSetting.getVmOptons().getText());
tomcatRunConfiguration.setEnvOptions(runnerSetting.getEnvOptions().getEnvs());
tomcatRunConfiguration.setPreplacedParentEnvironmentVariables(runnerSetting.getEnvOptions().isPreplacedParentEnvs());
}
@NotNull
@Override
protected JComponent createEditor() {
ComboboxWithBrowseButton tomcatField = runnerSetting.getTomcatField();
TextFieldWithBrowseButton docBaseField = runnerSetting.getDocBaseField();
JTextField contextPathField = runnerSetting.getContextPathField();
JFormattedTextField portField = runnerSetting.getPortField();
JFormattedTextField adminPort = runnerSetting.getAdminPort();
JXButton configrationButton = runnerSetting.getConfigrationButton();
configrationButton.addActionListener(e -> ShowSettingsUtil.getInstance().showSettingsDialog(project, TomcatSettingConfigurable.clreplaced));
VirtualFile baseDir = VirtualFileManager.getInstance().getFileSystem("file").findFileByPath(project.getBasePath());
FileChooserDescriptor chooserDescriptor = new IgnoreOutputFileChooserDescriptor(project).withRoots(baseDir);
docBaseField.addBrowseFolderListener("webapp", "Choose Web Folder", project, chooserDescriptor);
docBaseField.getTextField().getDoreplacedent().addDoreplacedentListener(new DoreplacedentAdapter() {
@Override
protected void textChanged(DoreplacedentEvent doreplacedentEvent) {
if (!doreplacedentEvent.getType().equals(DoreplacedentEvent.EventType.REMOVE)) {
String text = docBaseField.getText();
if (text != null && !text.trim().equals("")) {
VirtualFile fileByIoFile = LocalFileSystem.getInstance().findFileByIoFile(new File(text));
Module module = ModuleUtilCore.findModuleForFile(fileByIoFile, project);
String contextPath = module == null ? "/" : "/" + module.getName();
contextPathField.setText(contextPath);
runnerSetting.setModule(module);
}
}
}
});
portField.setValue(8080);
adminPort.setValue(8005);
DefaultFormatterFactory tf = new DefaultFormatterFactory();
NumberFormat format = NumberFormat.getInstance();
format.setGroupingUsed(false);
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClreplaced(Integer.clreplaced);
formatter.setMinimum(0);
formatter.setMaximum(65535);
tf.setDefaultFormatter(formatter);
portField.setFormatterFactory(tf);
adminPort.setFormatterFactory(tf);
return runnerSetting.getMainPanel();
}
clreplaced IgnoreOutputFileChooserDescriptor extends FileChooserDescriptor {
private Project project;
public IgnoreOutputFileChooserDescriptor(Project project) {
super(false, true, false, false, false, false);
this.project = project;
}
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
ModuleManager moduleManager = ModuleManager.getInstance(project);
Module[] modules = moduleManager.getModules();
for (Module module : modules) {
VirtualFile[] excludeRoots = ModuleRootManager.getInstance(module).getExcludeRoots();
for (VirtualFile excludeFile : excludeRoots) {
if (excludeFile.getCanonicalPath().equals(file.getCanonicalPath())) {
return false;
}
}
}
return super.isFileVisible(file, showHiddenFiles);
}
}
}
19
Source : CptUpdateUtils.java
with Apache License 2.0
from xylo
with Apache License 2.0
from xylo
public static void checkForWebTemplateUpdates(Project project) {
checkForWebTemplateUpdates(project, false, null);
}
19
Source : AddTemplateFileDialog.java
with Apache License 2.0
from xylo
with Apache License 2.0
from xylo
public clreplaced AddTemplateFileDialog extends DialogWrapper {
private final Project project;
private final CptLang lang;
private final CptVirtualFile cptVirtualFile;
private final Set<String> otherFileNames;
private JPanel contentPane;
private JComboBox<CptFileType> typeField;
private JTextField urlField;
private JButton fileChooserButton;
private JTextField nameField;
private JLabel urlLabel;
public AddTemplateFileDialog(Project project, @NotNull CptLang lang, @Nullable CptVirtualFile cptVirtualFile, @NotNull Set<String> otherFileNames) {
super(project);
this.project = project;
this.lang = lang;
this.cptVirtualFile = cptVirtualFile;
this.otherFileNames = otherFileNames;
val url = cptVirtualFile != null ? cptVirtualFile.getUrl() : null;
setreplacedle(url == null ? "Add Template File" : "Edit Template File");
// setContentPane(contentPane);
// setModal(true);
typeField.setModel(new DefaultComboBoxModel<>(CptFileType.values()));
typeField.addActionListener(e -> {
val selectedItem = (CptFileType) typeField.getSelectedItem();
fileChooserButton.setVisible(selectedItem != CptFileType.Web);
urlLabel.setEnabled(selectedItem != CptFileType.LocalInPluginDir);
urlField.setEnabled(selectedItem != CptFileType.LocalInPluginDir);
fileChooserButton.setEnabled(selectedItem != CptFileType.LocalInPluginDir);
if (selectedItem == CptFileType.LocalInPluginDir) {
urlField.setText("");
}
});
fileChooserButton.setVisible(false);
fileChooserButton.addActionListener(e -> onChooseFile());
if (url == null) {
typeField.setSelectedItem(CptFileType.LocalInPluginDir);
} else if (url.getProtocol().equals("file")) {
typeField.setSelectedItem(CptFileType.LocalInFs);
} else {
typeField.setSelectedItem(CptFileType.Web);
}
if (url != null) {
urlField.setText(url.toString());
}
if (cptVirtualFile != null) {
nameField.setText(cptVirtualFile.getFile().getName().replace(".postfixTemplates", ""));
}
// call onCancel() on ESCAPE
// contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
if (project != null) {
init();
}
}
private void onChooseFile() {
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {
private final List<String> extensions = _List("postfixTemplates");
@Override
public boolean isFileSelectable(VirtualFile virtualFile) {
return extensions.contains(virtualFile.getExtension());
}
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || isFileSelectable(file));
}
};
val virtualFile = FileChooser.chooseFile(descriptor, project, null);
if (virtualFile != null) {
urlField.setText(virtualFile.getUrl());
nameField.setText(virtualFile.getNameWithoutExtension());
}
}
public CptVirtualFile getCptVirtualFile() {
try {
URL oldUrl = null;
File oldFile = null;
boolean isNew = true;
if (cptVirtualFile != null) {
oldUrl = cptVirtualFile.getOldUrl();
if (oldUrl == null) {
oldUrl = cptVirtualFile.getUrl();
}
oldFile = cptVirtualFile.getOldFile();
if (oldFile == null) {
oldFile = cptVirtualFile.getFile();
}
isNew = cptVirtualFile.isNew();
}
val urlString = urlField.getText().trim().equals("") ? null : urlField.getText();
val newUrl = urlString != null ? new URL(urlString) : null;
val newFile = CptUtil.getTemplateFile(lang.getLanguage(), nameField.getText().trim());
val newCptVirtualFile = new CptVirtualFile(null, newUrl, newFile, isNew);
if (!isNew && newUrl != null && oldUrl != null && !newUrl.equals(oldUrl)) {
newCptVirtualFile.setOldUrl(oldUrl);
}
if (!isNew && oldFile != null && !FileUtil.filesEqual(newFile, oldFile)) {
newCptVirtualFile.setOldFile(oldFile);
}
return newCptVirtualFile;
} catch (MalformedURLException ignored) {
return null;
}
}
@Nullable
@Override
protected JComponent createCenterPanel() {
return contentPane;
}
public static void main(String[] args) {
val dialog = new AddTemplateFileDialog(null, SupportedLanguages.getCptLang("java"), null, _Set());
new JDialog() {
{
getRootPane().setContentPane(dialog.createCenterPanel());
setSize(500, 100);
setVisible(true);
}
};
}
@Nullable
@Override
protected ValidationInfo doValidate() {
val urlString = urlField.getText().trim();
if (typeField.getSelectedItem() == CptFileType.LocalInFs) {
try {
new URL(urlString);
} catch (MalformedURLException e) {
return new ValidationInfo("Please select an existing file.", fileChooserButton);
}
}
if (typeField.getSelectedItem() == CptFileType.Web) {
try {
new URL(urlString);
} catch (MalformedURLException e) {
return new ValidationInfo("Please enter a valid URL.", urlField);
}
}
final String name = nameField.getText().trim();
if (name.isEmpty()) {
return new ValidationInfo("Please enter a name for the local file.", nameField);
}
if (otherFileNames.contains(name)) {
return new ValidationInfo("This name is already used. Please choose another one.", nameField);
}
return null;
}
@Nullable
@Override
public JComponent getPreferredFocusedComponent() {
return nameField;
}
}
19
Source : CptElementFactory.java
with Apache License 2.0
from xylo
with Apache License 2.0
from xylo
public static CptFile createFile(Project project, String text) {
String name = "dummy.Cpt";
return (CptFile) PsiFileFactory.getInstance(project).createFileFromText(name, CptFileType.INSTANCE, text);
}
19
Source : CptElementFactory.java
with Apache License 2.0
from xylo
with Apache License 2.0
from xylo
public static CptMapping createMapping(Project project, String name, String code) {
final CptFile file = createFile(project, name + " -> " + code);
return (CptMapping) file.getFirstChild();
}
19
Source : CptElementFactory.java
with Apache License 2.0
from xylo
with Apache License 2.0
from xylo
public static PsiElement createCRLF(Project project) {
final CptFile file = createFile(project, "\n");
return file.getFirstChild();
}
19
Source : CptElementFactory.java
with Apache License 2.0
from xylo
with Apache License 2.0
from xylo
public static CptTemplate createTemplate(Project project, String name, String description) {
final CptFile file = createFile(project, "." + name + " : " + description);
return (CptTemplate) file.getFirstChild();
}
19
Source : CptParserDefinition.java
with Apache License 2.0
from xylo
with Apache License 2.0
from xylo
@NotNull
public PsiParser createParser(final Project project) {
return new CptParser();
}
19
Source : ClassHelper.java
with MIT License
from xujiaji
with MIT License
from xujiaji
/**
* search clreplaced by clreplaced name.
*
* @param name
* @param project
* @return
*/
private static PsiClreplaced searchClreplacedByName(String name, Project project) {
GlobalSearchScope searchScope = GlobalSearchScope.allScope(project);
PsiClreplaced[] psiClreplacedes = PsiShortNamesCache.getInstance(project).getClreplacedesByName(name, searchScope);
if (psiClreplacedes.length == 1) {
return psiClreplacedes[0];
}
if (psiClreplacedes.length > 1) {
for (PsiClreplaced pc : psiClreplacedes) {
PsiJavaFile psiJavaFile = (PsiJavaFile) pc.getContainingFile();
String packageName = psiJavaFile.getPackageName();
if (List.clreplaced.getPackage().getName().equals(packageName) || packageName.contains("io.xujiaji.xmvp")) {
return pc;
}
}
}
return null;
}
19
Source : ClassHelper.java
with MIT License
from xujiaji
with MIT License
from xujiaji
/**
* add method to Clreplaced
*
* @param psiClreplaced
*/
public static void addMethodToClreplaced(Project project, PsiClreplaced psiClreplaced, java.util.List<String> methods, boolean over) {
PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
for (String method : methods) {
String[] strings = method.split("##");
PsiMethod psiMethod = null;
if (over) {
psiMethod = factory.createMethodFromText("public " + strings[0] + " " + strings[1] + " {\n\n}", psiClreplaced);
psiMethod.getModifierList().addAnnotation("Override");
} else {
psiMethod = factory.createMethodFromText(strings[0] + " " + strings[1] + ";", psiClreplaced);
}
psiClreplaced.add(psiMethod);
importReturnAndPra(strings[0], psiClreplaced, project);
for (PsiParameter pp : psiMethod.getParameterList().getParameters()) {
importReturnAndPra(pp.getTypeElement().getType().getPresentableText(), psiClreplaced, project);
// System.out.println(pp.getTypeElement().getType().getPresentableText());
}
}
}
19
Source : ClassHelper.java
with MIT License
from xujiaji
with MIT License
from xujiaji
public static boolean isFileExists(AnActionEvent e, String name) {
Project project = e.getProject();
GlobalSearchScope searchScope = GlobalSearchScope.allScope(project);
PsiClreplaced[] psiClreplacedes = new PsiClreplaced[0];
try {
psiClreplacedes = PsiShortNamesCache.getInstance(project).getClreplacedesByName(name, searchScope);
} catch (Exception ignored) {
ignored.printStackTrace();
}
return psiClreplacedes.length > 0;
}
19
Source : ClassHelper.java
with MIT License
from xujiaji
with MIT License
from xujiaji
private static void importContractClreplaced(Project project, PsiClreplaced clreplacedContract, String viewParent) {
String[] strings = viewParent.split("\\.");
if (strings.length < 1) {
return;
}
searchAndImportClreplaced(strings[0], clreplacedContract, project);
}
19
Source : ClassHelper.java
with MIT License
from xujiaji
with MIT License
from xujiaji
/**
* search and import clreplaced
*
* @param name
* @param resClreplaced
* @param project
*/
private static void searchAndImportClreplaced(String name, PsiClreplaced resClreplaced, Project project) {
if ("".equals(name) || "void".equals(name))
return;
PsiClreplaced importClreplaced = searchClreplacedByName(name, project);
if (importClreplaced == null)
return;
PsiJavaFile psiJavaFile = ((PsiJavaFile) importClreplaced.getContainingFile());
String packageName = psiJavaFile.getPackageName();
if (packageName.contains("java.lang"))
return;
importClreplaced(importClreplaced, resClreplaced, project);
}
19
Source : ClassHelper.java
with MIT License
from xujiaji
with MIT License
from xujiaji
/**
* If it is xmvp, add inheritance
*
* @param factory
* @param searchScope
* @param psiClreplaced
*/
private static void addExtendToPresenter(Project project, PsiElementFactory factory, GlobalSearchScope searchScope, PsiClreplaced psiClreplaced, String contractName, String modelName) {
if (!PropertiesComponent.getInstance().getBoolean(Constant.IS_XMVP)) {
return;
}
extendsClreplaced(factory, searchScope, psiClreplaced, "XBasePresenter<" + contractName + ".View," + modelName + ">");
searchAndImportClreplaced("XBasePresenter", psiClreplaced, project);
searchAndImportClreplaced(modelName, psiClreplaced, project);
}
19
Source : ClassHelper.java
with MIT License
from xujiaji
with MIT License
from xujiaji
/**
* import clreplaced
*
* @param importClreplaced
* @param resClreplaced
* @param project
*/
private static void importClreplaced(PsiClreplaced importClreplaced, PsiClreplaced resClreplaced, Project project) {
if (importClreplaced == null || resClreplaced == null)
return;
PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
PsiImportStatement importStatement = factory.createImportStatement(importClreplaced);
PsiJavaFile psiJavaFile = ((PsiJavaFile) resClreplaced.getContainingFile());
PsiImportList psiImportList = psiJavaFile.getImportList();
if (psiImportList == null)
return;
for (PsiImportStatement pis : psiImportList.getImportStatements()) {
if (pis.getText().equals(importStatement.getText())) {
return;
}
}
psiImportList.add(importStatement);
}
19
Source : ClassHelper.java
with MIT License
from xujiaji
with MIT License
from xujiaji
private static void addExtendToView(Project project, PsiElementFactory factory, GlobalSearchScope searchScope, PsiClreplaced psiClreplaced, String baseViewParent, String presenterName) {
if (baseViewParent == null || "".equals(baseViewParent))
return;
extendsClreplaced(factory, searchScope, psiClreplaced, baseViewParent + "<" + presenterName + ">");
searchAndImportClreplaced(baseViewParent, psiClreplaced, project);
searchAndImportClreplaced(presenterName, psiClreplaced, project);
PsiClreplaced baseViewParentClreplaced = searchClreplacedByName(baseViewParent, project);
if (baseViewParentClreplaced == null)
return;
PsiMethod[] psiMethods = baseViewParentClreplaced.getMethods();
for (PsiMethod p : psiMethods) {
PsiModifierList psiModifierList = p.getModifierList();
if (psiModifierList.hasModifierProperty("abstract")) {
String text = p.getText();
text = text.replaceAll("/\\*\\*[\\s\\S]+\\*/", "");
text = text.replaceAll("abstract ", "");
PsiMethod psiMethod = factory.createMethodFromText("@Override " + text.substring(0, text.lastIndexOf(";")) + " {\n\n}", psiClreplaced);
psiClreplaced.add(psiMethod);
// factory.createMethod();
// psiMethod.getModifierList().addAnnotation("Override");
// psiClreplaced.add(psiMethod);
}
}
}
19
Source : CapnpParserDefinition.java
with BSD 3-Clause "New" or "Revised" License
from xmonader
with BSD 3-Clause "New" or "Revised" License
from xmonader
// @NotNull
public PsiParser createParser(final Project project) {
return null;
// return new SimpleParser();
}
19
Source : Notify.java
with Apache License 2.0
from XiaoMi
with Apache License 2.0
from XiaoMi
/**
* Shows {@link Notification}.
*
* @param project current project
* @param replacedle notification replacedle
* @param group notification group
* @param content notification text
* @param type notification type
* @param listener optional listener
*/
public static void show(@NotNull Project project, @NotNull String replacedle, @NotNull String content, @NotNull NotificationGroup group, @NotNull NotificationType type, @Nullable NotificationListener listener) {
Notification notification = group.createNotification(replacedle, content, type, listener);
Notifications.Bus.notify(notification, project);
}
19
Source : SpringBootProGenerator.java
with Apache License 2.0
from XiaoMi
with Apache License 2.0
from XiaoMi
public clreplaced SpringBootProGenerator extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField projectPathField;
private JTextField projectNameField;
private JTextField groupIdField;
private JTextField packageField;
private JTextField versionField;
private JTextField authorField;
private Project project;
public SpringBootProGenerator(Project project) {
this.project = project;
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
buttonOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onOK();
}
});
buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
this.setSize(this.getWidth() + 1, this.getHeight() + 1);
}
private void onOK() {
String projectPath = projectPathField.getText().trim();
String projectName = projectNameField.getText().trim();
String srcPath = "/src/main/java/";
String testPath = "/src/test/java/";
String deployPath = "/deploy/manifests";
String groupId = groupIdField.getText().trim();
String packageName = packageField.getText().trim();
String author = authorField.getText().trim();
String versionId = versionField.getText().trim();
String catAppdatas = "/data/appdatas/cat";
String catApplogs = "/data/applogs/cat";
String packagePath = packageName.replaceAll("\\.", "/");
// 创建项目
DirectoryGenerator directoryGenerator = new DirectoryGenerator(projectPath, projectName, "");
directoryGenerator.generator();
generageParentPom(projectPath, projectName, groupId, versionId);
generageReadMe(projectPath, projectName);
generageGitignore(projectPath, projectName);
// 创建module: api
DirectoryGenerator apiModule = new DirectoryGenerator(projectPath, projectName, projectName + "-api" + File.separator + srcPath + File.separator + packagePath + File.separator + "api" + File.separator + "service");
apiModule.generator();
generateApiPom(projectPath, projectName, groupId, versionId);
generateDubboApi(projectPath, projectName, packageName, packagePath + File.separator + "api" + File.separator + "service", projectName + "-api" + File.separator + srcPath);
DirectoryGenerator apiTest = new DirectoryGenerator(projectPath, projectName, projectName + "-api" + File.separator + testPath + File.separator + packagePath + File.separator + "test");
apiTest.generator();
// 创建module: common
DirectoryGenerator commonModule = new DirectoryGenerator(projectPath, projectName, projectName + "-common" + File.separator + srcPath);
commonModule.generator();
generateCommonPom(projectPath, projectName, groupId, versionId);
DirectoryGenerator commonTest = new DirectoryGenerator(projectPath, projectName, projectName + "-common" + File.separator + testPath);
commonTest.generator();
// 创建module: service
DirectoryGenerator serviceModule = new DirectoryGenerator(projectPath, projectName, projectName + "-service" + File.separator + srcPath + File.separator + packagePath);
serviceModule.generator();
generateServicePom(projectPath, projectName, groupId, author, versionId);
DirectoryGenerator serviceTest = new DirectoryGenerator(projectPath, projectName, projectName + "-service" + File.separator + testPath + File.separator + packagePath);
serviceTest.generator();
// 创建module: server
DirectoryGenerator serverModule = new DirectoryGenerator(projectPath, projectName, projectName + "-server" + File.separator + srcPath + File.separator + packagePath + File.separator + "bootstrap");
serverModule.generator();
DirectoryGenerator serverModule1 = new DirectoryGenerator(projectPath, projectName, projectName + "-server" + File.separator + srcPath + File.separator + packagePath + File.separator + "service");
serverModule1.generator();
DirectoryGenerator serverModule2 = new DirectoryGenerator(projectPath, projectName, projectName + "-server" + File.separator + srcPath + File.separator + packagePath + File.separator + "config");
serverModule2.generator();
generateServerPom(projectPath, projectName, groupId, author, versionId);
DirectoryGenerator serverTest = new DirectoryGenerator(projectPath, projectName, projectName + "-server" + File.separator + testPath + File.separator + packagePath);
serverTest.generator();
// 生成入口类
generateBootstrap(projectPath, projectName, packageName, author, packagePath + File.separator + "bootstrap", projectName + "-server" + File.separator + srcPath);
// 生成配置文件
generateResources(projectPath, projectName);
generateLogback(projectPath, projectName);
// 生成dubbo相关
generateDubboProperties(projectPath, projectName);
generateDubboConfig(projectPath, projectName, packageName, packagePath + File.separator + "config", projectName + "-server" + File.separator + srcPath);
generateDubboApiImp(projectPath, projectName, packageName, packagePath + File.separator + "service", projectName + "-server" + File.separator + srcPath);
// 生成nacos相关
generateNacosConfig(projectPath, projectName, packageName, packagePath + File.separator + "config", projectName + "-server" + File.separator + srcPath);
// 生成编译部署相关
generateBuild(projectPath, projectName, versionId);
DirectoryGenerator deploy = new DirectoryGenerator(projectPath, projectName, projectName + "-server" + File.separator + deployPath);
deploy.generator();
generateDeploy(projectPath, projectName, versionId, deployPath);
// 生成cat监控相关
generateCatProperties(projectPath, projectName);
FileUtils.createDirectories(catAppdatas);
FileUtils.createDirectories(catApplogs);
String template = FileUtils.getTemplate("springboot_cat_client.tml");
String str = FileUtils.renderTemplate(template, new HashMap<>());
FileUtils.writeFile(catAppdatas + File.separator + "client.xml", str);
colorEgg(projectPath, projectName, testPath, packagePath);
if (null != project) {
Messages.showMessageDialog(project, "Success", "Generate Success", null);
}
}
private void generateResources(String projectPath, String projectName) {
// 生成文件夹
DirectoryGenerator directoryGenerator = new DirectoryGenerator(projectPath, projectName, projectName + "-server/src/main/resources/config");
directoryGenerator.generator();
// 生成文件
FileGenerator fileGenerator = new FileGenerator(projectPath, projectName, projectName + "-server/src/main/resources/application.properties", "springboot_application_properties.tml");
FileGenerator devGenerator = new FileGenerator(projectPath, projectName, projectName + "-server/src/main/resources/config/dev.properties", "springboot_application_properties_dev.tml");
FileGenerator stagingGenerator = new FileGenerator(projectPath, projectName, projectName + "-server/src/main/resources/config/staging.properties", "springboot_application_properties_st.tml");
FileGenerator c3Generator = new FileGenerator(projectPath, projectName, projectName + "-server/src/main/resources/config/c3.properties", "springboot_application_properties_c3.tml");
FileGenerator c4Generator = new FileGenerator(projectPath, projectName, projectName + "-server/src/main/resources/config/c4.properties", "springboot_application_properties_c4.tml");
FileGenerator previewGenerator = new FileGenerator(projectPath, projectName, projectName + "-server/src/main/resources/config/preview.properties", "springboot_application_properties_preview.tml");
Map<String, Object> m = new HashMap<>(1);
m.put("appName", projectName);
fileGenerator.generator(m);
devGenerator.generator(m);
stagingGenerator.generator(m);
c3Generator.generator(m);
c4Generator.generator(m);
previewGenerator.generator(m);
}
private void generateLogback(String projectPath, String projectName) {
// 生成文件夹
DirectoryGenerator directoryGenerator = new DirectoryGenerator(projectPath, projectName, projectName + "-server/src/main/resources");
directoryGenerator.generator();
// 生成文件
FileGenerator fileGenerator = new FileGenerator(projectPath, projectName, projectName + "-server/src/main/resources/logback.xml", "springboot_logback.tml");
Map<String, Object> m = new HashMap<>(1);
m.put("project", projectName);
fileGenerator.generator(m);
}
private void generateCatProperties(String projectPath, String projectName) {
// 生成文件夹
DirectoryGenerator directoryGenerator = new DirectoryGenerator(projectPath, projectName, projectName + "-server/src/main/resources/META-INF");
directoryGenerator.generator();
// 生成文件
FileGenerator fileGenerator = new FileGenerator(projectPath, projectName, projectName + "-server/src/main/resources/META-INF/app.properties", "springboot_cat_properties.tml");
Map<String, Object> m = new HashMap<>(1);
m.put("appName", projectName);
fileGenerator.generator(m);
}
private void generateDubboProperties(String projectPath, String projectName) {
// 生成文件夹
DirectoryGenerator directoryGenerator = new DirectoryGenerator(projectPath, projectName, projectName + "-server/src/main/resources");
directoryGenerator.generator();
// 生成文件
FileGenerator fileGenerator = new FileGenerator(projectPath, projectName, projectName + "-server/src/main/resources/dubbo.properties", "springboot_dubbo_properties.tml");
Map<String, Object> m = new HashMap<>(1);
m.put("project", projectName);
fileGenerator.generator(m);
}
private void generateBootstrap(String projectPath, String projectName, String packageName, String author, String packagePath, String serviceSrcPath) {
ClreplacedGenerator clreplacedGenerator = new ClreplacedGenerator(projectPath, projectName, serviceSrcPath, packagePath, StringUtils.capitalize(projectName) + "Bootstrap", "springboot_bootstrap_clreplaced.tml");
Map<String, Object> m = new HashMap<>(3);
m.put("package", packageName);
m.put("author", author);
m.put("project", StringUtils.capitalize(projectName));
clreplacedGenerator.generator(m);
}
private void generateDubboApiImp(String projectPath, String projectName, String packageName, String packagePath, String serviceSrcPath) {
ClreplacedGenerator clreplacedGenerator = new ClreplacedGenerator(projectPath, projectName, serviceSrcPath, packagePath, "DubboTestServiceImpl", "springboot_dubbo_api_imp_clreplaced.tml");
Map<String, Object> m = new HashMap<>(1);
m.put("package", packageName);
clreplacedGenerator.generator(m);
}
private void generateDubboApi(String projectPath, String projectName, String packageName, String packagePath, String serviceSrcPath) {
ClreplacedGenerator clreplacedGenerator = new ClreplacedGenerator(projectPath, projectName, serviceSrcPath, packagePath, "DubboTestService", "springboot_dubbo_api_clreplaced.tml");
Map<String, Object> m = new HashMap<>(2);
m.put("package", packageName);
m.put("project", projectName);
clreplacedGenerator.generator(m);
}
private void generateDubboConfig(String projectPath, String projectName, String packageName, String packagePath, String serviceSrcPath) {
ClreplacedGenerator clreplacedGenerator = new ClreplacedGenerator(projectPath, projectName, serviceSrcPath, packagePath, "DubboConfiguration", "springboot_dubbo_config.tml");
Map<String, Object> m = new HashMap<>(2);
m.put("package", packageName);
m.put("project", StringUtils.capitalize(projectName));
clreplacedGenerator.generator(m);
}
private void generateNacosConfig(String projectPath, String projectName, String packageName, String packagePath, String serviceSrcPath) {
ClreplacedGenerator clreplacedGenerator = new ClreplacedGenerator(projectPath, projectName, serviceSrcPath, packagePath, "NacosConfiguration", "springboot_nacos_config.tml");
Map<String, Object> m = new HashMap<>(1);
m.put("package", packageName);
clreplacedGenerator.generator(m);
}
private void generateApiPom(String projectPath, String projectName, String groupId, String versionId) {
// 生成api module 下的pom文件
PomGenerator apiPomGenerator = new PomGenerator(projectPath, projectName + File.separator + projectName + "-api", "springboot_pom_api.tml");
Map<String, Object> ampom = new HashMap<>();
ampom.put("groupId", groupId);
ampom.put("parent_artifactId", projectName);
ampom.put("artifactId", projectName + "-api");
ampom.put("version", versionId + "-SNAPSHOT");
ampom.put("version_id", versionId);
apiPomGenerator.generator(ampom);
}
private void generateCommonPom(String projectPath, String projectName, String groupId, String versionId) {
// 生成api module 下的pom文件
PomGenerator commonPomGenerator = new PomGenerator(projectPath, projectName + File.separator + projectName + "-common", "springboot_pom_common.tml");
Map<String, Object> cmpom = new HashMap<>();
cmpom.put("groupId", groupId);
cmpom.put("parent_artifactId", projectName);
cmpom.put("artifactId", projectName + "-common");
cmpom.put("version", versionId + "-SNAPSHOT");
commonPomGenerator.generator(cmpom);
}
private void generageParentPom(String projectPath, String projectName, String groupId, String versionId) {
// 生成主项目的pom文件
PomGenerator pomGenerator = new PomGenerator(projectPath, projectName, "springboot_pom.tml");
Map<String, Object> mpom = new HashMap<>();
mpom.put("groupId", groupId);
mpom.put("artifactId", projectName);
mpom.put("version", versionId + "-SNAPSHOT");
mpom.put("api_module", projectName + "-api");
mpom.put("common_module", projectName + "-common");
mpom.put("service_module", projectName + "-service");
mpom.put("server_module", projectName + "-server");
pomGenerator.generator(mpom);
}
private void generageReadMe(String projectPath, String projectName) {
FileGenerator mdGenerator = new FileGenerator(projectPath, projectName, "README.md", "springboot_readme.tml");
mdGenerator.generator(new HashMap<>());
}
private void generageGitignore(String projectPath, String projectName) {
FileGenerator mdGenerator = new FileGenerator(projectPath, projectName, ".gitignore", "springboot_gitignore.tml");
mdGenerator.generator(new HashMap<>());
}
private void generateServicePom(String projectPath, String projectName, String groupId, String author, String versionId) {
// 生成service module 下的pom文件
PomGenerator servicePomGenerator = new PomGenerator(projectPath, projectName + File.separator + projectName + "-service", "springboot_pom_service.tml");
Map<String, Object> smpom = new HashMap<>();
smpom.put("groupId", groupId);
smpom.put("parent_artifactId", projectName);
smpom.put("artifactId", projectName + "-service");
smpom.put("version", versionId + "-SNAPSHOT");
smpom.put("version_id", versionId);
smpom.put("author", author);
smpom.put("api_artifactId", projectName + "-api");
smpom.put("common_artifactId", projectName + "-common");
servicePomGenerator.generator(smpom);
}
private void generateServerPom(String projectPath, String projectName, String groupId, String author, String versionId) {
// 生成service module 下的pom文件
PomGenerator servicePomGenerator = new PomGenerator(projectPath, projectName + File.separator + projectName + "-server", "springboot_pom_server.tml");
Map<String, Object> smpom = new HashMap<>();
smpom.put("groupId", groupId);
smpom.put("parent_artifactId", projectName);
smpom.put("artifactId", projectName + "-server");
smpom.put("version", versionId + "-SNAPSHOT");
smpom.put("bootstrap", StringUtils.capitalize(projectName) + "Bootstrap");
smpom.put("service_artifactId", projectName + "-service");
servicePomGenerator.generator(smpom);
}
private void generateBuild(String projectPath, String projectName, String versionId) {
FileGenerator buildGenerator = new FileGenerator(projectPath, projectName + File.separator + projectName + "-server", "build.sh", "springboot_build.tml");
Map<String, Object> smpom = new HashMap<>();
smpom.put("project", projectName);
smpom.put("version", versionId + "-SNAPSHOT");
buildGenerator.generator(smpom);
}
private void generateDeploy(String projectPath, String projectName, String versionId, String deployPath) {
FileGenerator deployGenerator = new FileGenerator(projectPath, projectName + File.separator + projectName + "-server" + File.separator + deployPath, "config.pp.template", "springboot_deploy.tml");
Map<String, Object> smpom = new HashMap<>();
smpom.put("project", projectName);
smpom.put("version", versionId + "-SNAPSHOT");
deployGenerator.generator(smpom);
}
private void colorEgg(String projectPath, String projectName, String testPath, String packagePath) {
String data = "硬广时间:http://gxxxx/#/index";
try {
Request req = Request.create("http://xxxx/mtop/arch/im", Request.METHOD.POST);
Map<String, String> mh = new HashMap<>();
mh.put("Content-Type", "application/json");
Header header = Header.create(mh);
req.setHeader(header);
Map<String, String> md = new HashMap<>();
md.put("type", "generator");
md.put("cmd", "changelog");
req.setData(new Gson().toJson(md));
PostSender ps = new PostSender(req);
Response res = ps.setTimeout(3000).send();
data = res.getContent();
} catch (Exception e) {
// ignore
}
String str = ColorEggUtils.parseByte2HexStr(ColorEggUtils.encrypt(data, "xiaomiYP"));
FileGenerator mdGenerator = new FileGenerator(projectPath, projectName, projectName + "-api" + File.separator + testPath + File.separator + packagePath + File.separator + "test" + File.separator + ".des", "springboot_color_egg.tml");
Map<String, Object> smpom = new HashMap<>();
smpom.put("data", str);
mdGenerator.generator(smpom);
}
private void onCancel() {
dispose();
}
public static void main(String[] args) {
SpringBootProGenerator dialog = new SpringBootProGenerator(null);
dialog.pack();
// 设置对话框大小是否可改变
dialog.setResizable(true);
dialog.setSize(500, 400);
dialog.setVisible(true);
System.exit(0);
}
}
19
Source : FilterUi.java
with Apache License 2.0
from XiaoMi
with Apache License 2.0
from XiaoMi
public clreplaced FilterUi extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField projectPathField;
private JTextField projectNameField;
private JTextField groupIdField;
private JTextField packageField;
private JTextField filterOrderField;
private JTextField authorField;
private JTextField versionField;
private JTextField descField;
private JTextField gitAddressField;
private JTextField paramsField;
private JTextField cnameField;
private JTextField isSystemField;
private Project project;
public FilterUi(Project project) {
this.project = project;
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
buttonOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onOK();
}
});
buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
this.setSize(this.getWidth() + 1, this.getHeight() + 1);
}
private void onOK() {
String projectPath = projectPathField.getText().trim();
String projectName = projectNameField.getText().trim();
String srcPath = "/src/main/java/";
String groupId = groupIdField.getText().trim();
String packageName = packageField.getText().trim();
String author = authorField.getText().trim();
if (!author.endsWith("@xxxx.com")) {
author = author + "@xxxxx.com";
}
String versionId = versionField.getText().trim();
String filterOrder = filterOrderField.getText().trim();
String desc = descField.getText().trim();
String gitAddress = gitAddressField.getText().trim();
String params = paramsField.getText().trim();
String cname = cnameField.getText().trim();
String isSystem = isSystemField.getText().trim();
String packagePath = packageName.replaceAll("\\.", "/");
// 创建项目
DirectoryGenerator directoryGenerator = new DirectoryGenerator(projectPath, projectName, "src/main/java/" + packagePath + "/filter");
directoryGenerator.generator();
generageParentPom(projectPath, projectName, groupId, versionId);
generageGitignore(projectPath, projectName);
// 生成入口类
generateFilter(projectPath, projectName, packageName, author, packagePath + "/filter", "src/main/java", filterOrder);
// 生成配置文件
generateExtensions(projectPath, projectName, versionId, desc, author, packageName, gitAddress, params, cname, isSystem);
if (null != project) {
Messages.showMessageDialog(project, "Success", "Generate Success", null);
}
}
private void generateExtensions(String projectPath, String projectName, String version, String desc, String author, String packageName, String gitAddress, String params, String cname, String system) {
if (!system.equals("0") && !system.equals("1")) {
system = "0";
}
// 生成文件夹
DirectoryGenerator directoryGenerator = new DirectoryGenerator(projectPath, projectName, "src/main/resources");
directoryGenerator.generator();
// 生成文件
FileGenerator fileGenerator = new FileGenerator(projectPath, projectName, "src/main/resources/FilterDef", "filter_def.tml");
Map<String, Object> m = new HashMap<>(9);
m.put("name", projectName);
m.put("filter", packageName + ".filter." + StringUtils.capitalize(projectName));
m.put("date", new SimpleDateFormat("YYYY-MM-dd").format(new Date()));
m.put("version", version);
m.put("desc", desc);
m.put("author", author);
m.put("gitAddress", gitAddress);
m.put("params", params);
m.put("cname", cname);
m.put("system", system);
fileGenerator.generator(m);
}
private void generateFilter(String projectPath, String projectName, String packageName, String author, String packagePath, String serviceSrcPath, String filterOrder) {
ClreplacedGenerator clreplacedGenerator = new ClreplacedGenerator(projectPath, projectName, serviceSrcPath, packagePath, StringUtils.capitalize(projectName), "filter_clreplaced.tml");
Map<String, Object> m = new HashMap<>(4);
m.put("package", packageName + ".filter");
m.put("author", author);
m.put("filterOrder", filterOrder);
m.put("project", StringUtils.capitalize(projectName));
clreplacedGenerator.generator(m);
}
private void generageParentPom(String projectPath, String projectName, String groupId, String versionId) {
// 生成主项目的pom文件
PomGenerator pomGenerator = new PomGenerator(projectPath, projectName, "filter_pom.tml");
Map<String, Object> mpom = new HashMap<>();
mpom.put("groupId", groupId);
mpom.put("artifactId", projectName);
mpom.put("version", versionId + "-SNAPSHOT");
pomGenerator.generator(mpom);
}
private void generageGitignore(String projectPath, String projectName) {
FileGenerator mdGenerator = new FileGenerator(projectPath, projectName, ".gitignore", "springboot_gitignore.tml");
mdGenerator.generator(new HashMap<>());
}
private void onCancel() {
dispose();
}
public static void main(String[] args) {
FilterUi dialog = new FilterUi(null);
dialog.pack();
// 设置对话框大小是否可改变
dialog.setResizable(true);
dialog.setSize(800, 800);
dialog.setVisible(true);
System.exit(0);
}
}
19
Source : CodeGeneratorUi.java
with Apache License 2.0
from XiaoMi
with Apache License 2.0
from XiaoMi
public clreplaced CodeGeneratorUi extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField projectPathField;
private JTextField urlField;
private JTextField projectNameField;
private JTextField groupIdField;
private JTextField packageField;
private JTextField versionField;
private JTextField authorField;
private JLabel projectField;
private Project project;
public CodeGeneratorUi(Project project) {
this.project = project;
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
buttonOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onOK();
}
});
buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
this.setSize(this.getWidth() + 1, this.getHeight() + 1);
}
private void onOK() {
String projectPath = projectPathField.getText().trim();
String projectName = projectNameField.getText().trim();
String srcPath = "/src/main/java/";
String groupId = groupIdField.getText().trim();
String packageName = packageField.getText().trim();
String author = authorField.getText().trim();
String versionId = versionField.getText().trim();
String url = urlField.getText().trim();
String packagePath = packageName.replaceAll("\\.", "/");
// 创建项目
DirectoryGenerator directoryGenerator = new DirectoryGenerator(projectPath, projectName, "");
directoryGenerator.generator();
// 创建module
DirectoryGenerator apiModule = new DirectoryGenerator(projectPath, projectName, projectName + "-api" + File.separator + srcPath);
apiModule.generator();
generateApiPom(projectPath, projectName, groupId, versionId);
DirectoryGenerator commonModule = new DirectoryGenerator(projectPath, projectName, projectName + "-common" + File.separator + srcPath);
commonModule.generator();
generateCommonPom(projectPath, projectName, groupId, versionId);
String serviceSrcPath = projectName + "-service" + File.separator + srcPath;
String serviceFullSrcPath = serviceSrcPath + File.separator + packagePath;
// generateDubboService(author, projectPath, projectName, packageName);
DirectoryGenerator serviceModule = new DirectoryGenerator(projectPath, projectName, serviceFullSrcPath);
serviceModule.generator();
generateServicePom(projectPath, projectName, groupId, author, versionId, url);
generageParentPom(projectPath, projectName, groupId, versionId);
generageGitignore(projectPath, projectName);
// 生成入口类
generateHandler(projectPath, projectName, packageName, author, url, packagePath, serviceSrcPath);
// 生成plugin handler 配置文件
generateExtensions(projectPath, projectName, packageName);
if (null != project) {
Messages.showMessageDialog(project, "Success", "Generate Success", null);
}
}
private void generageGitignore(String projectPath, String projectName) {
FileGenerator mdGenerator = new FileGenerator(projectPath, projectName, ".gitignore", "springboot_gitignore.tml");
mdGenerator.generator(new HashMap<>());
}
private void generateExtensions(String projectPath, String projectName, String handlerPkg) {
// 生成文件夹
DirectoryGenerator directoryGenerator = new DirectoryGenerator(projectPath, projectName, projectName + "-service/src/main/resources/META-INF");
directoryGenerator.generator();
// 生成文件
FileGenerator fileGenerator = new FileGenerator(projectPath, projectName, projectName + "-service/src/main/resources/META-INF/extensions.idx", "extensions.tml");
Map<String, Object> m = new HashMap<>(2);
m.put("package", handlerPkg);
m.put("project", StringUtils.capitalize(projectName));
fileGenerator.generator(m);
}
private void generateHandler(String projectPath, String projectName, String packageName, String author, String url, String packagePath, String serviceSrcPath) {
ClreplacedGenerator clreplacedGenerator = new ClreplacedGenerator(projectPath, projectName, serviceSrcPath, packagePath, StringUtils.capitalize(projectName) + "Handler", "handler_clreplaced.tml");
Map<String, Object> m = new HashMap<>(4);
m.put("package", packageName);
m.put("author", author);
m.put("url", url);
m.put("project", StringUtils.capitalize(projectName));
clreplacedGenerator.generator(m);
}
private void generateDubboService(String author, String projectPath, String projectName, String packageName, String packagePath, String serviceSrcPath) {
ClreplacedGenerator clreplacedGenerator = new ClreplacedGenerator(projectPath, projectName, serviceSrcPath, packagePath, StringUtils.capitalize(projectName) + "Service", "dubbo_service_clreplaced.tml");
Map<String, Object> m = new HashMap<>(3);
m.put("package", packageName);
m.put("project", StringUtils.capitalize(projectName));
m.put("author", author);
clreplacedGenerator.generator(m);
}
private void generateApiPom(String projectPath, String projectName, String groupId, String versionId) {
// 生成api module 下的pom文件
PomGenerator apiPomGenerator = new PomGenerator(projectPath, projectName + File.separator + projectName + "-api", "pom_api.tml");
Map<String, Object> ampom = new HashMap<>();
ampom.put("groupId", groupId);
ampom.put("parent_artifactId", projectName);
ampom.put("artifactId", projectName + "-api");
ampom.put("version", versionId + "-SNAPSHOT");
ampom.put("plugin_id", projectName);
ampom.put("version_id", versionId);
apiPomGenerator.generator(ampom);
}
private void generateCommonPom(String projectPath, String projectName, String groupId, String versionId) {
// 生成api module 下的pom文件
PomGenerator commonPomGenerator = new PomGenerator(projectPath, projectName + File.separator + projectName + "-common", "pom_common.tml");
Map<String, Object> cmpom = new HashMap<>();
cmpom.put("groupId", groupId);
cmpom.put("parent_artifactId", projectName);
cmpom.put("artifactId", projectName + "-common");
cmpom.put("version", versionId + "-SNAPSHOT");
commonPomGenerator.generator(cmpom);
}
private void generageParentPom(String projectPath, String projectName, String groupId, String versionId) {
// 生成主项目的pom文件
PomGenerator pomGenerator = new PomGenerator(projectPath, projectName, "pom.tml");
Map<String, Object> mpom = new HashMap<>();
mpom.put("groupId", groupId);
mpom.put("artifactId", projectName);
mpom.put("version", versionId + "-SNAPSHOT");
mpom.put("api_module", projectName + "-api");
mpom.put("common_module", projectName + "-common");
mpom.put("service_module", projectName + "-service");
pomGenerator.generator(mpom);
}
private void generateServicePom(String projectPath, String projectName, String groupId, String author, String versionId, String url) {
// 生成service module 下的pom文件
PomGenerator servicePomGenerator = new PomGenerator(projectPath, projectName + File.separator + projectName + "-service", "pom_service.tml");
Map<String, Object> smpom = new HashMap<>();
smpom.put("groupId", groupId);
smpom.put("parent_artifactId", projectName);
smpom.put("artifactId", projectName + "-service");
smpom.put("version", versionId + "-SNAPSHOT");
smpom.put("plugin_id", projectName);
smpom.put("version_id", versionId);
smpom.put("author", author);
smpom.put("plugin", projectName);
smpom.put("plugin_url", url);
smpom.put("plugin_clreplaced", "com.xiaomi.youpin.tesla.plug.TeslaPlugin");
servicePomGenerator.generator(smpom);
}
private void onCancel() {
dispose();
}
public static void main(String[] args) {
CodeGeneratorUi dialog = new CodeGeneratorUi(null);
dialog.pack();
// 设置对话框大小是否可改变
dialog.setResizable(true);
dialog.setSize(500, 400);
dialog.setVisible(true);
System.exit(0);
}
}
19
Source : SpringStaticContextUtils.java
with Apache License 2.0
from WangJi92
with Apache License 2.0
from WangJi92
/**
* 获取静态Spring context的前缀 #springContext=@applicationContextProvider@context
*
* @return
*/
public static String getStaticSpringContextPrefix(Project project) {
String springStaticContextConfig = getSpringStaticContextConfig(project);
// #springContext=填充
return "" + ArthasCommandConstants.SPRING_CONTEXT_PARAM + "=" + springStaticContextConfig;
}
19
Source : SpringStaticContextUtils.java
with Apache License 2.0
from WangJi92
with Apache License 2.0
from WangJi92
/**
* 获取静态Spring context的前缀
* //这个是配置的 @com.wj.study.demo.generator.ApplicationContextProvider@context 这个是配置的
* //例子 #springContext=@com.wj.study.demo.generator.ApplicationContextProvider@context,#springContext.getBean("userService")
* <p> 构造一个如下的例子
* // #springContext=填充,#springContext.getBean("%s")
*
* @return
*/
public static String getStaticSpringContextGetBeanPrefix(Project project, String beanName) {
String springStaticContextConfig = getStaticSpringContextPrefix(project);
return String.format(SPRING_CONTEXT_GET_BEAN, springStaticContextConfig, beanName);
}
19
Source : SpringStaticContextUtils.java
with Apache License 2.0
from WangJi92
with Apache License 2.0
from WangJi92
/**
* #springContext=填充,#targetBean=#springContext.getBean("%s")
*
* @param beanName
* @return
*/
public static String getStaticSpringContextGetBeanVariable(Project project, String beanName) {
String springStaticContextConfig = getStaticSpringContextPrefix(project);
return String.format(SPRING_CONTEXT_TARGET_BEAN, springStaticContextConfig, beanName);
}
19
Source : NotifyUtils.java
with Apache License 2.0
from WangJi92
with Apache License 2.0
from WangJi92
/**
* 推送消息哦
*
* @param project
* @param message
* @param type
*/
public static void notifyMessage(Project project, String message, @NotNull NotificationType type) {
try {
Notification currentNotify = NOTIFICATION.createNotification(message, type);
Notifications.Bus.notify(currentNotify, project);
} catch (Exception e) {
//
}
}
19
Source : NotifyUtils.java
with Apache License 2.0
from WangJi92
with Apache License 2.0
from WangJi92
/**
* 消息
*
* @param project
* @param message
*/
public static void notifyMessage(Project project, String message) {
try {
Notification currentNotify = NOTIFICATION.createNotification(message, NotificationType.INFORMATION);
Notifications.Bus.notify(currentNotify, project);
} catch (Exception e) {
//
}
}
19
Source : NotifyUtils.java
with Apache License 2.0
from WangJi92
with Apache License 2.0
from WangJi92
/**
* 通知消息
*
* @param project
*/
public static void notifyMessageDefault(Project project) {
notifyMessage(project, COMMAND_COPIED);
}
19
Source : BaseArthasPluginAction.java
with Apache License 2.0
from WangJi92
with Apache License 2.0
from WangJi92
/**
* 构造命令信息,处理命令后续操作
*
* @param clreplacedName
* @param methodName
* @param project
* @param psiElement
* @return
*/
public void doCommand(String clreplacedName, String methodName, Project project, PsiElement psiElement) {
}
19
Source : MirrorLauncher.java
with Apache License 2.0
from wajahatkarim3
with Apache License 2.0
from wajahatkarim3
private void showChoosePathDialog(Project project) {
ChoosePathDialog pathDialog = new ChoosePathDialog(project, new MirrorPathSelectedCallback() {
@Override
public void onPathSelected(String path) {
launchScrcpy(path, project);
}
});
pathDialog.setreplacedle("Choose your mirror path such as scrcpy or Vysor.");
pathDialog.setSize(new Dimension(300, 150));
pathDialog.setMaximumSize(new Dimension(300, 150));
pathDialog.setPreferredSize(new Dimension(300, 150));
pathDialog.setMinimumSize(new Dimension(300, 150));
pathDialog.setLocationByPlatform(true);
pathDialog.setLocationRelativeTo(null);
pathDialog.setVisible(true);
}
19
Source : ChoosePathMenuAction.java
with Apache License 2.0
from wajahatkarim3
with Apache License 2.0
from wajahatkarim3
private void showChoosePathDialog(Project project) {
ChoosePathDialog pathDialog = new ChoosePathDialog(project, null);
pathDialog.setreplacedle("Choose scrcpy EXE path");
pathDialog.setSize(new Dimension(300, 150));
pathDialog.setMaximumSize(new Dimension(300, 150));
pathDialog.setPreferredSize(new Dimension(300, 150));
pathDialog.setMinimumSize(new Dimension(300, 150));
pathDialog.setLocationByPlatform(true);
pathDialog.setLocationRelativeTo(null);
pathDialog.setVisible(true);
}
19
Source : ChoosePathDialog.java
with Apache License 2.0
from wajahatkarim3
with Apache License 2.0
from wajahatkarim3
/**
* The dialog to allow the user to choose the path of either scrcpy (https://github.com/Genymobile/scrcpy) or
* Vysor (https://www.vysor.io/) EXE files. Once the path is set, then the action will directly open the file to mirror the connected
* Android device in the computer.
* @date 22/03/2020
* @author Wajahat Karim (https://wajahatkarim.com)
*/
public clreplaced ChoosePathDialog extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField mirrorPath;
private JButton browseButton;
Project project;
MirrorPathSelectedCallback pathSelectedCallback;
public ChoosePathDialog(final Project project, MirrorPathSelectedCallback pathSelected) {
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
this.project = project;
pathSelectedCallback = pathSelected;
String savedMirrorPath = PropertiesComponent.getInstance().getValue(MirrorLauncher.MIRROR_PATH_KEY);
if (savedMirrorPath != null && !savedMirrorPath.isEmpty()) {
mirrorPath.setText(savedMirrorPath);
}
browseButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false);
descriptor.setShowFileSystemRoots(true);
descriptor.withFileFilter(new Condition<VirtualFile>() {
@Override
public boolean value(VirtualFile virtualFile) {
return virtualFile != null;
}
});
VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null);
if (virtualFile != null) {
mirrorPath.setText(virtualFile.getCanonicalPath());
}
}
});
buttonOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!mirrorPath.getText().isEmpty()) {
PropertiesComponent.getInstance().setValue(MirrorLauncher.MIRROR_PATH_KEY, mirrorPath.getText());
if (pathSelected != null) {
pathSelected.onPathSelected(mirrorPath.getText());
}
onCancel();
} else {
JOptionPane.showMessageDialog(mirrorPath, "You must select a valid EXE file!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
});
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
}
private void onCancel() {
// add your code here if necessary
dispose();
}
}
19
Source : GitMachetePanel.java
with MIT License
from VirtusLab
with MIT License
from VirtusLab
@CustomLog
public final clreplaced GitMachetePanel extends SimpleToolWindowPanel {
private final Project project;
@UIEffect
public GitMachetePanel(Project project) {
super(/* vertical */
false, /* borderless */
true);
LOG.debug("Instantiating");
this.project = project;
val selectedGitRepositoryProvider = project.getService(SelectedGitRepositoryProvider.clreplaced);
val selectionComponent = selectedGitRepositoryProvider.getSelectionComponent();
val graphTable = getGraphTable();
// This clreplaced is final, so the instance is `@Initialized` at this point.
setToolbar(createGitMacheteVerticalToolbar(graphTable).getComponent());
add(createShrinkingWrapper(selectionComponent), BorderLayout.NORTH);
setContent(ScrollPaneFactory.createScrollPane(graphTable));
// The following listener executes on each opening of the Git Machete tab.
addAncestorListener(new AncestorListenerAdapter() {
@Override
public void ancestorAdded(AncestorEvent event) {
val gitRepository = selectedGitRepositoryProvider.getSelectedGitRepository().getOrNull();
if (gitRepository != null) {
val macheteFilePath = getMacheteFilePath(gitRepository);
Runnable queueDiscoverOperation = () -> graphTable.queueDiscover(macheteFilePath, () -> {
});
val rediscoverSuggester = new RediscoverSuggester(gitRepository, queueDiscoverOperation);
graphTable.queueRepositoryUpdateAndModelRefresh(() -> rediscoverSuggester.perform());
}
}
});
}
public BaseEnhancedGraphTable getGraphTable() {
return project.getService(GraphTableProvider.clreplaced).getGraphTable();
}
@UIEffect
private static ActionToolbar createGitMacheteVerticalToolbar(BaseEnhancedGraphTable graphTable) {
val actionManager = ActionManager.getInstance();
val toolbarActionGroup = (ActionGroup) actionManager.getAction(ActionGroupIds.ACTION_GROUP_TOOLBAR);
val toolbar = actionManager.createActionToolbar(ActionPlaces.ACTION_PLACE_TOOLBAR, toolbarActionGroup, /* horizontal */
false);
toolbar.setTargetComponent(graphTable);
return toolbar;
}
@UIEffect
private static JComponent createShrinkingWrapper(JComponent component) {
final JPanel wrapper = new JPanel(new BorderLayout());
wrapper.add(component, BorderLayout.WEST);
wrapper.add(Box.createHorizontalGlue(), BorderLayout.CENTER);
return wrapper;
}
}
19
Source : GitMacheteContentProvider.java
with MIT License
from VirtusLab
with MIT License
from VirtusLab
public clreplaced GitMacheteContentProvider implements ChangesViewContentProvider {
private final Project project;
public GitMacheteContentProvider(Project project) {
this.project = project;
}
@Override
@UIEffect
public JComponent initContent() {
return new GitMachetePanel(project);
}
@Override
public void disposeContent() {
}
}
19
Source : GitRepositoryComboBox.java
with MIT License
from VirtusLab
with MIT License
from VirtusLab
@CustomLog
public final clreplaced GitRepositoryComboBox extends JComboBox<GitRepository> implements IGitRepositorySelectionComponentProvider {
private final java.util.List<IGitRepositorySelectionChangeObserver> observers = new SmartList<>();
private final Project project;
@UIEffect
public GitRepositoryComboBox(Project project) {
super(new MutableCollectionComboBoxModel<>());
this.project = project;
updateRepositories();
setRenderer(SimpleListCellRenderer.create(/* nullValue */
"", repo -> repo.getRoot().getName()));
project.getMessageBus().connect().subscribe(VcsRepositoryManager.VCS_REPOSITORY_MAPPING_UPDATED, () -> {
LOG.debug("Git repository mappings changed");
GuiUtils.invokeLaterIfNeeded(() -> updateRepositories(), ModalityState.NON_MODAL);
});
}
@Override
@SafeEffect
public MutableCollectionComboBoxModel<GitRepository> getModel() {
return (MutableCollectionComboBoxModel<GitRepository>) super.getModel();
}
@UIEffect
private void updateRepositories() {
// A bit of a shortcut: we're accessing filesystem even though we are on the UI thread here;
// this shouldn't ever be a heavyweight operation, however.
List<GitRepository> repositories = List.ofAll(GitUtil.getRepositories(project));
LOG.debug("Git repositories:");
repositories.forEach(r -> LOG.debug("* ${r.getRoot().getName()}"));
// `com.intellij.ui.MutableCollectionComboBoxModel.getSelected` must be performed
// before `com.intellij.ui.MutableCollectionComboBoxModel.update`
// because the update method sets the selected item to null
GitRepository selected = getModel().getSelected();
if (!getModel().gereplacedems().equals(repositories)) {
getModel().update(DvcsUtil.sortRepositories(repositories.asJavaMutable()));
}
this.setVisible(getModel().gereplacedems().size() > 1);
boolean selectedItemUpdateRequired = selected == null || !getModel().gereplacedems().contains(selected);
if (repositories.isEmpty()) {
// TODO (#255): properly handle plugin visibility/"empty" text on no-repo project
LOG.debug("No Git repositories found");
if (selected != null) {
setSelectedItem(null);
}
} else if (selectedItemUpdateRequired) {
LOG.debug("Selecting first Git repository");
setSelectedItem(repositories.get(0));
} else {
LOG.debug("Selecting previously selected Git repository");
// GitRepositoryComboBox#setSelectedItem is omitted to avoid unnecessary observers call
getModel().setSelectedItem(selected);
}
}
@Override
public Option<GitRepository> getSelectedGitRepository() {
return Option.of(getModel().getSelected());
}
@Override
@UIEffect
public void setSelectedItem(@Nullable Object anObject) {
super.setSelectedItem(anObject);
observers.forEach(o -> o.onSelectionChanged());
}
public void addSelectionChangeObserver(IGitRepositorySelectionChangeObserver observer) {
observers.add(observer);
}
@Override
public JComponent getSelectionComponent() {
return this;
}
}
See More Examples