Skip to content
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

refactor: private constructors for util classes and changing places of modifiers #6

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/main/java/io/unlogged/AgentCommandExecutorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

public class AgentCommandExecutorImpl implements AgentCommandExecutor {

final private ObjectMapper objectMapper;
final private IEventLogger logger;
private final ObjectMapper objectMapper;
private final IEventLogger logger;
Objenesis objenesis = new ObjenesisStd(); // or ObjenesisSerializer
private Map<String, MockInstance> mockInstanceMap = new HashMap<>();
private final Map<String, MockInstance> mockInstanceMap = new HashMap<>();

public AgentCommandExecutorImpl(ObjectMapper objectMapper, IEventLogger logger) {
this.objectMapper = objectMapper;
Expand Down Expand Up @@ -430,15 +430,16 @@ private Object tryObjectConstruct(String className, ClassLoader targetClassLoade

// try to get the instance of the class using Singleton.getInstance
for (Method method : methods) {
if (method.getParameterCount() == 0 && Modifier.isStatic(method.getModifiers())) {
if (method.getReturnType().equals(loadedClass)) {
try {
return method.invoke(null);
} catch (InvocationTargetException ex) {
// this method for potentially getting instance from static getInstance type method
// did not work
}
if (method.getParameterCount() == 0
&& Modifier.isStatic(method.getModifiers())
&& (method.getReturnType().equals(loadedClass))) {
try {
return method.invoke(null);
} catch (InvocationTargetException ex) {
// this method for potentially getting instance from static getInstance type method
// did not work
}

}
}
throw new RuntimeException(e);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/unlogged/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@


public class Constants {

private Constants() {}

public static final String AGENT_VERSION = "1.0.1";
}
2 changes: 1 addition & 1 deletion src/main/java/io/unlogged/Unlogged.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public @interface Unlogged {
/**
* Comma separated list of package names which are to be included for recording
* @return List of strings, each one being a package name
* @return Array of strings, each one being a package name
*/
String[] includePackage() default "";

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/unlogged/launch/AnnotationProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Iterable<? extends Completion> getCompletions(Element element, Annotation
}

public static class AstModificationNotifierData {
public volatile static boolean lombokInvoked = false;
public static volatile boolean lombokInvoked = false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class DetailedEventStreamAggregatedLogger implements IEventLogger {
// private final ThreadLocal<ByteArrayOutputStream> threadOutputBuffer =
// ThreadLocal.withInitial(ByteArrayOutputStream::new);
private final ThreadLocal<Boolean> isRecording = ThreadLocal.withInitial(() -> false);
final private boolean serializeValues = true;
private final boolean serializeValues = true;
// private final Map<String, WeaveLog> classMap = new HashMap<>();
// private final Map<Integer, DataInfo> callProbes = new HashMap<>();
private final Set<Integer> probesToRecord = new HashSet<>();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/unlogged/util/ClassTypeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.util.regex.Pattern;

public class ClassTypeUtil {

private ClassTypeUtil() {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); in these utility classes can make it more readable.
@artpar your opinion?


public static List<String> splitMethodDesc(String desc) {
int beginIndex = desc.indexOf('(');
int endIndex = desc.lastIndexOf(')');
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/unlogged/util/StreamUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.nio.charset.StandardCharsets;

public class StreamUtil {

private StreamUtil() {}

public static final int BUFFER_SIZE = 8192;

public static int copy(InputStream inputStream, OutputStream outputStream) throws IOException {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/unlogged/weaver/TypeHierarchy.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

public class TypeHierarchy {

final private Map<String, String> parentMap = new HashMap<>();
final private Map<String, String[]> interfaceMap = new HashMap<>();
private final Map<String, String> parentMap = new HashMap<>();
private final Map<String, String[]> interfaceMap = new HashMap<>();
private final Names names;
private final Symtab symtab;
private Method loadClassMethod = null;
Expand Down