-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for the package attribute on the types element. #904
Changes from 2 commits
20efc51
2ac9ee3
7280689
81eb134
e9b4134
065e6b6
f1eff14
b021a02
8ceb73d
b29daa1
b38f1cd
6ddce5a
f876441
6c0a263
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2013-2022 Real Logic Limited. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 uk.co.real_logic.sbe.generation; | ||
|
||
import org.agrona.generation.OutputManager; | ||
|
||
/** | ||
* Extended version of the OutputManager allowing to set the java package. To be moved to agrona. | ||
*/ | ||
public interface MultiPackageOutputManager extends OutputManager | ||
{ | ||
/** | ||
* Sets the current package name. | ||
* @param packageName the packageName | ||
*/ | ||
void setPackageName(String packageName); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2013-2022 Real Logic Limited. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 uk.co.real_logic.sbe.generation.java; | ||
|
||
import java.io.FilterWriter; | ||
import java.io.IOException; | ||
import java.io.Writer; | ||
import org.agrona.collections.Object2NullableObjectHashMap; | ||
import org.agrona.collections.Object2ObjectHashMap; | ||
import org.agrona.generation.PackageOutputManager; | ||
import uk.co.real_logic.sbe.generation.MultiPackageOutputManager; | ||
|
||
/** | ||
* Implementation of {@link MultiPackageOutputManager} for Java. | ||
*/ | ||
public class JavaOutputManager implements MultiPackageOutputManager | ||
{ | ||
|
||
ratcashdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private final String baseDirName; | ||
private final PackageOutputManager global; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming should be more explicit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming's difficult. But tried to do my best. |
||
private PackageOutputManager acting; | ||
private final Object2ObjectHashMap<String, PackageOutputManager> outputManagerCache | ||
= new Object2NullableObjectHashMap<>(); | ||
|
||
/** | ||
* Constructor. | ||
* @param baseDirName the target directory | ||
* @param packageName the initial package name | ||
*/ | ||
public JavaOutputManager(final String baseDirName, final String packageName) | ||
{ | ||
global = new PackageOutputManager(baseDirName, packageName); | ||
acting = global; | ||
this.baseDirName = baseDirName; | ||
} | ||
|
||
@Override | ||
public void setPackageName(final String packageName) | ||
{ | ||
acting = outputManagerCache.get(packageName); | ||
if (acting == null) | ||
{ | ||
acting = new PackageOutputManager(baseDirName, packageName); | ||
outputManagerCache.put(packageName, acting); | ||
} | ||
} | ||
|
||
private void resetPackage() | ||
{ | ||
acting = global; | ||
} | ||
|
||
@Override | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OverRide not used in code style. |
||
public Writer createOutput(final String name) throws IOException | ||
{ | ||
return new FilterWriter(acting.createOutput(name)) | ||
{ | ||
@Override | ||
ratcashdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public void close() throws IOException | ||
{ | ||
super.close(); | ||
resetPackage(); | ||
} | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this default to
true
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless
TYPE_PACKAGE_OVERRIDE
is explicitly set totrue
, the generator will not respect package overrides, therefore behave like before this change - unless I am missing something here?