我正在使用谷歌AutoFactory的注释处理器.我注释SomeClass
与@AutoFactory
和引用的new SomeClassFactory().create()
是同一个模块在其他地方.
我在Maven中添加了必要的依赖:
<dependency>
<groupId>com.google.auto.factory</groupId>
<artifactId>auto-factory</artifactId>
<version>1.0-beta2</version>
<optional>true</optional>
</dependency>
Run Code Online (Sandbox Code Playgroud)
运行时,$ mvn clean compile
我看到它target/generated-sources/annotions/somepackage/SomeClassFactory
已创建,模块编译没有错误.
Reimport all maven modules
Preferences
- > Annotation Processors
- >Enable annotation processing
Rebuild Project
v14.1.4
如果我的理解是正确的,那么在我的IDEA()版本中这应该足够了.
我还执行了以下步骤:
generated-sources
文件夹已添加为源Project Structure
Generated sources folders
已设置为Detect automatically
target
首先删除文件夹以确保它是由IntelliJ生成的)Exclude output paths
按照@tilpner的建议在项目结构中禁用.idea
文件夹和.iml
文件Phase to be used for …
我正在尝试为从某个抽象类扩展或实现某个接口的所有类实现通用反序列化器.在这个例子中,我使用的是界面StringConvertible
.我需要确定具体类型,以便我可以创建一个实例.
程序员布鲁斯的一篇旧论坛帖子让我使用了ContextDeserializer,当StringConvertible是另一个类中的属性时它正在工作.
但是当我想直接反序列化StringConvertible时,我无法找到获取具体类型的方法,因为beanProperty
参数是null
.根据Jackson JSON用户组的这个问题/回答,显然这是预期的:
The only case where property should be null is when serializing a "root value", meaning the object instance passed directly to ObjectMapper's (or ObjectWriter's) writeValue() method -- in this case there simply isn't a referring property. But otherwise it should always be passed.
有关两种情况的示例,请参阅下面的主要方法:
@JsonDeserialize(using = StringConvertibleDeserializer.class)
public final class SomeStringConvertible implements StringConvertible {
private final String value;
public SomeStringConvertible(final String value) {
this.value = …
Run Code Online (Sandbox Code Playgroud) 我正在为AtomicInteger和AtomicBoolean编写单元测试.它们将用作参考测试,用于在objective-c中测试这些类的仿真,以用于翻译项目.
我认为AtomicInteger测试很好,主要是通过在大量for循环中执行可预测数量的递增,递减,加法和减法操作,每个循环都在自己的线程中运行(每个操作类型有很多线程).实际操作使用CountDownLatch同时启动.
当所有线程完成后,我通过比较原子整数和预期的整数值来断言,基于线程数,每个线程的迭代次数和每次迭代的预期增加/减少.这个测试通过.
但是如何测试AtomicBoolean?基本操作是get和set,因此在许多线程中多次调用并期望最终结果为true或false似乎没有意义.我正在考虑的方向是使用两个应始终具有相反值的AtomicBooleans.像这样:
@Test
public void testAtomicity() throws Exception {
// ==== SETUP ====
final AtomicBoolean booleanA = new AtomicBoolean(true);
final AtomicBoolean booleanB = new AtomicBoolean(false);
final int threadCount = 50;
final int iterationsPerThread = 5000;
final CountDownLatch startSignalLatch = new CountDownLatch(1);
final CountDownLatch threadsFinishedLatch = new CountDownLatch(threadCount);
final AtomicBoolean assertFailed = new AtomicBoolean(false);
// ==== EXECUTE: start all threads ====
for (int i = 0; i < threadCount; i++) {
// ==== Create the thread =====
AtomicOperationsThread …
Run Code Online (Sandbox Code Playgroud) 我正在重新审视一个我至少一年没有碰过的 Maven 项目。我很确定当我离开它时它已经成功编译(目录中仍然有一个工作 jar target
),但现在编译失败,因为生成的类丢失了。
target/generated-sources/annotations
(不存在)-proc:none
(它不是)mvn clean dependency:unpack-dependencies -Dmdep.useSubDirectoryPerArtifact=true
以确保预期的依赖项位于类路径上并且它们包含有效的META-INF/services/javax.annotation.processing.Processor
条目(是的,有多个,包括org.immutables.processor.ProxyProcessor
)-nowarn
选项并添加-verbose -XprintRounds -XprintProcessorInfo -Xlint -J-verbose
. 注意:我还必须添加主类的相对路径,否则 javac 会抱怨没有源。-proc:only
向 javac 命令添加了选项-processor org.immutables.processor.ProxyProcessor
到 javac 命令(处理器现已加载,但仍然没有打印轮次,也没有生成类)-processor org.immutables.processor.ProxyProcessorXXX
查看是否会产生影响(确实如此 …我pv
在管道中使用命令来显示进度条。我用一个简单的计数器试了一下:
for (( i = 1 ; i <= 100 ; i++ )); do sleep 1; echo $i; done | pv --progress --line-mode --size 100 --eta --timer
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我希望进度条显示在同一行。这个答案解释了如何做到这一点。
所以我试过这个:
for (( i = 1 ; i <= 100 ; i++ )); do sleep 1; echo $i; done | >&2 echo -en "\r"; pv --progress --line-mode --size 100 --eta --timer
Run Code Online (Sandbox Code Playgroud)
它保持在一行,但现在不再更新 ETA。
我怎样才能让 ETA 也更新?
现在 iBug回答了上一节中的问题,我意识到我还有一个相关的要求:stdout
需要保留以便可以在下一个管道中使用。在我的特定情况下,我需要将结果写入文件(即> …
java ×4
maven ×2
autofactory ×1
bash ×1
concurrency ×1
jackson ×1
javac ×1
json ×1
linux ×1
macos ×1
pv ×1
shell ×1
unit-testing ×1