-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(codegen): moved default types to mspec base
- Loading branch information
Showing
35 changed files
with
1,163 additions
and
32 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
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
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
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
65 changes: 65 additions & 0 deletions
65
.../apache/plc4x/plugins/codegenerator/language/mspec/model/definitions/DefaultArgument.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,65 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.plugins.codegenerator.language.mspec.model.definitions; | ||
|
||
import org.apache.plc4x.plugins.codegenerator.types.definitions.Argument; | ||
import org.apache.plc4x.plugins.codegenerator.types.references.TypeReference; | ||
|
||
import java.util.Objects; | ||
|
||
public class DefaultArgument implements Argument { | ||
|
||
private final TypeReference type; | ||
private final String name; | ||
|
||
public DefaultArgument(TypeReference type, String name) { | ||
// TODO: add null checks | ||
this.type = type; | ||
this.name = name; | ||
} | ||
|
||
public TypeReference getType() { | ||
return type; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DefaultArgument{" + | ||
"type=" + type + | ||
", name='" + name + '\'' + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
DefaultArgument that = (DefaultArgument) o; | ||
return Objects.equals(type, that.type) && Objects.equals(name, that.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(type, name); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...4x/plugins/codegenerator/language/mspec/model/references/AbstractSimpleTypeReference.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,65 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.plugins.codegenerator.language.mspec.model.references; | ||
|
||
import org.apache.plc4x.plugins.codegenerator.types.references.SimpleTypeReference; | ||
|
||
import java.util.Objects; | ||
|
||
public abstract class AbstractSimpleTypeReference implements SimpleTypeReference { | ||
|
||
protected final SimpleBaseType baseType; | ||
protected final int sizeInBits; | ||
|
||
public AbstractSimpleTypeReference(SimpleBaseType baseType, int sizeInBits) { | ||
this.baseType = Objects.requireNonNull(baseType); | ||
this.sizeInBits = sizeInBits; | ||
} | ||
|
||
@Override | ||
public SimpleBaseType getBaseType() { | ||
return baseType; | ||
} | ||
|
||
@Override | ||
public int getSizeInBits() { | ||
return sizeInBits; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AbstractSimpleTypeReference{" + | ||
"baseType=" + baseType + | ||
", sizeInBits=" + sizeInBits + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof AbstractSimpleTypeReference)) return false; | ||
AbstractSimpleTypeReference that = (AbstractSimpleTypeReference) o; | ||
return getSizeInBits() == that.getSizeInBits() && getBaseType() == that.getBaseType(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getBaseType(), getSizeInBits()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...4x/plugins/codegenerator/language/mspec/model/references/DefaultBooleanTypeReference.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,29 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.plugins.codegenerator.language.mspec.model.references; | ||
|
||
import org.apache.plc4x.plugins.codegenerator.types.references.BooleanTypeReference; | ||
|
||
public class DefaultBooleanTypeReference extends AbstractSimpleTypeReference implements BooleanTypeReference { | ||
|
||
public DefaultBooleanTypeReference() { | ||
super(SimpleBaseType.BIT, 1); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...plc4x/plugins/codegenerator/language/mspec/model/references/DefaultByteTypeReference.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,29 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.plugins.codegenerator.language.mspec.model.references; | ||
|
||
import org.apache.plc4x.plugins.codegenerator.types.references.ByteTypeReference; | ||
|
||
public class DefaultByteTypeReference extends AbstractSimpleTypeReference implements ByteTypeReference { | ||
|
||
public DefaultByteTypeReference() { | ||
super(SimpleBaseType.BYTE, 8); | ||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
...4x/plugins/codegenerator/language/mspec/model/references/DefaultComplexTypeReference.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,88 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.plugins.codegenerator.language.mspec.model.references; | ||
|
||
import org.apache.plc4x.plugins.codegenerator.types.definitions.TypeDefinition; | ||
import org.apache.plc4x.plugins.codegenerator.types.references.ComplexTypeReference; | ||
import org.apache.plc4x.plugins.codegenerator.types.terms.Term; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class DefaultComplexTypeReference implements ComplexTypeReference { | ||
|
||
protected final String name; | ||
|
||
protected final List<Term> params; | ||
|
||
// TODO: this should be ComplexTypeDefinition | ||
protected transient TypeDefinition typeDefinition; | ||
|
||
public DefaultComplexTypeReference(String name, List<Term> params) { | ||
this.name = Objects.requireNonNull(name); | ||
this.params = params; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Optional<List<Term>> getParams() { | ||
return Optional.ofNullable(params); | ||
} | ||
|
||
// TODO: this should be ComplexTypeDefinition | ||
@Override | ||
public TypeDefinition getTypeDefinition() { | ||
if (typeDefinition == null) { | ||
throw new IllegalStateException("Should not happen as this should be initialized. No type for " + name + " set!!!"); | ||
} | ||
return typeDefinition; | ||
} | ||
|
||
// TODO: this should be ComplexTypeDefinition | ||
public void setTypeDefinition(TypeDefinition typeDefinition) { | ||
Objects.requireNonNull(typeDefinition); | ||
this.typeDefinition = typeDefinition; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DefaultComplexTypeReference{" + | ||
"name='" + name + '\'' + | ||
", params=" + params + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
DefaultComplexTypeReference that = (DefaultComplexTypeReference) o; | ||
return Objects.equals(name, that.name) && Objects.equals(params, that.params); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, params); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...lc4x/plugins/codegenerator/language/mspec/model/references/DefaultFloatTypeReference.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,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.plugins.codegenerator.language.mspec.model.references; | ||
|
||
import org.apache.plc4x.plugins.codegenerator.types.references.FloatTypeReference; | ||
|
||
public class DefaultFloatTypeReference extends AbstractSimpleTypeReference implements FloatTypeReference { | ||
|
||
public DefaultFloatTypeReference(SimpleBaseType baseType, int size) { | ||
super(baseType, size); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DefaultFloatTypeReference{} " + super.toString(); | ||
} | ||
|
||
} |
Oops, something went wrong.