Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/src/main/java/com/readdle/codegen/JavaSwiftProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ public SourceVersion getSupportedSourceVersion() {

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
try {
return processImpl(annotations, roundEnv);
}
catch(SwiftMappingException exc) {
exc.printStackTrace();
error(exc.getElement(), exc.getMessage());
return true;
}
}

private boolean processImpl(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Filer filer = processingEnv.getFiler();
messager.printMessage(Diagnostic.Kind.NOTE, "Start SwiftJava code generation:");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public class SwiftCallbackFuncDescriptor {
int paramEnd = funcFullName.indexOf(")");

if (paramStart <= 0 || paramEnd <= 0 || paramEnd <= paramStart) {
throw new IllegalArgumentException("Wrong func name");
throw new SwiftMappingException("Wrong func name", executableElement);
}

this.swiftMethodName = funcFullName.substring(0, paramStart);
String arguments = funcFullName.substring(paramStart + 1, paramEnd);
String[] paramNames = arguments.split(":");

if (paramNames.length != params.size()) {
throw new IllegalArgumentException("Wrong count of arguments in func name");
throw new SwiftMappingException("Wrong count of arguments in func name", executableElement);
}

this.paramNames = Arrays.asList(paramNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ class SwiftDelegateDescriptor {
ExecutableElement executableElement = (ExecutableElement) element;
if (executableElement.getSimpleName().toString().equals("release")) {
if (!executableElement.getModifiers().contains(Modifier.NATIVE)) {
throw new IllegalArgumentException(String.format("%s is not native method",
executableElement.getSimpleName()));
throw new SwiftMappingException(String.format("%s is not native method",
executableElement.getSimpleName()), executableElement);
}
releaseExecutableElement = executableElement;
}
if (executableElement.getSimpleName().toString().equals("init")) {
if (!executableElement.getModifiers().contains(Modifier.NATIVE)) {
throw new IllegalArgumentException(String.format("%s is not native method",
executableElement.getSimpleName()));
throw new SwiftMappingException(String.format("%s is not native method",
executableElement.getSimpleName()), executableElement);
}
initExecutableElement = executableElement;
}
Expand Down Expand Up @@ -147,8 +147,9 @@ class SwiftDelegateDescriptor {
if (element.getKind() == ElementKind.METHOD && element.getAnnotation(SwiftCallbackFunc.class) != null) {
ExecutableElement executableElement = (ExecutableElement) element;
if (executableElement.getModifiers().contains(Modifier.NATIVE)) {
throw new IllegalArgumentException(String.format("%s is native method. Only java methods can be annotated with @%s",
executableElement.getSimpleName(), SwiftCallbackFunc.class.getSimpleName()));
String message = String.format("%s is native method. Only java methods can be annotated with @%s",
executableElement.getSimpleName(), SwiftCallbackFunc.class.getSimpleName());
throw new SwiftMappingException(message, executableElement);
}

callbackFunctions.add(new SwiftCallbackFuncDescriptor(executableElement));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SwiftFuncDescriptor implements JavaSwiftProcessor.WritableElement {
int paramEnd = funcFullName.indexOf(")");

if (paramStart <= 0 || paramEnd <= 0 || paramEnd <= paramStart) {
throw new IllegalArgumentException("Wrong func name");
throw new SwiftMappingException("Wrong func name", executableElement);
}

this.swiftMethodName = funcFullName.substring(0, paramStart);
Expand All @@ -60,7 +60,7 @@ class SwiftFuncDescriptor implements JavaSwiftProcessor.WritableElement {
String[] paramNames = arguments.split(":");

if (paramNames.length != params.size()) {
throw new IllegalArgumentException("Wrong count of arguments in func name");
throw new SwiftMappingException("Wrong count of arguments in func name", executableElement);
}

for (String paramName : paramNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class SwiftGetterDescriptor implements JavaSwiftProcessor.WritableElement {
this.isReturnTypeOptional = JavaSwiftProcessor.isNullable(executableElement);

if (executableElement.getThrownTypes().size() != 0) {
throw new IllegalArgumentException("Getter can't throw");
throw new SwiftMappingException("Getter can't throw", executableElement);
}

if (executableElement.getParameters().size() != 0) {
throw new IllegalArgumentException("Getter can't has parameters");
throw new SwiftMappingException("Getter can't has parameters", executableElement);
}

if (getterAnnotation != null && !getterAnnotation.value().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.readdle.codegen;

import javax.lang.model.element.Element;

public class SwiftMappingException extends RuntimeException {
private final Element element;

public SwiftMappingException(String message, Element element) {
super(message);
this.element = element;
}

public SwiftMappingException(String message, Element element, Throwable parent) {
super(message, parent);
this.element = element;
}

public Element getElement() {
return element;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class SwiftReferenceDescriptor {
ExecutableElement executableElement = (ExecutableElement) element;
if (executableElement.getSimpleName().toString().equals("release")) {
if (!executableElement.getModifiers().contains(Modifier.NATIVE)) {
throw new IllegalArgumentException(String.format("%s is not native method",
executableElement.getSimpleName()));
String message = String.format("%s is not native method",
executableElement.getSimpleName());
throw new SwiftMappingException(message, executableElement);
}
releaseExecutableElement = executableElement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class SwiftSetterDescriptor implements JavaSwiftProcessor.WritableElement {
this.isStatic = executableElement.getModifiers().contains(Modifier.STATIC);

if (executableElement.getThrownTypes().size() != 0) {
throw new IllegalArgumentException("Setter can't throw");
throw new SwiftMappingException("Setter can't throw", executableElement);
}

if (executableElement.getParameters().size() != 1) {
throw new IllegalArgumentException("Setter should have exactly 1 parameter");
throw new SwiftMappingException("Setter should have exactly 1 parameter", executableElement);
}

param = new SwiftParamDescriptor(executableElement.getParameters().get(0));
Expand Down