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
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+
}
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
}
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

+1-5
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
}
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
}
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+
}
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

+2-3
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

-5
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

+6-24
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
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
public class InvalidContextException extends InvocationRuntimeException {
1313
private Token mainToken;
1414

15+
public InvalidContextException(String code, String message) {
16+
super(code, message);
17+
}
18+
1519
public InvalidContextException(String code, String message, Token mainToken) {
1620
super(code, message);
1721
this.mainToken = mainToken;
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
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 InvalidFunctionException extends MultilevelRuntimeException {
9+
public InvalidFunctionException(String code, String message) {
10+
super(code, message);
11+
}
412

5-
public class InvalidFunctionException extends BaseRuntimeException {
613
public InvalidFunctionException(ErrorDetail detail) {
714
super(detail);
815
}
16+
17+
public InvalidFunctionException(ErrorDetail detail, Throwable cause) {
18+
super(detail, cause);
19+
}
20+
21+
@Override
22+
public RuntimeException translate(Token token) {
23+
if(isHighLevel()) return this;
24+
return new InvalidFunctionException(formatForSchema(getCode(),
25+
getMessage(), token), this);
26+
}
927
}
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;
45

5-
public class InvalidImportException extends BaseRuntimeException {
6-
public InvalidImportException(ErrorDetail detail) {
7-
super(detail);
6+
import static com.relogiclabs.jschema.message.MessageFormatter.formatForSchema;
7+
8+
public class InvalidImportException extends MultilevelRuntimeException {
9+
public InvalidImportException(String code, String message) {
10+
super(code, message);
11+
}
12+
13+
public InvalidImportException(ErrorDetail detail, Throwable cause) {
14+
super(detail, cause);
15+
}
16+
17+
@Override
18+
public RuntimeException translate(Token token) {
19+
if(isHighLevel()) return this;
20+
return new InvalidImportException(formatForSchema(getCode(),
21+
getMessage(), token), this);
822
}
923
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
package com.relogiclabs.jschema.exception;
22

33
import com.relogiclabs.jschema.message.ErrorDetail;
4+
import org.antlr.v4.runtime.Token;
45

5-
public class InvalidReturnTypeException extends BaseRuntimeException {
6+
import static com.relogiclabs.jschema.message.MessageFormatter.formatForSchema;
7+
8+
public class InvalidReturnTypeException extends InvalidFunctionException {
69
public InvalidReturnTypeException(String code, String message) {
710
super(code, message);
811
}
912

1013
public InvalidReturnTypeException(ErrorDetail detail) {
1114
super(detail);
1215
}
16+
17+
public InvalidReturnTypeException(ErrorDetail detail, Throwable cause) {
18+
super(detail, cause);
19+
}
20+
21+
@Override
22+
public RuntimeException translate(Token token) {
23+
if(isHighLevel()) return this;
24+
return new InvalidReturnTypeException(formatForSchema(getCode(),
25+
getMessage(), token), this);
26+
}
1327
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
import com.relogiclabs.jschema.message.ErrorDetail;
4+
import com.relogiclabs.jschema.type.EValue;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import org.antlr.v4.runtime.Token;
8+
9+
import static com.relogiclabs.jschema.message.MessageFormatter.formatForSchema;
10+
11+
@Getter @Setter
12+
public class InvalidSelfStateException extends InvocationRuntimeException {
13+
private EValue self;
14+
15+
public InvalidSelfStateException(String code, String message) {
16+
super(code, message);
17+
}
18+
19+
public InvalidSelfStateException(ErrorDetail detail, Throwable cause) {
20+
super(detail, cause);
21+
}
22+
23+
@Override
24+
public RuntimeException translate(Token token) {
25+
if(isHighLevel() || getSubject() == null) return this;
26+
var message = addSelf(getMessage() + " of method '" + getSubject() + "'", self);
27+
return new InvalidSelfStateException(formatForSchema(getCode(),
28+
addNative(message), token), this);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
package com.relogiclabs.jschema.exception;
22

33
import com.relogiclabs.jschema.message.ErrorDetail;
4+
import com.relogiclabs.jschema.type.EValue;
45
import lombok.Getter;
56
import lombok.Setter;
67
import org.antlr.v4.runtime.Token;
78

9+
import java.lang.reflect.Method;
10+
11+
import static com.relogiclabs.jschema.internal.util.ReflectionHelper.getSignature;
812
import static com.relogiclabs.jschema.message.MessageFormatter.formatForSchema;
913

1014
@Getter @Setter
1115
public class InvocationRuntimeException extends MultilevelRuntimeException {
1216
private String subject;
13-
14-
public InvocationRuntimeException(String message) {
15-
super(message);
16-
}
17+
private Method method;
1718

1819
public InvocationRuntimeException(String code, String message) {
1920
super(code, message);
2021
}
2122

22-
public InvocationRuntimeException(String code, String message, Throwable cause) {
23-
super(code, message, cause);
24-
}
25-
2623
public InvocationRuntimeException(ErrorDetail detail, Throwable cause) {
2724
super(detail, cause);
2825
}
@@ -31,6 +28,16 @@ public InvocationRuntimeException(ErrorDetail detail, Throwable cause) {
3128
public RuntimeException translate(Token token) {
3229
if(isHighLevel() || subject == null) return this;
3330
return new InvocationRuntimeException(formatForSchema(getCode(),
34-
getMessage() + " '" + subject + "'", token), this);
31+
addNative(getMessage() + " '" + subject + "'"), token), this);
32+
}
33+
34+
protected String addNative(String message) {
35+
if(method == null) return message;
36+
return message + " with native: " + getSignature(method);
37+
}
38+
39+
protected static String addSelf(String message, EValue self) {
40+
if(self == null) return message;
41+
return message + " in " + self.getType();
3542
}
3643
}

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
public class MethodArgumentTypeException extends ArgumentTypeException {
1313
private EValue self;
1414

15-
MethodArgumentTypeException(EValue self, ArgumentTypeException cause) {
16-
super(cause.getCode(), cause.getMessage(), cause);
17-
setParameter(cause.getParameter());
18-
this.self = self;
15+
public MethodArgumentTypeException(String code, String message) {
16+
super(code, message);
1917
}
2018

2119
public MethodArgumentTypeException(ErrorDetail detail, Throwable cause) {

0 commit comments

Comments
 (0)