промежуточный. частичный рефакторинг с прицелом на библиотечную часть

This commit is contained in:
2024-10-07 00:58:29 +03:00
parent c211ffb82b
commit 6b1576461d
798 changed files with 3007 additions and 2344 deletions

View File

@@ -0,0 +1,25 @@
package Common_old.Utils.Files;
import Common_old.Constants;
import Common_old.Utils.Utils;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.io.File;
public class ProjectsChooser extends VFileChooser_ {
public ProjectsChooser(String title) {
super(title, new FileFilter() {
@Override
public boolean accept(File f) {
return
!Utils.ContainsCyrillic(f.getAbsolutePath()) &&
!f.getName().equalsIgnoreCase(Constants.data)
;
}
@Override
public String getDescription() {
return "Все папки";
}
});
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
}

View File

@@ -0,0 +1,21 @@
package Common_old.Utils.Files;
import Common_old.Utils.Utils;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.io.File;
public class VDirectoryChooser extends VFileChooser_ {
public VDirectoryChooser(String title) {
super(title, new FileFilter() {
@Override
public boolean accept(File f) {
return !Utils.ContainsCyrillic(f.getAbsolutePath());
}
@Override
public String getDescription() {
return "Все папки";
}
});
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
}

View File

@@ -0,0 +1,44 @@
package Common_old.Utils.Files;
import Common_old.Utils.Utils;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.io.File;
import java.util.Arrays;
import java.util.Vector;
public class VFileChooser extends VFileChooser_ {
Vector<String> Extensions = new Vector<>();
String extensionsLine = "";
public VFileChooser(String title, String... extensions_in) {
super(title, null);
Extensions.addAll(Arrays.asList(extensions_in));
if (Extensions.isEmpty())
extensionsLine = "*.*";
else
for (String ext : Extensions)
extensionsLine += "*" + (ext.isEmpty() ? "" : ".") + ext + ";";
fileChooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return !Utils.ContainsCyrillic(f.getName())
&& (f.isDirectory() || acceptExtensions(f));
}
@Override
public String getDescription() {
return extensionsLine;
}
});
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
public VFileChooser(String title, FileFilter filter_in) {
super(title, filter_in);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
public boolean acceptExtensions(File file) {
if (Extensions.isEmpty()) return true;
String file_ext = Utils.getExtension(file);
for (String ext : Extensions)
if (ext.equalsIgnoreCase(file_ext)) return true;
return false;
}
}

View File

@@ -0,0 +1,50 @@
package Common_old.Utils.Files;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.io.File;
import java.util.Arrays;
import java.util.Vector;
public class VFileChooser_ {
protected JFileChooser fileChooser = new JFileChooser() {
@Override
protected JDialog createDialog(Component parent) throws HeadlessException {
JDialog res = super.createDialog(parent);
res.setAlwaysOnTop(true);
return res;
}
};
public File getCurrentDirectory(){
return fileChooser.getCurrentDirectory();
}
public VFileChooser_(String title, FileFilter filter) {
fileChooser.setDialogTitle(title);
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setFileFilter(filter);
}
public void setTitle(String title_in) {
fileChooser.setDialogTitle(title_in);
}
public File ShowDialog() {
fileChooser.setMultiSelectionEnabled(false);
File result = null;
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
result = fileChooser.getSelectedFile();
}
return result;
}
public Vector<File> ShowMultiDialog() {
fileChooser.setMultiSelectionEnabled(true);
Vector<File> result = new Vector<>();
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
result = new Vector<>(Arrays.asList(fileChooser.getSelectedFiles()));
}
return result;
}
public void SetCurrentDirectory(String dir) {
fileChooser.setCurrentDirectory(new File(dir));
}
public void SetCurrentDirectory(File dir) {
fileChooser.setCurrentDirectory(dir);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,234 @@
package Common_old.Utils.Validators;
import Common_old.Utils.Utils;
import GlobalData.Compiler.Compiler;
import GlobalData.CompilerEnvironment.CompilerEnvironment;
import GlobalData.CompilerOption.CompilerOption;
import java.util.Arrays;
public class DVMHelpParser {
public static HelpParserState state;
public static String t_line;
public static String line;
//-
public static OptionState optionState;
public static CompilerOption option;
//-
public static int spacesCounter;
public static CompilerEnvironment environment;
public static EnvironmentState environmentState;
//-
public static String descriptionLine = "";
//-
public static Compiler compiler = null;
public static String[] banned_options = new String[]{
"-o",
"-c",
"-f90",
"-FI"
};
public static void ResetOption() {
optionState = OptionState.SearchName;
option = null;
descriptionLine = "";
}
public static void TryConfirmOptionDescriptionLine() {
if (option != null && !descriptionLine.isEmpty()) {
option.description.add(descriptionLine.trim());
descriptionLine = "";
}
}
public static void TryConfirmOption() {
if ((option != null) && (!compiler.options.containsKey(option.name))) {
if (!descriptionLine.isEmpty())
option.description.add(descriptionLine.trim());
option.CheckParameterVariants();
if (!Arrays.asList(banned_options).contains(option.name)) {
compiler.options.put(option.name, option);
}
ResetOption();
}
}
public static void ResetEnvironment() {
environmentState = EnvironmentState.SearchName;
spacesCounter = 0;
environment = null;
descriptionLine = "";
}
public static void TryConfirmEnvironmentDescriptionLine() {
if (environment != null && !descriptionLine.isEmpty()) {
environment.description.add(descriptionLine.trim());
descriptionLine = "";
}
}
public static void TryConfirmEnvironment() {
if ((environment != null) && (!compiler.environments.containsKey(environment.name))) {
if (!descriptionLine.isEmpty())
environment.description.add(descriptionLine.trim());
environment.CheckDefaults();
compiler.environments.put(environment.name, environment);
ResetEnvironment();
}
}
public static void ReadOptions(Compiler compiler_in) {
compiler = compiler_in;
String[] lines = compiler.helpText.split("\n");
state = HelpParserState.Search;
for (String line_ : lines) {
line = line_; //нужна для окружения. там пробелы нужно считать сразу.
t_line = Utils.remove(line_.trim(), "\r");
switch (state) {
case Search:
switch (t_line) {
case "Output and debugging options:":
case "Convertation options:":
case "Optimization options:":
state = HelpParserState.OptionsChapter;
ResetOption();
break;
case "Environment variables":
state = HelpParserState.EnvironmentsChapterHeader;
break;
}
break;
case EnvironmentsChapterHeader:
state = HelpParserState.EnvironmentsChapter;
ResetEnvironment();
break;
case OptionsChapter:
if (t_line.isEmpty()) {
TryConfirmOption();
state = HelpParserState.Search;
} else {
char[] symbols = t_line.toCharArray();
//- Новая строка.
optionState = OptionState.SearchName;
//-
for (char c : symbols) {
switch (optionState) {
case SearchName:
switch (c) {
case '-':
TryConfirmOption();
//-
option = new CompilerOption();
option.name += c;
optionState = OptionState.Name;
break;
default:
descriptionLine += c;
optionState = OptionState.Description;
break;
}
break;
case Name:
switch (c) {
case '<':
optionState = OptionState.Parameter;
break;
case ' ':
case '=':
case '\t':
option.parameterSeparator += c;
optionState = OptionState.SearchParameter;
break;
default:
option.name += c;
break;
}
break;
case SearchParameter:
if (c == '<') {
optionState = OptionState.Parameter;
} else {
option.parameterSeparator = "";
optionState = OptionState.Description;
descriptionLine += c;
}
break;
case Parameter:
if (c == '>') {
optionState = OptionState.SearchDescription;
} else {
option.parameterName += c;
}
break;
case SearchDescription:
if (c != ' ') {
descriptionLine += c;
optionState = OptionState.Description;
}
break;
case Description:
descriptionLine += c;
break;
}
}
//-
TryConfirmOptionDescriptionLine();
}
break;
case EnvironmentsChapter:
if (t_line.isEmpty()) {
TryConfirmEnvironment();
state = HelpParserState.Search;
} else {
char[] symbols = line.toCharArray();
//- Новая строка.
environmentState = EnvironmentState.SearchName;
spacesCounter = 0;
//-
for (char c : symbols) {
switch (environmentState) {
case SearchName:
if (c == ' ') {
if (spacesCounter++ > 4) {
//имя нам уже не встретится. это строка описания.
environmentState = EnvironmentState.Description;
}
} else if (Character.isLetter(c)) {
if (spacesCounter == 4) {
TryConfirmEnvironment();
environment = new CompilerEnvironment();
environment.name += c;
environmentState = EnvironmentState.Name;
}
} else {
descriptionLine += c;
environmentState = EnvironmentState.Description;
}
break;
case Name:
//в имени окружения пробелов быть не может. ждем описания.
if (c == ' ') {
environmentState = EnvironmentState.SearchDescription;
} else if (Character.isLetterOrDigit(c) || c == '_') {
//буквы цифры и подчеркивания - имя продолжается.
environment.name += c;
} else {
descriptionLine += c;
environmentState = EnvironmentState.Description;
}
break;
case SearchDescription:
if (c == ' ') {
//игнорируем.
} else {
descriptionLine += c;
environmentState = EnvironmentState.Description;
}
break;
case Description:
descriptionLine += c;
break;
}
TryConfirmOptionDescriptionLine();
}
//-
TryConfirmEnvironmentDescriptionLine();
}
break;
}
}
}
//------------------------------------------------------------------------------------>>
}

View File

@@ -0,0 +1,8 @@
package Common_old.Utils.Validators;
public enum EnvironmentState {
SearchName,
Name,
//-
SearchDescription,
Description
}

View File

@@ -0,0 +1,10 @@
package Common_old.Utils.Validators;
public enum HelpParserState {
Search,
OptionsChapter,
//------------------
//------------------
EnvironmentsChapterHeader,
EnvironmentsChapter,
End
}

View File

@@ -0,0 +1,11 @@
package Common_old.Utils.Validators;
public enum OptionState {
SearchName,
Name,
//-
SearchParameter,
Parameter,
//-
SearchDescription,
Description
}

View File

@@ -0,0 +1,69 @@
package Common_old.Utils.Validators;
import Common_old.Constants;
import Common.Utils.TextLog;
import Common_old.Utils.Utils;
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
public class PathValidator extends Validator {
PathValidatorState state;
StringBuilder name;
int spaces_count;
public PathValidator(String string, String string_name_in, TextLog log_in) {
super(string, string_name_in, log_in);
}
@Override
protected void reset() {
state = PathValidatorState.Start;
name = new StringBuilder();
spaces_count = 0;
}
@Override
protected boolean continueCondition() {
return (state == PathValidatorState.Name) || state == PathValidatorState.Start;
}
@Override
protected void Body() {
switch (state) {
case Start:
if (RSyntaxUtilities.isLetter(c) || RSyntaxUtilities.isDigit(c) || c == '_') {
name.append(c);
state = PathValidatorState.Name;
} else state = PathValidatorState.WrongNameFormat;
break;
case Name:
switch (c) {
case '/':
reset();
break;
case ' ':
spaces_count++;
name.append(c);
break;
default:
if (Utils.isForbidden(c))
state = PathValidatorState.Forbidden;
else name.append(c);
break;
}
break;
}
}
@Override
protected void PerformFinish() {
switch (state) {
case WrongNameFormat:
Log.Writeln(string_name + ": имя файла или каталога в пути имеет неверный формат");
break;
case Forbidden:
Log.Writeln(string_name + ": Составляющие путь имена содержат запрещённые символы \n" + Constants.all_forbidden_characters_string);
break;
case Name:
if (spaces_count > 0)
Log.Writeln(string_name + ": Пробелы в окончании пути к файлу запрещены.");
break;
}
}
@Override
protected int getStartIndex() {
return 1;
}
}

View File

@@ -0,0 +1,8 @@
package Common_old.Utils.Validators;
public enum PathValidatorState {
Start,
Name,
WrongNameFormat,
Forbidden,
SpacesInLastName
}

View File

@@ -0,0 +1,292 @@
package Common_old.Utils.Validators;
import Common_old.Constants;
import _VisualDVM.Global;
import Common_old.Utils.Utils;
import java.io.InputStreamReader;
import java.util.Vector;
public class ShellParser {
public static ShellParserState state;
public static StringBuilder lineBuilder;
public static String userName;
public static StringBuilder invitationBuilder;
public static char c;
public static char[] buffer = new char[1];
public static Vector<String> lines = new Vector<>();
// public static boolean bracketOpened = false;
public static boolean return_active = false;
public static boolean isCommandSymbol() {
int code = c;
return code <= 31 || c == 127;
}
public static void ResetLine() {
invitationBuilder = new StringBuilder();
lineBuilder = new StringBuilder();
// bracketOpened = false;
state = ShellParserState.NewLine;
return_active = false;
}
public static boolean isNameCharacter() {
//латиница, цифры,подчеркивания. и -
return String.valueOf(c).matches("[\\w\\-]*") || c == '?';
}
public static boolean isRBracket(){
return c=='('||c==')';
}
//false наоборот означать что конец строки ЕСТЬ.
public static boolean checkEndLine() {
if (return_active) {
switch (c) {
case '\n':
//ложная тревога. возврат каретки ни на что не влияет.
lines.add(lineBuilder.toString());
ResetLine();
return false;
case '\r':
return false;
default:
//тут был возврат. надо игнорить символ, ибо он уже прочитан.
return_active = false;
return false;
}
} else {
switch (c) {
case '\r':
return_active = true;
return false;
case '\n':
lines.add(lineBuilder.toString());
ResetLine();
return false;
}
}
return true;
}
/*
public static void NewLine() {
if (c == '[') {//приглашение со скобками.
// bracketOpened = true;
invitationBuilder.append(c);
state = ShellParserState.UserName;
} else {
if (isNameCharacter()) {
invitationBuilder.append(c);
state = ShellParserState.UserName;
} else
//не буква и не скобка. значит в этой строке приглашения нет.
state = ShellParserState.Skip;
}
}
*/
public static void NewLine() {
if (c=='@'){ //собака, признак приглашения.
String test = invitationBuilder.toString();
test = test.toLowerCase();
state = test.endsWith(userName.toLowerCase()) ? ShellParserState.MachineName : ShellParserState.Skip;
invitationBuilder.append(c);
}else {
invitationBuilder.append(c);
}
/*
if (c == '[') {//приглашение со скобками.
// bracketOpened = true;
invitationBuilder.append(c);
state = ShellParserState.UserName;
} else {
if (isNameCharacter()) {
invitationBuilder.append(c);
state = ShellParserState.UserName;
} else
//не буква и не скобка. значит в этой строке приглашения нет.
state = ShellParserState.Skip;
}
*/
}
/*
public static void UserName() {
if (c == '@') { //проверить. а тот ли юзернейм.
String test = invitationBuilder.toString();
// if (bracketOpened) test = test.substring(1);
test = test.toLowerCase();
state = test.endsWith(userName.toLowerCase()) ? ShellParserState.MachineName : ShellParserState.Skip;
invitationBuilder.append(c);
} else if (isNameCharacter() || (c == '['))
invitationBuilder.append(c);
else
state = ShellParserState.Skip;
}
*/
public static void MachineName() {
switch (c) {
case ' ':
case ':':
state = ShellParserState.Path;
invitationBuilder.append(c);
break;
default:
if (isNameCharacter())
invitationBuilder.append(c);
else state = ShellParserState.Skip;
break;
}
}
public static void Path() {
switch (c) {
case '$':
case '#':
case '>':
invitationBuilder.append(c);
state = ShellParserState.Space; //приглашение завершено. осталось прочитать пробел после него
break;
/*
case ']':
if (bracketOpened) {
invitationBuilder.append(c);
bracketOpened = false;
} else {
// UI.Info("KEK");
state = ShellParserState.Skip; //непарная скобка, все, привет
}
break;
*/
default:
invitationBuilder.append(c);
break;
}
}
public static void Space() {
if (c == ' ') {
state = ShellParserState.End;
invitationBuilder.append(c);
} else {
state = ShellParserState.Skip;
}
}
public static void setUserName(String userName_in) {
userName = userName_in;
}
public static void printChar() {
if (c != Constants.boop) {
int code = c;
if ((!return_active) || (c == '\n')) {
System.out.print(c == '\r' ? ("\\r") :
(c == '\n' ? "\\n\n" : c));
if (isCommandSymbol())
System.out.print(Utils.RBrackets(code));
}
}
}
public static void ReadInvitation(InputStreamReader fromServer) {
lines.clear();
ResetLine();
do {
try {
if (fromServer.read(buffer) >= 0) {
c = buffer[0];
printChar();
// if (!isCommandSymbol()) {
if (checkEndLine() && (!isCommandSymbol())) {
lineBuilder.append(c);
switch (state) {
case NewLine:
NewLine();
break;
// case UserName:
// UserName();
// break;
case MachineName:
MachineName();
break;
case Path:
Path();
break;
case Space:
Space();
break;
case Skip:
break;
}
}
} else
state = ShellParserState.End;
} catch (Exception ex) {
Global.Log.PrintException(ex);
state = ShellParserState.End;
}
} while (!state.equals(ShellParserState.End));
}
public static String ReadLine(InputStreamReader fromServer) {
StringBuilder res = new StringBuilder();
state = ShellParserState.NewLine;
do {
try {
if (fromServer.read(buffer) >= 0) {
c = buffer[0];
printChar();
switch (c) {
case '\r':
break;
case '\n':
state = ShellParserState.End;
break;
default:
res.append(c);
break;
}
} else
state = ShellParserState.End;
} catch (Exception ex) {
Global.Log.PrintException(ex);
state = ShellParserState.End;
}
} while (!state.equals(ShellParserState.End));
return res.toString();
}
public static void ReadCommand(String command, InputStreamReader fromServer){
StringBuilder res = new StringBuilder();
do {
try {
if (fromServer.read(buffer) >= 0) {
c = buffer[0];
printChar();
switch (c) {
case '\r':
break;
case '\n':
break;
default:
res.append(c);
break;
}
} else
return;
} catch (Exception ex) {
Global.Log.PrintException(ex);
return;
}
} while (!res.toString().contains(command));
}
public static String getCommandResult(InputStreamReader fromServer) {
//если последняя строка ответа - кончается на приглашение, то ничего не делаем.
//если нет. значит ответ кончается на перевод строки. или пуст.
// нужно прочитать еще одно приглашение.
String last_line = "";
String res = "";
boolean no_extra_read = false;
if (lines.size() > 0) {
last_line = lines.lastElement();
if (no_extra_read = last_line.endsWith(invitationBuilder.toString())) {
lines.remove(lines.size() - 1);
//больше ничего не читаем. но. обрезаем ее конец.
last_line = last_line.substring(0, last_line.length() - invitationBuilder.length());
lines.add(last_line);
}
res = String.join("\n", lines);
}
if (!no_extra_read) {
ReadInvitation(fromServer);
}
return res;
}
}

View File

@@ -0,0 +1,12 @@
package Common_old.Utils.Validators;
public enum ShellParserState {
//--------------------------------
NewLine, //начало строки.
UserName, //имя пользователя.
MachineName, //имя машины
Path, //путь к текущей папке - часть приглашения
Space, //завершающий приглашение пробел.
Skip, //гарантированно не приглашение.
//--------------------------------
End//выход
}

View File

@@ -0,0 +1,14 @@
package Common_old.Utils.Validators;
import Common.Utils.TextLog;
public class StatementsChecker {
public static boolean Check(TextLog Log, boolean drop_on_first, Object... args) {
if (args.length % 2 != 0) return false;
for (int i = 0; i < args.length; i += 2) {
if ((boolean) args[i]) {
Log.Writeln((String) args[i + 1]);
if (drop_on_first) return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,34 @@
package Common_old.Utils.Validators;
import Common.Utils.TextLog;
public class Validator {
protected char c;
protected int i;
protected String string_name;
protected char[] chars;
protected TextLog Log;
public Validator(String string, String string_name_in, TextLog log_in) {
string_name = string_name_in;
chars = string.toCharArray();
Log = log_in;
reset();
}
protected void reset() {
}
protected int getStartIndex() {
return 0;
}
protected boolean continueCondition() {
return true;
}
protected void Body() {
}
protected void PerformFinish() {
}
public void Validate() {
for (i = getStartIndex(); i < chars.length && continueCondition(); ++i) {
c = chars[i];
Body();
}
PerformFinish();
}
}