{
27 |
28 | private final ExternalParcelRepository externalParcelRepository;
29 |
30 | public ParcelMatcher(ExternalParcelRepository externalParcelRepository) {
31 | this.externalParcelRepository = externalParcelRepository;
32 | }
33 |
34 | @Override
35 | public boolean matches(ASTType type) {
36 | return (!(type instanceof ASTArrayType)) && type.isAnnotated(org.parceler.Parcel.class) || externalParcelRepository.contains(type);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/parceler/src/main/java/org/parceler/internal/matcher/RemoterMatcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal.matcher;
17 |
18 |
19 | import org.androidtransfuse.adapter.ASTStringType;
20 | import org.androidtransfuse.adapter.ASTType;
21 | import org.androidtransfuse.util.matcher.Matcher;
22 |
23 | /**
24 | * Matches a @Remoter inteface
25 | *
26 | * @author js
27 | */
28 | public class RemoterMatcher implements Matcher {
29 |
30 | private static final ASTType REMOTER = new ASTStringType("remoter.annotations.Remoter");
31 |
32 | @Override
33 | public boolean matches(ASTType input) {
34 | return input.isInterface() && input.isAnnotated(REMOTER);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/parceler/src/main/resources/META-INF/gradle/incremental.annotation.processors:
--------------------------------------------------------------------------------
1 | org.parceler.ParcelAnnotationProcessor,isolating
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/CodeGenerationUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import com.sun.codemodel.JCodeModel;
19 |
20 | import javax.inject.Inject;
21 | import java.io.IOException;
22 | import java.util.Map;
23 |
24 | /**
25 | * @author John Ericksen
26 | */
27 | public class CodeGenerationUtil {
28 |
29 | private final JCodeModel codeModel;
30 | private final StringCodeWriter stringCodeWriter;
31 | private final MemoryClassLoader classLoader;
32 |
33 | @Inject
34 | public CodeGenerationUtil(JCodeModel codeModel, StringCodeWriter stringCodeWriter, MemoryClassLoader classLoader) {
35 | this.codeModel = codeModel;
36 | this.stringCodeWriter = stringCodeWriter;
37 | this.classLoader = classLoader;
38 | }
39 |
40 | public ClassLoader build() throws IOException {
41 | return build(false);
42 | }
43 |
44 | public ClassLoader build(boolean print) throws IOException {
45 | codeModel.build(stringCodeWriter);
46 |
47 | classLoader.add(stringCodeWriter.getOutput());
48 |
49 | if (print) {
50 | for (Map.Entry codeEntry : stringCodeWriter.getOutput().entrySet()) {
51 | System.out.println("Key: " + codeEntry.getKey());
52 | System.out.println(codeEntry.getValue());
53 | }
54 | }
55 |
56 | return classLoader;
57 | }
58 | }
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/ErrorCheckingMessager.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import javax.annotation.processing.Messager;
19 | import javax.lang.model.element.AnnotationMirror;
20 | import javax.lang.model.element.AnnotationValue;
21 | import javax.lang.model.element.Element;
22 | import javax.tools.Diagnostic;
23 |
24 | /**
25 | * @author John Ericksen
26 | */
27 | public class ErrorCheckingMessager implements Messager {
28 |
29 | private boolean errored = false;
30 | private String message = null;
31 |
32 | @Override
33 | public void printMessage(Diagnostic.Kind kind, CharSequence message) {
34 | checkError(kind, message.toString());
35 | }
36 |
37 | @Override
38 | public void printMessage(Diagnostic.Kind kind, CharSequence message, Element element) {
39 | checkError(kind, message.toString());
40 | }
41 |
42 | @Override
43 | public void printMessage(Diagnostic.Kind kind, CharSequence message, Element element, AnnotationMirror annotationMirror) {
44 | checkError(kind, message.toString());
45 | }
46 |
47 | @Override
48 | public void printMessage(Diagnostic.Kind kind, CharSequence message, Element element, AnnotationMirror annotationMirror, AnnotationValue annotationValue) {
49 | checkError(kind, message.toString());
50 | }
51 |
52 | private void checkError(Diagnostic.Kind kind, String message){
53 | if(Diagnostic.Kind.ERROR.equals(kind)){
54 | errored = true;
55 | this.message = message;
56 | }
57 | }
58 |
59 | public boolean isErrored(){
60 | return errored;
61 | }
62 |
63 | public String getMessage() {
64 | return message;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/JavaUtilLogger.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import org.androidtransfuse.util.Logger;
19 |
20 | /**
21 | * @author John Ericksen
22 | */
23 | public class JavaUtilLogger implements Logger {
24 |
25 | private final boolean debug;
26 | private final java.util.logging.Logger logger;
27 |
28 | public JavaUtilLogger(Object targetInstance, boolean debug) {
29 | this.logger = java.util.logging.Logger.getLogger(targetInstance.getClass().getCanonicalName());
30 | this.debug = debug;
31 | }
32 |
33 | @Override
34 | public void info(String value) {
35 | logger.info(value);
36 | }
37 |
38 | @Override
39 | public void warning(String value) {
40 | logger.warning(value);
41 | }
42 |
43 | @Override
44 | public void error(String value) {
45 | logger.severe(value);
46 | }
47 |
48 | @Override
49 | public void error(String s, Throwable e) {
50 | logger.throwing(s, e.getMessage(), e);
51 | }
52 |
53 | @Override
54 | public void debug(String value) {
55 | if(debug) {
56 | info(value);
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/MemoryClassLoader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import javax.tools.JavaCompiler;
19 | import javax.tools.JavaFileObject;
20 | import javax.tools.ToolProvider;
21 | import java.util.ArrayList;
22 | import java.util.Collections;
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | /**
27 | * @author John Ericksen
28 | */
29 | public class MemoryClassLoader extends ClassLoader {
30 |
31 | private final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
32 | private final MemoryFileManager manager = new MemoryFileManager(this.compiler);
33 |
34 | public MemoryClassLoader(){
35 | //default ClassLoader backing
36 | super(MemoryClassLoader.class.getClassLoader());
37 | }
38 |
39 | public void add(String classname, String fileContent) {
40 | add(Collections.singletonMap(classname, fileContent));
41 | }
42 |
43 | public void add(Map map) {
44 | List list = new ArrayList();
45 | for (Map.Entry entry : map.entrySet()) {
46 | list.add(new Source(entry.getKey(), JavaFileObject.Kind.SOURCE, entry.getValue()));
47 | }
48 | this.compiler.getTask(null, this.manager, null, null, null, list).call();
49 | }
50 |
51 | @Override
52 | protected Class> findClass(String name) throws ClassNotFoundException {
53 | synchronized (this.manager) {
54 | Output mc = this.manager.map.remove(name);
55 | if (mc != null) {
56 | byte[] array = mc.toByteArray();
57 | return defineClass(name, array, 0, array.length);
58 | }
59 | }
60 | return super.findClass(name);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/MemoryFileManager.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import javax.tools.*;
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | class MemoryFileManager extends ForwardingJavaFileManager {
23 | public final Map map = new HashMap();
24 |
25 | MemoryFileManager(JavaCompiler compiler) {
26 | super(compiler.getStandardFileManager(null, null, null));
27 | }
28 |
29 | @Override
30 | public Output getJavaFileForOutput
31 | (Location location, String name, JavaFileObject.Kind kind, FileObject source) {
32 | Output mc = new Output(name, kind);
33 | this.map.put(name, mc);
34 | return mc;
35 | }
36 | }
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/NoOpFiler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import javax.annotation.processing.Filer;
19 | import javax.lang.model.element.Element;
20 | import javax.tools.FileObject;
21 | import javax.tools.JavaFileManager;
22 | import javax.tools.JavaFileObject;
23 | import java.io.IOException;
24 |
25 | /**
26 | * Empty filer for testing placeholder purposes.
27 | *
28 | * @author John Ericksen
29 | */
30 | public class NoOpFiler implements Filer {
31 | @Override
32 | public JavaFileObject createSourceFile(CharSequence charSequence, Element... elements) throws IOException {
33 | return null;
34 | }
35 |
36 | @Override
37 | public JavaFileObject createClassFile(CharSequence charSequence, Element... elements) throws IOException {
38 | return null;
39 | }
40 |
41 | @Override
42 | public FileObject createResource(JavaFileManager.Location location, CharSequence charSequence, CharSequence charSequence1, Element... elements) throws IOException {
43 | return null;
44 | }
45 |
46 | @Override
47 | public FileObject getResource(JavaFileManager.Location location, CharSequence charSequence, CharSequence charSequence1) throws IOException {
48 | return null;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/Output.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import javax.tools.SimpleJavaFileObject;
19 | import java.io.ByteArrayOutputStream;
20 | import java.net.URI;
21 |
22 | class Output extends SimpleJavaFileObject {
23 | private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
24 |
25 | Output(String name, Kind kind) {
26 | super(URI.create("memo:///" + name.replace('.', '/') + kind.extension), kind);
27 | }
28 |
29 | byte[] toByteArray() {
30 | return this.outputStream.toByteArray();
31 | }
32 |
33 | @Override
34 | public ByteArrayOutputStream openOutputStream() {
35 | return this.outputStream;
36 | }
37 | }
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/ParcelSecondTarget.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import org.apache.commons.lang.builder.EqualsBuilder;
19 | import org.apache.commons.lang.builder.HashCodeBuilder;
20 | import org.parceler.Parcel;
21 |
22 | /**
23 | * @author John Ericksen
24 | */
25 | @Parcel(Parcel.Serialization.BEAN)
26 | public class ParcelSecondTarget {
27 |
28 | private String value;
29 |
30 | public String getValue() {
31 | return value;
32 | }
33 |
34 | public void setValue(String value) {
35 | this.value = value;
36 | }
37 |
38 | @Override
39 | public boolean equals(Object rhs) {
40 | return EqualsBuilder.reflectionEquals(this, rhs);
41 | }
42 |
43 | @Override
44 | public int hashCode() {
45 | return HashCodeBuilder.reflectionHashCode(this);
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "ParcelSecondTarget{" +
51 | "value='" + value + '\'' +
52 | '}';
53 | }
54 | }
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/ParcelTarget.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import org.apache.commons.lang.builder.EqualsBuilder;
19 | import org.apache.commons.lang.builder.HashCodeBuilder;
20 | import org.parceler.Parcel;
21 |
22 | /**
23 | * @author John Ericksen
24 | */
25 | @Parcel(Parcel.Serialization.BEAN)
26 | public class ParcelTarget {
27 | private String stringValue;
28 | private Double doubleValue;
29 | private ParcelSecondTarget secondTarget;
30 |
31 | public String getStringValue() {
32 | return stringValue;
33 | }
34 |
35 | public void setStringValue(String stringValue) {
36 | this.stringValue = stringValue;
37 | }
38 |
39 | public Double getDoubleValue() {
40 | return doubleValue;
41 | }
42 |
43 | public void setDoubleValue(Double doubleValue) {
44 | this.doubleValue = doubleValue;
45 | }
46 |
47 | public ParcelSecondTarget getSecondTarget() {
48 | return secondTarget;
49 | }
50 |
51 | public void setSecondTarget(ParcelSecondTarget secondTarget) {
52 | this.secondTarget = secondTarget;
53 | }
54 |
55 | @Override
56 | public boolean equals(Object rhs) {
57 | return EqualsBuilder.reflectionEquals(this, rhs);
58 | }
59 |
60 | @Override
61 | public int hashCode() {
62 | return HashCodeBuilder.reflectionHashCode(this);
63 | }
64 |
65 | @Override
66 | public String toString() {
67 | return "ParcelTarget{" +
68 | "stringValue='" + stringValue + '\'' +
69 | ", doubleValue=" + doubleValue +
70 | ", secondTarget=" + secondTarget +
71 | '}';
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/Source.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import javax.tools.SimpleJavaFileObject;
19 | import java.net.URI;
20 |
21 | class Source extends SimpleJavaFileObject {
22 | private final String content;
23 |
24 | Source(String name, Kind kind, String content) {
25 | super(URI.create("memo:///" + name.replace('.', '/') + kind.extension), kind);
26 | this.content = content;
27 | }
28 |
29 | @Override
30 | public CharSequence getCharContent(boolean ignore) {
31 | return this.content;
32 | }
33 | }
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/StringWriterConverter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import android.os.Parcel;
19 | import org.parceler.ParcelConverter;
20 |
21 | /**
22 | * @author John Ericksen
23 | */
24 | public class StringWriterConverter implements ParcelConverter {
25 |
26 | @Override
27 | public void toParcel(String input, Parcel parcel) {
28 | parcel.writeString(input);
29 | }
30 |
31 | @Override
32 | public String fromParcel(Parcel parcel) {
33 | return parcel.readString();
34 | }
35 | }
--------------------------------------------------------------------------------
/parceler/src/test/java/org/parceler/internal/Target.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2011-2015 John Ericksen
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.parceler.internal;
17 |
18 | import org.apache.commons.lang.builder.EqualsBuilder;
19 | import org.apache.commons.lang.builder.HashCodeBuilder;
20 |
21 | /**
22 | * @author John Ericksen
23 | */
24 | public class Target{
25 | public String value;
26 |
27 | public Target(){}
28 |
29 | public Target(String value){
30 | this.value = value;
31 | }
32 |
33 | public String getValue() {
34 | return value;
35 | }
36 |
37 | public void setValue(String value) {
38 | this.value = value;
39 | }
40 |
41 | @Override
42 | public boolean equals(Object rhs) {
43 | return EqualsBuilder.reflectionEquals(this, rhs);
44 | }
45 |
46 | @Override
47 | public int hashCode() {
48 | return HashCodeBuilder.reflectionHashCode(this);
49 | }
50 | }
--------------------------------------------------------------------------------