Use enum instead of Boolean; switch to synchronized map

This commit is contained in:
Rawi01 authored and Roel Spilker committed 2020-08-27 22:59:59 +02:00
1 parent 355ea57b80
commit f44c642d40
1 file changed
+15 -8
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2019 The Project Lombok Authors.
* Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -24,6 +24,8 @@ package lombok.eclipse;
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
import lombok.ConfigurationKeys;
@@ -64,7 +66,7 @@ public class TransformEclipseAST {
public static boolean disableLombok = false;
private static final HistogramTracker lombokTracker;
private static WeakHashMap<CompilationUnitDeclaration, Boolean> completlyHandled = new WeakHashMap<CompilationUnitDeclaration, Boolean>();
private static Map<CompilationUnitDeclaration, State> transformationStates = Collections.synchronizedMap(new WeakHashMap<CompilationUnitDeclaration, State>());
static {
String v = System.getProperty("lombok.histogram");
@@ -143,14 +145,14 @@ public class TransformEclipseAST {
* @return <code>true</code> if this AST was already handled by lombok.
*/
public static boolean alreadyTransformed(CompilationUnitDeclaration ast) {
Boolean state = completlyHandled.get(ast);
if (state != null) {
if (state) return true;
State state = transformationStates.get(ast);
if (state == State.FULL) return true;
if (state == State.DIET) {
if (!EclipseAST.isComplete(ast)) return true;
completlyHandled.put(ast, Boolean.TRUE);
transformationStates.put(ast, State.FULL);
} else {
completlyHandled.put(ast, Boolean.FALSE);
transformationStates.put(ast, State.DIET);
}
return false;
}
@@ -270,4 +272,9 @@ public class TransformEclipseAST {
nextPriority = Math.min(nextPriority, handlers.handleAnnotation(top, annotationNode, annotation, priority));
}
}
private static enum State {
DIET,
FULL
}
}