Does anyone know of an equivalent for Eclipse 4.4's Store information about method parameters (usable via reflection) compiler property in Intellij Idea 13 (or older, but I doubt it would be available)?
Edit: This link shows how to do it with maven, but I would still like to know how it's done in Idea Run Eclipse with M2 Maven build ignores "Store method parameter names" definition
Overview. Method Parameter Reflection support was added in Java 8. Simply put, it provides support for getting the names of parameters at runtime. In this quick tutorial, we'll take a look at how to access parameter names for constructors and methods at runtime – using reflection.
reflect package is used to fetch the parameter types using method parameter reflection. Reflection is a process of analyzing and modifying all capabilities of class at runtime. It is also used to manipulate private members of the class which includes fields, methods and constructors, etc..
View parameter hints in the editorOpen the Settings/Preferences dialog ( Ctrl+Alt+S ) and go to Editor | Inlay Hints | <required language>. Select Parameter hints from the list, make sure the Show parameter hints checkbox is selected, and then specify the context where you want parameter hints shown.
Try this to validate. I have copied it from the article.
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Parameter;
import static java.lang.System.out;
/**
* Uses JDK 8 Parameter class to demonstrate metadata related to the parameters
* of the methods and constructors of the provided class (includes private,
* protected, and public methods, but does not include methods inherited from
* parent classes; those classes should be individually submitted).
*
* @author Dustin
*/
public class Main {
private static void displayParametersMetadata(final String className) {
try {
final Class clazz = Class.forName(className);
// Get all class's declared methods (does not get inherited methods)
final Method[] declaredMethods = clazz.getDeclaredMethods();
for (final Method method : declaredMethods) {
writeHeader(
"Method " + method.toGenericString()
+ " has " + method.getParameterCount() + " Parameters:");
int parameterCount = 0;
final Parameter[] parameters = method.getParameters();
for (final Parameter parameter : parameters) {
out.println(
"\targ" + parameterCount++ + ": "
+ (parameter.isNamePresent() ? parameter.getName() : "Parameter Name not provided,")
+ (isParameterFinal(parameter) ? " IS " : " is NOT ")
+ "final, type " + parameter.getType().getCanonicalName()
+ ", and parameterized type of " + parameter.getParameterizedType()
+ " and " + (parameter.isVarArgs() ? "IS " : "is NOT ")
+ "variable.");
}
}
} catch (ClassNotFoundException cnfEx) {
out.println("Unable to find class " + className);
}
}
private static void writeHeader(final String headerText) {
out.println("\n==========================================================");
out.println("= " + headerText);
out.println("==========================================================");
}
/**
* Indicate whether provided Parameter is final.
*
* @param parameter Parameter to be tested for 'final' modifier.
* @return {@code true} if provided Parameter is 'final'.
*/
private static boolean isParameterFinal(final Parameter parameter) {
return Modifier.isFinal(parameter.getModifiers());
}
public static void main(final String[] arguments) {
displayParametersMetadata("TestProperties");
}
}
And the test class:
import java.util.List;
/**
* Created with IntelliJ IDEA.
* User: zpontikas
* Date: 7/10/2014
* Time: 17:02
*/
public class TestProperties {
public String getSomeStringValue(String thisIsAProperty) {
return thisIsAProperty;
}
public static List<Integer> getSomeLists(final List<Integer> anotherProName) {
return anotherProName;
}
public void manyProperties(final String onePropertyString,final int anotherIntProperty, final boolean thisIsBool) {
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With