当前位置: 首页>>代码示例>>Java>>正文


Java PsiAdapter.getGetterFieldName方法代码示例

本文整理汇总了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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:41,代码来源:ElementFactory.java

示例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()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:60,代码来源:GenerateToStringUtils.java

示例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()]);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:72,代码来源:GenerateToStringUtils.java

示例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;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:49,代码来源:ElementFactory.java


注:本文中的org.jetbrains.java.generate.psi.PsiAdapter.getGetterFieldName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。