Skip to content

Commit ac093a9

Browse files
committed
Refactor and optimize source code
1 parent e054235 commit ac093a9

File tree

60 files changed

+591
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+591
-347
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
public class AnnotationAttributeException extends BaseRuntimeException {
4+
public AnnotationAttributeException(String code, String message) {
5+
super(code, message);
6+
}
7+
}
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
package com.relogiclabs.jschema.exception;
22

33
import com.relogiclabs.jschema.message.ErrorDetail;
4-
import com.relogiclabs.jschema.type.EValue;
54

65
public class ArgumentTypeException extends InvalidArgumentException {
7-
public ArgumentTypeException(String message) {
8-
super(message);
9-
}
10-
11-
public ArgumentTypeException(String code, String message, Throwable cause) {
12-
super(code, message, cause);
6+
public ArgumentTypeException(String code, String message) {
7+
super(code, message);
138
}
149

1510
public ArgumentTypeException(ErrorDetail detail, Throwable cause) {
1611
super(detail, cause);
1712
}
18-
19-
@Override
20-
public FunctionArgumentTypeException failWithFunctionException() {
21-
return new FunctionArgumentTypeException(this);
22-
}
23-
24-
@Override
25-
public MethodArgumentTypeException failWithMethodException(EValue self) {
26-
return new MethodArgumentTypeException(self, this);
27-
}
2813
}
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
11
package com.relogiclabs.jschema.exception;
22

33
import com.relogiclabs.jschema.message.ErrorDetail;
4-
import com.relogiclabs.jschema.type.EValue;
54

65
public class ArgumentValueException extends InvalidArgumentException {
7-
public ArgumentValueException(String message) {
8-
super(message);
9-
}
10-
11-
public ArgumentValueException(String code, String message, Throwable cause) {
12-
super(code, message, cause);
13-
}
14-
156
public ArgumentValueException(ErrorDetail detail, Throwable cause) {
167
super(detail, cause);
178
}
18-
19-
@Override
20-
public InvalidArgumentException failWithFunctionException() {
21-
return new FunctionArgumentValueException(this);
22-
}
23-
24-
@Override
25-
public InvalidArgumentException failWithMethodException(EValue self) {
26-
return new MethodArgumentValueException(self, this);
27-
}
289
}

src/main/java/com/relogiclabs/jschema/exception/BaseRuntimeException.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88

99
@Getter @Setter
1010
public class BaseRuntimeException extends RuntimeException {
11-
// Exception creation method
11+
// Exception creation method prefix
1212
private static final String FAIL_METHOD_PREFIX = "fail";
1313
private String code;
1414

15-
public BaseRuntimeException(String message) {
16-
this(null, message, null);
17-
}
18-
1915
public BaseRuntimeException(String code, String message) {
2016
this(code, message, null);
2117
}
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
package com.relogiclabs.jschema.exception;
22

33
import com.relogiclabs.jschema.message.ErrorDetail;
4+
import org.antlr.v4.runtime.Token;
5+
6+
import static com.relogiclabs.jschema.message.MessageFormatter.formatForSchema;
7+
8+
public class ClassInstantiationException extends MultilevelRuntimeException {
9+
public ClassInstantiationException(String code, String message, Throwable cause) {
10+
super(code, message, cause);
11+
}
412

5-
public class ClassInstantiationException extends BaseRuntimeException {
613
public ClassInstantiationException(ErrorDetail detail, Throwable cause) {
714
super(detail, cause);
815
}
16+
17+
@Override
18+
public RuntimeException translate(Token token) {
19+
if(isHighLevel()) return this;
20+
return new ClassInstantiationException(formatForSchema(getCode(),
21+
getMessage(), token), this);
22+
}
923
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
public class DataOwnerMismatchedException extends BaseRuntimeException {
4+
public DataOwnerMismatchedException(String code, String message) {
5+
super(code, message);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
public class DuplicateMethodException extends BaseRuntimeException {
4+
public DuplicateMethodException(String code, String message) {
5+
super(code, message);
6+
}
7+
}

src/main/java/com/relogiclabs/jschema/exception/FunctionArgumentTypeException.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import static com.relogiclabs.jschema.message.MessageFormatter.formatForSchema;
77

88
public class FunctionArgumentTypeException extends ArgumentTypeException {
9-
FunctionArgumentTypeException(ArgumentTypeException cause) {
10-
super(cause.getCode(), cause.getMessage(), cause);
11-
setParameter(cause.getParameter());
9+
public FunctionArgumentTypeException(String code, String message) {
10+
super(code, message);
1211
}
1312

1413
public FunctionArgumentTypeException(ErrorDetail detail, Throwable cause) {

src/main/java/com/relogiclabs/jschema/exception/FunctionArgumentValueException.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
import static com.relogiclabs.jschema.message.MessageFormatter.formatForSchema;
77

88
public class FunctionArgumentValueException extends ArgumentValueException {
9-
FunctionArgumentValueException(ArgumentValueException cause) {
10-
super(cause.getCode(), cause.getMessage(), cause);
11-
setParameter(cause.getParameter());
12-
}
13-
149
public FunctionArgumentValueException(ErrorDetail detail) {
1510
super(detail, null);
1611
}

src/main/java/com/relogiclabs/jschema/exception/InvalidArgumentException.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,22 @@
22

33
import com.relogiclabs.jschema.message.ErrorDetail;
44
import com.relogiclabs.jschema.type.EValue;
5-
import lombok.Getter;
6-
import lombok.Setter;
75

8-
@Getter @Setter
9-
public abstract class InvalidArgumentException extends InvocationRuntimeException {
10-
private String parameter;
11-
12-
public InvalidArgumentException(String message) {
13-
super(message);
14-
}
15-
16-
public InvalidArgumentException(String code, String message, Throwable cause) {
17-
super(code, message, cause);
6+
public class InvalidArgumentException extends InvocationRuntimeException {
7+
public InvalidArgumentException(String code, String message) {
8+
super(code, message);
189
}
1910

2011
public InvalidArgumentException(ErrorDetail detail, Throwable cause) {
2112
super(detail, cause);
2213
}
2314

24-
public void setContext(String code, String parameter) {
25-
setCode(code);
26-
this.parameter = parameter;
27-
}
28-
29-
public abstract InvalidArgumentException failWithFunctionException();
30-
public abstract InvalidArgumentException failWithMethodException(EValue self);
31-
3215
protected String formatMethodMessage(EValue self) {
33-
return getMessage() + " for parameter '" + parameter
34-
+ "' in method '" + getSubject() + "' of " + self.getType();
16+
return addNative(getMessage() + " of method '" + getSubject()
17+
+ "' in " + self.getType());
3518
}
3619

3720
protected String formatFunctionMessage() {
38-
return getMessage() + " for parameter '" + parameter
39-
+ "' of function '" + getSubject() + "'";
21+
return addNative(getMessage() + " of function '" + getSubject() + "'");
4022
}
4123
}

0 commit comments

Comments
 (0)