Skip to content

Cli application - #1

Open
ValchukDmitry wants to merge 7 commits into
masterfrom
CLI_application
Open

Cli application#1
ValchukDmitry wants to merge 7 commits into
masterfrom
CLI_application

Conversation

@ValchukDmitry

Copy link
Copy Markdown
Owner

No description provided.

@@ -0,0 +1,68 @@
package ru.ifmo.cli_application;

import javafx.util.Pair;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javafx ? Зачем? Тем более, что класс для такой пары уже написан --- ParserRule

Scanner scanner = new Scanner(inputStream);

while (!ctx.isClosed()) {
List<IToken> tokens = parser.parseTokens(scanner.nextLine());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Парсеру становится плохо на строчках вида echo '1" | 2'. Возможно, стоит еще подумать над регулярным выражением. И хорошо бы к нему написать разные сложные тесты

import java.util.Map;

public class Context {
private Map<String, String> variables;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем отдельно писать конструктор, если мапу можно и здесь инициализировать?

}
List<IToken> tokensToExecute = new ArrayList<>();
IExecutable executableCommand = null;
for (IToken token : tokens) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предлагаю ввести еще одну абстракцию <команда c параметрами>

List<String> splitedCommand = splittingFunction.apply(command);
List<IToken> outputTokens = new ArrayList<>(splitedCommand.size());
for (String commandToken : splitedCommand) {
if (commandToken.isEmpty() || commandToken.equals("\n")) {

@artbez artbez Mar 6, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мы же вроде по строчке считаем, может ли это условие когда-либо выполниться?

StringBuilder resultString = new StringBuilder();
for (IToken fileName : args) {
try {
Scanner scanner = new Scanner(new FileInputStream(fileName.toString()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files.lines(Paths.get(fileName.toString())) ?

StringBuilder resultString = new StringBuilder();
for (IToken fileName : args) {
try {
Scanner scanner = new Scanner(new FileInputStream(fileName.toString()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделать try с ресурсами?

public class PwdCommand implements IToken, IExecutable {
@Override
public String execute(List<IToken> args, String inputStream) {
return System.getProperty("user.dir");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мы можем перемещаться по папкам, а pwd все user.dir будет выдавать

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А, это уже hw4, данный комментарий учитывать не нужно

package ru.ifmo.cli_application.tokens;

public interface IToken {
String toString();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мб по-другому как-нибудь назвать? Так-то любой объект имеет метод toString()

public void start() throws IOException {
Scanner scanner = new Scanner(inputStream);

while (!ctx.isClosed()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше добавить обработку вообще всех ошибок

@yurii-litvinov yurii-litvinov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В целом всё ок, но хочется ещё немного доработок

import java.util.List;
import java.util.Scanner;

public class Application {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хочется больше комментариев. Хотя бы к каждому классу и паблик-методу (кроме геттеров-сеттеров и прочей мелочи)

}

public void start() throws IOException {
Scanner scanner = new Scanner(inputStream);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это же современная Java, тут лучше писать var в случаях, если тип переменной очевиден из правой части присваивания, дабы не писать дважды одно и то же

import java.util.regex.Pattern;

public class SimpleParser extends Parser {
private static Pattern splittingPattern = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так оно не может раскрыть "12$x" --- думает, что это строка, тогда как $x должна интерпретироваться как подстановка


import java.util.List;

public interface IExecutable {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Особенно интерфейсы следует документировать

Comment thread build.gradle
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы рекомендовал на JUnit 5 переходить, он более идеологически правильный. Но это можно не править

@yurii-litvinov yurii-litvinov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enough, зачтена

import java.util.HashMap;
import java.util.Map;

public class Context {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы не сказал, что с комментариями стало прям сильно лучше


public class Variable implements IToken {
String variable;
Context ctx;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поля с пакетной видимостью не нужны, дыра в инкапсуляции же.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants