Java 类com.intellij.psi.codeStyle.arrangement.MemberOrderService 实例源码

项目:intellij-ce-playground    文件:JavaPsiImplementationHelperImpl.java   
@Nullable
@Override
public PsiElement getDefaultMemberAnchor(@NotNull PsiClass aClass, @NotNull PsiMember member) {
  CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(aClass.getProject());
  MemberOrderService service = ServiceManager.getService(MemberOrderService.class);
  PsiElement anchor = service.getAnchor(member, settings.getCommonSettings(JavaLanguage.INSTANCE), aClass);

  PsiElement newAnchor = skipWhitespaces(aClass, anchor);
  if (newAnchor != null) {
    return newAnchor;
  }

  if (anchor != null && anchor != aClass) {
    anchor = anchor.getNextSibling();
    while (anchor instanceof PsiJavaToken && (anchor.getText().equals(",") || anchor.getText().equals(";"))) {
      final boolean afterComma = anchor.getText().equals(",");
      anchor = anchor.getNextSibling();
      if (afterComma) {
        newAnchor = skipWhitespaces(aClass, anchor);
        if (newAnchor != null) return newAnchor;
      }
    }
    if (anchor != null) {
      return anchor;
    }
  }

  // The main idea is to avoid to anchor to 'white space' element because that causes reformatting algorithm
  // to perform incorrectly. The algorithm is encapsulated at the PostprocessReformattingAspect.doPostponedFormattingInner().
  final PsiElement lBrace = aClass.getLBrace();
  if (lBrace != null) {
    PsiElement result = lBrace.getNextSibling();
    while (result instanceof PsiWhiteSpace) {
      result = result.getNextSibling();
    }
    return result;
  }

  return aClass.getRBrace();
}
项目:tools-idea    文件:JavaPsiImplementationHelperImpl.java   
@Nullable
@Override
public PsiElement getDefaultMemberAnchor(@NotNull PsiClass aClass, @NotNull PsiMember member) {
  CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(aClass.getProject());
  MemberOrderService service = ServiceManager.getService(MemberOrderService.class);
  PsiElement anchor = service.getAnchor(member, settings.getCommonSettings(JavaLanguage.INSTANCE), aClass);

  PsiElement newAnchor = skipWhitespaces(aClass, anchor);
  if (newAnchor != null) {
    return newAnchor;
  }

  if (anchor != null && anchor != aClass) {
    anchor = anchor.getNextSibling();
    while (anchor instanceof PsiJavaToken && (anchor.getText().equals(",") || anchor.getText().equals(";"))) {
      final boolean afterComma = anchor.getText().equals(",");
      anchor = anchor.getNextSibling();
      if (afterComma) {
        newAnchor = skipWhitespaces(aClass, anchor);
        if (newAnchor != null) return newAnchor;
      }
    }
    if (anchor != null) {
      return anchor;
    }
  }

  // The main idea is to avoid to anchor to 'white space' element because that causes reformatting algorithm
  // to perform incorrectly. The algorithm is encapsulated at the PostprocessReformattingAspect.doPostponedFormattingInner().
  final PsiElement lBrace = aClass.getLBrace();
  if (lBrace != null) {
    PsiElement result = lBrace.getNextSibling();
    while (result instanceof PsiWhiteSpace) {
      result = result.getNextSibling();
    }
    return result;
  }

  return aClass.getRBrace();
}
项目:consulo-java    文件:JavaPsiImplementationHelperImpl.java   
@Nullable
@Override
public PsiElement getDefaultMemberAnchor(@NotNull PsiClass aClass, @NotNull PsiMember member)
{
    CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(aClass.getProject());
    MemberOrderService service = ServiceManager.getService(MemberOrderService.class);
    PsiElement anchor = service.getAnchor(member, settings.getCommonSettings(JavaLanguage.INSTANCE), aClass);

    PsiElement newAnchor = skipWhitespaces(aClass, anchor);
    if(newAnchor != null)
    {
        return newAnchor;
    }

    if(anchor != null && anchor != aClass)
    {
        anchor = anchor.getNextSibling();
        while(anchor instanceof PsiJavaToken && (anchor.getText().equals(",") || anchor.getText().equals(";")))
        {
            final boolean afterComma = anchor.getText().equals(",");
            anchor = anchor.getNextSibling();
            if(afterComma)
            {
                newAnchor = skipWhitespaces(aClass, anchor);
                if(newAnchor != null)
                {
                    return newAnchor;
                }
            }
        }
        if(anchor != null)
        {
            return anchor;
        }
    }

    // The main idea is to avoid to anchor to 'white space' element because that causes reformatting algorithm
    // to perform incorrectly. The algorithm is encapsulated at the PostprocessReformattingAspect.doPostponedFormattingInner().
    final PsiElement lBrace = aClass.getLBrace();
    if(lBrace != null)
    {
        PsiElement result = lBrace.getNextSibling();
        while(result instanceof PsiWhiteSpace)
        {
            result = result.getNextSibling();
        }
        return result;
    }

    return aClass.getRBrace();
}