-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from SpineEventEngine/generate-type-url-for-j…
…s-messages Generate a method providing `TypeUrl` for Protobuf types compiled to JS
- Loading branch information
Showing
107 changed files
with
3,034 additions
and
1,109 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
base/src/main/java/io/spine/code/generate/GeneratedBySpine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2018, TeamDev. All rights reserved. | ||
* | ||
* Redistribution and use in source and/or binary forms, with or without | ||
* modification, must retain the above copyright notice and the following | ||
* disclaimer. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package io.spine.code.generate; | ||
|
||
/** | ||
* Provides fields for {@link javax.annotation.Generated Generated} annotation used by | ||
* code generation tools for marking source code generated by Spine Model Compiler. | ||
*/ | ||
public final class GeneratedBySpine { | ||
|
||
private static final GeneratedBySpine INSTANCE = new GeneratedBySpine(); | ||
|
||
/** Prevents instantiation from outside. */ | ||
private GeneratedBySpine() { | ||
} | ||
|
||
public static GeneratedBySpine instance() { | ||
return INSTANCE; | ||
} | ||
|
||
/** Obtains the name for annotation field. */ | ||
@SuppressWarnings("DuplicateStringLiteralInspection") | ||
// Each occurrence has a different semantics. | ||
public String getFieldName() { | ||
return "value"; | ||
} | ||
|
||
/** Obtains the code block for the annotation value. */ | ||
public String getCodeBlock() { | ||
return "\"by Spine Model Compiler\""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
base/src/main/java/io/spine/code/generate/IndentLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright 2018, TeamDev. All rights reserved. | ||
* | ||
* Redistribution and use in source and/or binary forms, with or without | ||
* modification, must retain the above copyright notice and the following | ||
* disclaimer. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package io.spine.code.generate; | ||
|
||
import java.util.Objects; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
/** | ||
* An indent level, which determines a number of {@linkplain Indent indents} to align code with. | ||
* | ||
* <p>The value cannot be negative. | ||
*/ | ||
public class IndentLevel { | ||
|
||
private static final IndentLevel ZERO = of(0); | ||
|
||
private final int value; | ||
|
||
private IndentLevel(int value) { | ||
checkArgument(value >= 0, "An indent level cannot be negative."); | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* Creates an indent level with the specified value. | ||
*/ | ||
public static IndentLevel of(int value) { | ||
return new IndentLevel(value); | ||
} | ||
|
||
/** | ||
* Creates the indent level of zero. | ||
*/ | ||
public static IndentLevel zero() { | ||
return ZERO; | ||
} | ||
|
||
/** | ||
* Obtains the value of the level. | ||
*/ | ||
public int value() { | ||
return value; | ||
} | ||
|
||
/** | ||
* Obtains the indent level by incrementing this value. | ||
*/ | ||
public IndentLevel incremented() { | ||
return of(value + 1); | ||
} | ||
|
||
/** | ||
* Obtains the indent level by decrementing this value. | ||
*/ | ||
public IndentLevel decremented() { | ||
return of(value - 1); | ||
} | ||
|
||
/** | ||
* Obtains the total indent for the level. | ||
* | ||
* @param indentPerLevel | ||
* the indent per a level | ||
*/ | ||
public Indent totalIndent(Indent indentPerLevel) { | ||
int totalSize = indentPerLevel.getSize() * value; | ||
return Indent.of(totalSize); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof IndentLevel)) { | ||
return false; | ||
} | ||
IndentLevel level = (IndentLevel) o; | ||
return value == level.value; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2018, TeamDev. All rights reserved. | ||
* | ||
* Redistribution and use in source and/or binary forms, with or without | ||
* modification, must retain the above copyright notice and the following | ||
* disclaimer. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package io.spine.code.js; | ||
|
||
import java.util.Objects; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* A reference to a method of a Protobuf type. | ||
* | ||
* <p>The reference allows to identify a method in code | ||
* since it includes a type name and a method name. | ||
*/ | ||
public final class MethodReference { | ||
|
||
/** The type declaring the method. */ | ||
private final TypeName typeName; | ||
/** The name of the method. */ | ||
private final String methodName; | ||
/** Whether the method is defined on the prototype or not. */ | ||
private final boolean onPrototype; | ||
|
||
private MethodReference(TypeName typeName, String methodName, boolean onPrototype) { | ||
checkNotNull(typeName); | ||
checkNotNull(methodName); | ||
this.typeName = typeName; | ||
this.methodName = methodName; | ||
this.onPrototype = onPrototype; | ||
} | ||
|
||
/** | ||
* Obtains the reference to the instance method of the specified type. | ||
*/ | ||
public static MethodReference onType(TypeName typeName, String methodName) { | ||
return new MethodReference(typeName, methodName, false); | ||
} | ||
|
||
/** | ||
* Obtains the reference to the static method of the specified type. | ||
*/ | ||
public static MethodReference onPrototype(TypeName typeName, String methodName) { | ||
return new MethodReference(typeName, methodName, true); | ||
} | ||
|
||
/** | ||
* Obtains the value of the reference. | ||
*/ | ||
public String value() { | ||
String delimiter = onPrototype | ||
? ".prototype." | ||
: "."; | ||
return typeName + delimiter + methodName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof MethodReference)) { | ||
return false; | ||
} | ||
MethodReference reference = (MethodReference) o; | ||
return onPrototype == reference.onPrototype && | ||
typeName.equals(reference.typeName) && | ||
methodName.equals(reference.methodName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(typeName, methodName, onPrototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.