-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate idl reader code from parser and add tests
- Loading branch information
Showing
18 changed files
with
350 additions
and
40 deletions.
There are no files selected for viewing
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,80 @@ | ||
apply plugin: "java" | ||
apply plugin: 'signing' | ||
|
||
def module_name = "IDLReader" | ||
|
||
dependencies { | ||
testImplementation "junit:junit:$project.jUnitVersion" | ||
} | ||
|
||
//task fromClasses(type: Jar) { | ||
// from(sourceSets.main.output) { | ||
// } | ||
//} | ||
// | ||
//task javadocJar(type: Jar) { | ||
// archiveClassifier.set("javadoc") | ||
// from javadoc | ||
//} | ||
// | ||
//task sourcesJar(type: Jar) { | ||
// archiveClassifier.set("sources") | ||
// from sourceSets.main.allSource | ||
//} | ||
// | ||
//javadoc { | ||
// options.encoding = 'UTF-8' | ||
// options.addStringOption('Xdoclint:none', '-quiet') | ||
//} | ||
// | ||
//publishing { | ||
// publications { | ||
// maven(MavenPublication) { | ||
// version project.jParserVersion + project.jParserType | ||
// project.version = project.jParserVersion + project.jParserType | ||
// artifactId module_name | ||
// artifact fromClasses | ||
// artifact javadocJar | ||
// artifact sourcesJar | ||
// | ||
// pom { | ||
// name = "jParser" | ||
// description = "Java code parser" | ||
// url = "http://github.com/xpenatan/jParser" | ||
// developers { | ||
// developer { | ||
// id = "Xpe" | ||
// name = "Natan" | ||
// } | ||
// } | ||
// scm { | ||
// connection = "scm:git:git://github.com/xpenatan/jParser.git" | ||
// developerConnection = "scm:git:ssh://github.com/xpenatan/jParser.git" | ||
// url = "http://github.com/xpenatan/jParser/tree/master" | ||
// } | ||
// licenses { | ||
// license { | ||
// name = "The Apache License, Version 2.0" | ||
// url = "https://www.apache.org/licenses/LICENSE-2.0.txt" | ||
// } | ||
// } | ||
// withXml { | ||
// def dependenciesNode = asNode().appendNode('dependencies') | ||
// configurations.implementation.allDependencies.each { | ||
// def dependencyNode = dependenciesNode.appendNode('dependency') | ||
// dependencyNode.appendNode('groupId', it.group) | ||
// dependencyNode.appendNode('artifactId', it.name) | ||
// dependencyNode.appendNode('version', it.version) | ||
// } | ||
// } | ||
// } | ||
// } | ||
// } | ||
//} | ||
// | ||
//signing { | ||
// def signingKey = System.getenv("signingKey") | ||
// def signingPassword = System.getenv("signingPassword") | ||
// useInMemoryPgpKeys(signingKey, signingPassword) | ||
// sign publishing.publications.maven | ||
//} |
2 changes: 1 addition & 1 deletion
2
...enatan/jparser/core/idl/IDLAttribute.java → ...ub.xpenatan.jparser.idl/IDLAttribute.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.github.xpenatan.jparser.core.idl; | ||
package com.github.xpenatan.jparser.idl; | ||
|
||
/** | ||
* @author xpenatan | ||
|
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
75 changes: 75 additions & 0 deletions
75
IDLReader/src/main/java/com.github.xpenatan.jparser.idl/IDLClassHeader.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,75 @@ | ||
package com.github.xpenatan.jparser.idl; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* @author xpenatan | ||
*/ | ||
public class IDLClassHeader { | ||
public final IDLClass idlClass; | ||
|
||
public String headerLine; | ||
|
||
public String prefixName = ""; | ||
public String jsImplementation; | ||
public boolean isNoDelete; | ||
|
||
public ArrayList<String> options = new ArrayList<>(); | ||
|
||
public IDLClassHeader(String headerLine, IDLClass idlClass) { | ||
this.headerLine = headerLine; | ||
this.idlClass = idlClass; | ||
|
||
if(!headerLine.isEmpty()) { | ||
if(headerLine.startsWith("[") && headerLine.endsWith("]")) { | ||
headerLine = headerLine.replace("[", "").replace("]", ""); | ||
if(headerLine.contains(",")) { | ||
String[] commaSplit = headerLine.split(","); | ||
for(String option : commaSplit) { | ||
options.add(option.trim()); | ||
} | ||
} | ||
else { | ||
options.add(headerLine); | ||
} | ||
|
||
setupPrefixName(); | ||
setupJSImplementation(); | ||
setupNoDelete(); | ||
} | ||
else { | ||
throw new RuntimeException("Wrong header: " + headerLine); | ||
} | ||
} | ||
} | ||
|
||
public void setupPrefixName() { | ||
for(String option : options) { | ||
if(option.startsWith("Prefix")) { | ||
String[] split = option.split("="); | ||
prefixName = split[1].replace("\"", "").trim(); | ||
} | ||
} | ||
} | ||
|
||
private void setupJSImplementation() { | ||
for(String option : options) { | ||
if(option.startsWith("JSImplementation")) { | ||
String[] split = option.split("="); | ||
jsImplementation = split[1].replace("\"", "").trim(); | ||
} | ||
} | ||
} | ||
|
||
private void setupNoDelete() { | ||
for(String option : options) { | ||
if(option.equals("NoDelete")) { | ||
isNoDelete = true; | ||
} | ||
} | ||
} | ||
|
||
public static boolean isLineHeader(String line) { | ||
return line.startsWith("[Prefix") || line.startsWith("[JSImplementation") || line.startsWith("[NoDelete"); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...atan/jparser/core/idl/IDLConstructor.java → ....xpenatan.jparser.idl/IDLConstructor.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
2 changes: 1 addition & 1 deletion
2
...ub/xpenatan/jparser/core/idl/IDLFile.java → ....github.xpenatan.jparser.idl/IDLFile.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
2 changes: 1 addition & 1 deletion
2
.../xpenatan/jparser/core/idl/IDLMethod.java → ...ithub.xpenatan.jparser.idl/IDLMethod.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
2 changes: 1 addition & 1 deletion
2
...enatan/jparser/core/idl/IDLParameter.java → ...ub.xpenatan.jparser.idl/IDLParameter.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
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
95 changes: 95 additions & 0 deletions
95
IDLReader/src/test/java/com/github/xpenatan/jparser/idl/IDLReaderTest.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,95 @@ | ||
package com.github.xpenatan.jparser.idl; | ||
|
||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class IDLReaderTest { | ||
|
||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
} | ||
|
||
@Test | ||
public void test_NoDeleteClassTest_not_null() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("NoDeleteClassTest"); | ||
Assert.assertNotNull(idlClass); | ||
} | ||
|
||
@Test | ||
public void test_PrefixClassTest_not_null() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("PrefixClassTest"); | ||
Assert.assertNotNull(idlClass); | ||
} | ||
|
||
@Test | ||
public void test_PrefixClassTest_should_contains_prefix() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("PrefixClassTest"); | ||
Assert.assertEquals("MyPrefix::", idlClass.classHeader.prefixName); | ||
} | ||
|
||
@Test | ||
public void test_PrefixNoDeleteClassTest_not_null() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("PrefixNoDeleteClassTest"); | ||
Assert.assertNotNull(idlClass); | ||
} | ||
|
||
@Test | ||
public void test_PrefixNoDeleteClassTest_contains_prefix_and_no_delete() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("PrefixNoDeleteClassTest"); | ||
Assert.assertEquals("MyPrefix::", idlClass.classHeader.prefixName); | ||
Assert.assertEquals(true, idlClass.classHeader.isNoDelete); | ||
} | ||
|
||
@Test | ||
public void test_NoDeletePrefixClassTest_not_null() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("NoDeletePrefixClassTest"); | ||
Assert.assertNotNull(idlClass); | ||
} | ||
|
||
@Test | ||
public void test_NoDeletePrefixClassTest_contains_prefix_and_no_delete() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("NoDeletePrefixClassTest"); | ||
Assert.assertEquals("MyPrefix::", idlClass.classHeader.prefixName); | ||
Assert.assertEquals(true, idlClass.classHeader.isNoDelete); | ||
} | ||
|
||
@Test | ||
public void test_ConcreteJSImplementationClassTest_not_null() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("ConcreteJSImplementationClassTest"); | ||
Assert.assertNotNull(idlClass); | ||
} | ||
|
||
@Test | ||
public void test_ConcreteJSImplementationClassTest_contains_implementation() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("ConcreteJSImplementationClassTest"); | ||
Assert.assertEquals("NoDeletePrefixClassTest", idlClass.classHeader.jsImplementation); | ||
} | ||
|
||
@Test | ||
public void test_NormalClassTest_not_null() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("NormalClassTest"); | ||
Assert.assertNotNull(idlClass); | ||
} | ||
|
||
@Test | ||
public void test_ExtendClassTest_not_null() { | ||
IDLReader idlReader = IDLReader.readIDL("src\\test\\resources\\idl\\Test.idl"); | ||
IDLClass idlClass = idlReader.getClass("ExtendClassTest"); | ||
Assert.assertNotNull(idlClass); | ||
} | ||
|
||
|
||
} | ||
|
Oops, something went wrong.