本文整理汇总了Java中org.jetbrains.java.generate.psi.PsiAdapter.getGetterFieldName方法的典型用法代码示例。如果您正苦于以下问题:Java PsiAdapter.getGetterFieldName方法的具体用法?Java PsiAdapter.getGetterFieldName怎么用?Java PsiAdapter.getGetterFieldName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jetbrains.java.generate.psi.PsiAdapter
的用法示例。
在下文中一共展示了PsiAdapter.getGetterFieldName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newMethodElement
import org.jetbrains.java.generate.psi.PsiAdapter; //导入方法依赖的package包/类
/**
* Creates a new {@link MethodElement} object.
*
* @param method the PSI method object.
* @return a new {@link MethodElement} object.
* @since 2.15
*/
public static MethodElement newMethodElement(PsiMethod method) {
MethodElement me = new MethodElement();
PsiType type = method.getReturnType();
PsiModifierList modifiers = method.getModifierList();
// if something is wrong:
// http://www.intellij.net/forums/thread.jsp?nav=false&forum=18&thread=88676&start=0&msRange=15
if (type == null) {
log.warn("This method does not have a valid return type: " + method.getName() + ", returnType=" + type);
return me;
}
PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
setElementInfo(me, factory, type, modifiers);
// names
String fieldName = PsiAdapter.getGetterFieldName(method);
me.setName(fieldName == null ? method.getName() : fieldName);
me.setFieldName(fieldName);
me.setMethodName(method.getName());
// getter
me.setGetter(PsiAdapter.isGetterMethod(method));
// misc
me.setDeprecated(method.isDeprecated());
me.setReturnTypeVoid(PsiAdapter.isTypeOfVoid(method.getReturnType()));
// modifiers
if (modifiers.hasModifierProperty(PsiModifier.ABSTRACT)) me.setModifierAbstract(true);
if (modifiers.hasModifierProperty(PsiModifier.SYNCHRONIZED)) me.setModifierSynchronized(true);
return me;
}
示例2: filterAvailableMethods
import org.jetbrains.java.generate.psi.PsiAdapter; //导入方法依赖的package包/类
/**
* Filters the list of methods from the class to be
* <ul>
* <li/>a getter method (java bean compliant)
* <li/>should not be a getter for an existing field
* <li/>public, non static, non abstract
* <ul/>
*
*
* @param clazz the class to filter it's fields
* @param pattern the filter pattern to filter out unwanted fields
* @return methods available for this action after the filter process.
*/
@NotNull
public static PsiMethod[] filterAvailableMethods(PsiClass clazz, @NotNull FilterPattern pattern) {
if (log.isDebugEnabled()) log.debug("Filtering methods using the pattern: " + pattern);
List<PsiMethod> availableMethods = new ArrayList<PsiMethod>();
PsiMethod[] methods = clazz.getMethods();
for (PsiMethod method : methods) {
// the method should be a getter
if (!PsiAdapter.isGetterMethod(method)) {
continue;
}
// must not return void
final PsiType returnType = method.getReturnType();
if (returnType == null || PsiType.VOID.equals(returnType)) {
continue;
}
// method should be public, non static, non abstract
if (!method.hasModifierProperty(PsiModifier.PUBLIC) || method.hasModifierProperty(PsiModifier.STATIC) ||
method.hasModifierProperty(PsiModifier.ABSTRACT)) {
continue;
}
// method should not be a getter for an existing field
String fieldName = PsiAdapter.getGetterFieldName(method);
if (clazz.findFieldByName(fieldName, false) != null) {
continue;
}
// must not be named toString or getClass
final String methodName = method.getName();
if ("toString".equals(methodName) || "getClass".equals(methodName) || "hashCode".equals(methodName)) {
continue;
}
// if the method matches the pattern then it shouldn't be in the list of available methods
if (pattern.methodMatches(method)) {
continue;
}
if (log.isDebugEnabled())
log.debug("Adding the method " + methodName + " as there is not a field for this getter");
availableMethods.add(method);
}
return availableMethods.toArray(new PsiMethod[availableMethods.size()]);
}
示例3: filterAvailableMethods
import org.jetbrains.java.generate.psi.PsiAdapter; //导入方法依赖的package包/类
/**
* Filters the list of methods from the class to be
* <ul>
* <li/>a getter method (java bean compliant)
* <li/>should not be a getter for an existing field
* <li/>public, non static, non abstract
* <ul/>
*
* @param clazz the class to filter it's fields
* @param pattern the filter pattern to filter out unwanted fields
* @return methods available for this action after the filter process.
*/
@NotNull
public static PsiMethod[] filterAvailableMethods(PsiClass clazz, @NotNull FilterPattern pattern)
{
if(log.isDebugEnabled())
{
log.debug("Filtering methods using the pattern: " + pattern);
}
List<PsiMethod> availableMethods = new ArrayList<PsiMethod>();
PsiMethod[] methods = clazz.getMethods();
for(PsiMethod method : methods)
{
// the method should be a getter
if(!PsiAdapter.isGetterMethod(method))
{
continue;
}
// must not return void
final PsiType returnType = method.getReturnType();
if(returnType == null || PsiType.VOID.equals(returnType))
{
continue;
}
// method should be public, non static, non abstract
if(!method.hasModifierProperty(PsiModifier.PUBLIC) || method.hasModifierProperty(PsiModifier.STATIC) ||
method.hasModifierProperty(PsiModifier.ABSTRACT))
{
continue;
}
// method should not be a getter for an existing field
String fieldName = PsiAdapter.getGetterFieldName(method);
if(clazz.findFieldByName(fieldName, false) != null)
{
continue;
}
// must not be named toString or getClass
final String methodName = method.getName();
if("toString".equals(methodName) || "getClass".equals(methodName) || "hashCode".equals(methodName))
{
continue;
}
// if the method matches the pattern then it shouldn't be in the list of available methods
if(pattern.methodMatches(method))
{
continue;
}
if(log.isDebugEnabled())
{
log.debug("Adding the method " + methodName + " as there is not a field for this getter");
}
availableMethods.add(method);
}
return availableMethods.toArray(new PsiMethod[availableMethods.size()]);
}
示例4: newMethodElement
import org.jetbrains.java.generate.psi.PsiAdapter; //导入方法依赖的package包/类
/**
* Creates a new {@link MethodElement} object.
*
* @param method the PSI method object.
* @return a new {@link MethodElement} object.
* @since 2.15
*/
public static MethodElement newMethodElement(PsiMethod method)
{
MethodElement me = new MethodElement();
PsiType type = method.getReturnType();
PsiModifierList modifiers = method.getModifierList();
// if something is wrong:
// http://www.intellij.net/forums/thread.jsp?nav=false&forum=18&thread=88676&start=0&msRange=15
if(type == null)
{
log.warn("This method does not have a valid return type: " + method.getName() + ", returnType=" + type);
return me;
}
PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
setElementInfo(me, factory, type, modifiers);
// names
String fieldName = PsiAdapter.getGetterFieldName(method);
me.setName(fieldName == null ? method.getName() : fieldName);
me.setFieldName(fieldName);
me.setMethodName(method.getName());
// getter
me.setGetter(PsiAdapter.isGetterMethod(method));
// misc
me.setDeprecated(method.isDeprecated());
me.setReturnTypeVoid(PsiAdapter.isTypeOfVoid(method.getReturnType()));
// modifiers
if(modifiers.hasModifierProperty(PsiModifier.ABSTRACT))
{
me.setModifierAbstract(true);
}
if(modifiers.hasModifierProperty(PsiModifier.SYNCHRONIZED))
{
me.setModifierSynchronized(true);
}
return me;
}