use of com.intellij.openapi.util.Pair in project freeline by alibaba.
the class FreelineUtil method checkInstall.
/**
* 检查是否需要载入Freeline
*
* @param project
* @return
*/
public static boolean checkInstall(@NotNull final Project project) {
final FreelineStatus status = getFreelineStatus(project);
if (GradleUtil.isSyncInProgress(project)) {
NotificationUtils.errorMsgDialog("Waiting for sync project to complete");
return false;
}
if (status.hasInitFreeline()) {
return true;
}
if (status.getGradleBuildFiles().size() < 1) {
NotificationUtils.errorMsgDialog("It's not an Android Gradle project Currently?");
return false;
}
if (status.isExistClasspath() && status.isExistPlugin() && !status.isExistFreelineCore()) {
NotificationUtils.errorNotification("Execute task initFreeline and download freeline dependencies...");
initFreeline(project);
return false;
}
if (DialogUtil.createDialog("Detected that you did not installFreeline Freeline, Whether installFreeline Automatically?", "Install Freeline Automatically", "Cancel")) {
Module[] modules = ModuleManager.getInstance(project).getModules();
List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>();
for (Module module : modules) {
GradleBuildFile file = GradleBuildFile.get(module);
if (file != null && !GradleUtil.isLibrary(file)) {
selectModulesList.add(Pair.create(module, file.getPsiFile()));
}
}
// 多个app模块的情况
if (selectModulesList.size() > 1) {
final DialogBuilder builder = new DialogBuilder();
builder.setTitle("Install Freeline");
builder.resizable(false);
builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the module to be installed Freeline.", Messages.getInformationIcon(), SwingConstants.CENTER));
builder.addOkAction().setText("Cancel");
for (final Pair<Module, PsiFile> pair : selectModulesList) {
builder.addAction(new AbstractAction(":" + pair.first.getName()) {
@Override
public void actionPerformed(ActionEvent e) {
builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE);
installFreeline(project, status, pair.getSecond());
}
});
}
if (builder.show() > -1) {
return false;
}
} else if (selectModulesList.size() == 1) {
installFreeline(project, status, selectModulesList.get(0).getSecond());
} else {
NotificationUtils.errorMsgDialog("Can not found Application Module! Please Sync Project.");
return false;
}
}
return false;
}
use of com.intellij.openapi.util.Pair in project freeline by alibaba.
the class UsingReportAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
final Project project = event.getProject();
Module[] modules = ModuleManager.getInstance(project).getModules();
List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>();
for (Module module : modules) {
GradleBuildFile file = GradleBuildFile.get(module);
if (file != null && !GradleUtil.isLibrary(file)) {
selectModulesList.add(Pair.create(module, file.getPsiFile()));
}
}
if (selectModulesList.size() > 1) {
final DialogBuilder builder = new DialogBuilder();
builder.setTitle("Freeline Reporter");
builder.resizable(false);
builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the exact one.", Messages.getInformationIcon(), SwingConstants.CENTER));
builder.addOkAction().setText("Cancel");
for (final Pair<Module, PsiFile> pair : selectModulesList) {
builder.addAction(new AbstractAction(":" + pair.first.getName()) {
@Override
public void actionPerformed(ActionEvent e) {
builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE);
report(project, pair.getSecond());
}
});
}
if (builder.show() > -1) {
//return false;
}
} else if (selectModulesList.size() == 1) {
report(project, selectModulesList.get(0).getSecond());
}
}
use of com.intellij.openapi.util.Pair in project intellij-elixir by KronicDeth.
the class CreateElixirModuleAction method buildDialog.
/*
* Protected Instance Methods
*/
/**
* todo: the Application-template, Supervisor-template, GenServer-template, GenEvent-template should be improved
*/
@Override
protected void buildDialog(@NotNull Project project, @NotNull final PsiDirectory directory, @NotNull CreateFileFromTemplateDialog.Builder builder) {
builder.setTitle(NEW_ELIXIR_MODULE).addKind("Empty module", ElixirIcons.FILE, "Elixir Module").addKind("Elixir Application", ElixirIcons.ELIXIR_APPLICATION, "Elixir Application").addKind("Elixir Supervisor", ElixirIcons.ELIXIR_SUPERVISOR, "Elixir Supervisor").addKind("Elixir GenServer", ElixirIcons.ELIXIR_GEN_SERVER, "Elixir GenServer").addKind("Elixir GenEvent", ElixirIcons.ELIXIR_GEN_EVENT, "Elixir GenEvent").setValidator(new InputValidatorEx() {
/*
* Public Instance Methods
*/
@Override
public boolean canClose(String inputString) {
return !StringUtil.isEmptyOrSpaces(inputString) && getErrorText(inputString) == null;
}
@Override
public boolean checkInput(String inputString) {
return checkFormat(inputString) && checkDoesNotExist(inputString);
}
@Nullable
@Override
public String getErrorText(String inputString) {
String errorText = null;
if (!StringUtil.isEmpty(inputString)) {
if (!checkFormat(inputString)) {
errorText = String.format(INVALID_MODULE_MESSAGE_FMT, inputString);
} else if (!checkDoesNotExist(inputString)) {
String fullPath = fullPath(directory, ancestorDirectoryNamesBaseNamePair(inputString));
errorText = String.format(EXISTING_MODULE_MESSAGE_FMT, fullPath);
}
}
return errorText;
}
/*
* Private Instance Methods
*/
private boolean checkDoesNotExist(@NotNull String moduleName) {
Pair<List<String>, String> ancestorDirectoryNamesBaseNamePair = ancestorDirectoryNamesBaseNamePair(moduleName);
List<String> ancestorDirectoryNames = ancestorDirectoryNamesBaseNamePair.first;
PsiDirectory currentDirectory = directory;
boolean doesNotExists = false;
for (String ancestorDirectoryName : ancestorDirectoryNames) {
PsiDirectory subdirectory = currentDirectory.findSubdirectory(ancestorDirectoryName);
if (subdirectory == null) {
doesNotExists = true;
break;
}
currentDirectory = subdirectory;
}
// if all the directories exist
if (!doesNotExists) {
String baseName = ancestorDirectoryNamesBaseNamePair.second;
doesNotExists = currentDirectory.findFile(baseName) == null;
}
return doesNotExists;
}
private boolean checkFormat(@NotNull String inputString) {
Matcher matcher = MODULE_NAME_PATTERN.matcher(inputString);
return matcher.matches();
}
});
}
use of com.intellij.openapi.util.Pair in project intellij-elixir by KronicDeth.
the class Module method childCallTreeElements.
/*
* Private Static Methods
*/
@Contract(pure = true)
@Nullable
private static TreeElement[] childCallTreeElements(@NotNull Modular modular, Call[] childCalls) {
TreeElement[] treeElements = null;
if (childCalls != null) {
int length = childCalls.length;
final List<TreeElement> treeElementList = new ArrayList<TreeElement>(length);
FunctionByNameArity functionByNameArity = new FunctionByNameArity(length, treeElementList, modular);
MacroByNameArity macroByNameArity = new MacroByNameArity(length, treeElementList, modular);
Set<Overridable> overridableSet = new HashSet<Overridable>();
Set<org.elixir_lang.structure_view.element.Use> useSet = new HashSet<org.elixir_lang.structure_view.element.Use>();
for (Call childCall : childCalls) {
if (Callback.is(childCall)) {
treeElementList.add(new Callback(modular, childCall));
} else if (Delegation.is(childCall)) {
functionByNameArity.addDelegationToTreeElementList(childCall);
} else if (Exception.is(childCall)) {
functionByNameArity.setException(new Exception(modular, childCall));
} else if (CallDefinitionClause.isFunction(childCall)) {
functionByNameArity.addClausesToCallDefinition(childCall);
} else if (CallDefinitionSpecification.is(childCall)) {
functionByNameArity.addSpecificationToCallDefinition(childCall);
} else if (Implementation.is(childCall)) {
treeElementList.add(new Implementation(modular, childCall));
} else if (CallDefinitionClause.isMacro(childCall)) {
macroByNameArity.addClausesToCallDefinition(childCall);
} else if (Module.is(childCall)) {
treeElementList.add(new Module(modular, childCall));
} else if (Overridable.is(childCall)) {
Overridable overridable = new Overridable(modular, childCall);
overridableSet.add(overridable);
treeElementList.add(overridable);
} else if (Protocol.is(childCall)) {
treeElementList.add(new Protocol(modular, childCall));
} else if (org.elixir_lang.structure_view.element.Quote.is(childCall)) {
treeElementList.add(new Quote(modular, childCall));
} else if (Structure.is(childCall)) {
treeElementList.add(new Structure(modular, childCall));
} else if (Type.is(childCall)) {
treeElementList.add(Type.fromCall(modular, childCall));
} else if (org.elixir_lang.structure_view.element.Use.is(childCall)) {
org.elixir_lang.structure_view.element.Use use = new org.elixir_lang.structure_view.element.Use(modular, childCall);
useSet.add(use);
treeElementList.add(use);
} else if (Unknown.is(childCall)) {
// Should always be last since it will match all macro calls
treeElementList.add(new Unknown(modular, childCall));
}
}
for (Overridable overridable : overridableSet) {
for (TreeElement treeElement : overridable.getChildren()) {
CallReference callReference = (CallReference) treeElement;
Integer arity = callReference.arity();
if (arity != null) {
String name = callReference.name();
CallDefinition function = functionByNameArity.get(pair(name, arity));
if (function != null) {
function.setOverridable(true);
}
}
}
}
Collection<TreeElement> useCollection = new HashSet<TreeElement>(useSet.size());
useCollection.addAll(useSet);
Collection<TreeElement> nodesFromUses = Used.provideNodesFromChildren(useCollection);
Map<Pair<String, Integer>, CallDefinition> useFunctionByNameArity = Used.functionByNameArity(nodesFromUses);
for (Map.Entry<Pair<String, Integer>, CallDefinition> useNameArityFunction : useFunctionByNameArity.entrySet()) {
CallDefinition useFunction = useNameArityFunction.getValue();
if (useFunction.isOverridable()) {
Pair<String, Integer> useNameArity = useNameArityFunction.getKey();
CallDefinition function = functionByNameArity.get(useNameArity);
if (function != null) {
function.setOverride(true);
}
}
}
treeElements = treeElementList.toArray(new TreeElement[treeElementList.size()]);
}
return treeElements;
}
use of com.intellij.openapi.util.Pair in project intellij-elixir by KronicDeth.
the class CallDefinition method getLineMarkerInfo.
@Nullable
private LineMarkerInfo getLineMarkerInfo(@NotNull Call call) {
LineMarkerInfo lineMarkerInfo = null;
if (daemonCodeAnalyzerSettings.SHOW_METHOD_SEPARATORS && CallDefinitionClause.is(call)) {
Call previousCallDefinitionClause = siblingCallDefinitionClause(call, PREVIOUS_SIBLING);
boolean firstClause;
if (previousCallDefinitionClause == null) {
firstClause = true;
} else {
Pair<String, IntRange> callNameArityRange = nameArityRange(call);
if (callNameArityRange != null) {
Pair<String, IntRange> previousNameArityRange = nameArityRange(previousCallDefinitionClause);
firstClause = previousNameArityRange == null || !previousNameArityRange.equals(callNameArityRange);
} else {
firstClause = true;
}
}
if (firstClause) {
PsiElement previousExpression = previousSiblingExpression(call);
if (previousExpression instanceof AtUnqualifiedNoParenthesesCall) {
AtUnqualifiedNoParenthesesCall previousModuleAttributeDefinition = (AtUnqualifiedNoParenthesesCall) previousExpression;
String moduleAttributeName = moduleAttributeName(previousModuleAttributeDefinition);
if (moduleAttributeName.equals("@doc")) {
firstClause = false;
} else if (moduleAttributeName.equals("@spec")) {
Pair<String, IntRange> callNameArityRange = nameArityRange(call);
if (callNameArityRange != null) {
Pair<String, Integer> specNameArity = moduleAttributeNameArity(previousModuleAttributeDefinition);
if (specNameArity != null) {
Integer specArity = specNameArity.second;
IntRange callArityRange = callNameArityRange.second;
if (callArityRange.containsInteger(specArity)) {
firstClause = false;
}
}
}
}
}
}
if (firstClause) {
lineMarkerInfo = callDefinitionSeparator(call);
}
}
return lineMarkerInfo;
}
Aggregations