Java 类com.intellij.psi.PsiMember 实例源码

项目:intellij-ce-playground    文件:JavaCallHierarchyData.java   
public JavaCallHierarchyData(PsiClass originalClass,
                             PsiMethod methodToFind,
                             PsiClassType originalType,
                             PsiMethod method,
                             Set<PsiMethod> methodsToFind,
                             NodeDescriptor nodeDescriptor,
                             Map<PsiMember, NodeDescriptor> resultMap,
                             Project project) {

  myOriginalClass = originalClass;
  myMethodToFind = methodToFind;
  myOriginalType = originalType;
  myMethod = method;
  myMethodsToFind = methodsToFind;
  myNodeDescriptor = nodeDescriptor;
  myResultMap = resultMap;
  myProject = project;
}
项目:intellij-ce-playground    文件:AnnotatedMacro.java   
@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
  final Query<PsiMember> query = findAnnotated(context, params);

  if (query != null) {
    Set<LookupElement> set = new LinkedHashSet<LookupElement>();
    final String secondParamValue = params.length > 1 ? params[1].calculateResult(context).toString() : null;
    final boolean isShortName = secondParamValue != null && !Boolean.valueOf(secondParamValue);
    final Project project = context.getProject();
    final PsiClass findInClass = secondParamValue != null
                                 ? JavaPsiFacade.getInstance(project).findClass(secondParamValue, GlobalSearchScope.allScope(project))
                                 : null;

    for (PsiMember object : query.findAll()) {
      if (findInClass != null && !object.getContainingClass().equals(findInClass)) continue;
      boolean isClazz = object instanceof PsiClass;
      final String name = isShortName || !isClazz ? object.getName() : ((PsiClass) object).getQualifiedName();
      set.add(LookupElementBuilder.create(name));
    }

    return set.toArray(new LookupElement[set.size()]);
  }
  return LookupElement.EMPTY_ARRAY;
}
项目:intellij-ce-playground    文件:SamePsiMemberWeigher.java   
@Override
public Comparable weigh(@NotNull final PsiElement element, @NotNull final ProximityLocation location) {
  PsiElement position = location.getPosition();
  if (position == null){
    return null;
  }
  if (!INSIDE_PSI_MEMBER.getValue(location)) {
    return 0;
  }
  if (element.isPhysical()) {
    position = PHYSICAL_POSITION.getValue(location);
  }

  final PsiMember member = PsiTreeUtil.getContextOfType(PsiTreeUtil.findCommonContext(position, element), PsiMember.class, false);
  if (member instanceof PsiClass) return 1;
  if (member != null) return 2;
  return 0;
}
项目:intellij-ce-playground    文件:MissedTestsDialog.java   
private void disableMethodsWithTests(List<MemberInfo> info) {
  final Set<String> existingNames = new HashSet<String>();
  final String prefix = getTestPrefix(existingNames);

  existingNames.addAll(ContainerUtil.map(myTestClass.getMethods(), new Function<PsiMethod, String>() {
    @Override
    public String fun(PsiMethod method) {
      return StringUtil.decapitalize(StringUtil.trimStart(method.getName(), prefix));
    }
  }));


  for (MemberInfo memberInfo : info) {
    final PsiMember member = memberInfo.getMember();
    memberInfo.setChecked(!(member instanceof PsiMethod && existingNames.contains(member.getName())));
  }
}
项目:intellij-ce-playground    文件:ExtractSuperclassDialog.java   
protected JComponent createCenterPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(RefactoringBundle.message("members.to.form.superclass"),
                                                                             myMemberInfos, RefactoringBundle.message("make.abstract"));
  panel.add(memberSelectionPanel, BorderLayout.CENTER);
  final MemberInfoModel<PsiMember, MemberInfo> memberInfoModel =
    new UsesAndInterfacesDependencyMemberInfoModel<PsiMember, MemberInfo>(mySourceClass, null, false, myContainmentVerifier) {
      @Override
      public Boolean isFixedAbstract(MemberInfo member) {
        return Boolean.TRUE;
      }
    };
  memberInfoModel.memberInfoChanged(new MemberInfoChange<PsiMember, MemberInfo>(myMemberInfos));
  memberSelectionPanel.getTable().setMemberInfoModel(memberInfoModel);
  memberSelectionPanel.getTable().addMemberInfoChangeListener(memberInfoModel);

  panel.add(myDocCommentPanel, BorderLayout.EAST);

  return panel;
}
项目:intellij-ce-playground    文件:PushDownDialog.java   
protected JComponent createCenterPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(
    RefactoringBundle.message("members.to.be.pushed.down.panel.title"),
    myMemberInfos,
    RefactoringBundle.message("keep.abstract.column.header"));
  panel.add(memberSelectionPanel, BorderLayout.CENTER);

  myMemberInfoModel = new MyMemberInfoModel();
  myMemberInfoModel.memberInfoChanged(new MemberInfoChange<PsiMember, MemberInfo>(myMemberInfos));
  memberSelectionPanel.getTable().setMemberInfoModel(myMemberInfoModel);
  memberSelectionPanel.getTable().addMemberInfoChangeListener(myMemberInfoModel);


  myJavaDocPanel = new DocCommentPanel(RefactoringBundle.message("push.down.javadoc.panel.title"));
  myJavaDocPanel.setPolicy(JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC);
  panel.add(myJavaDocPanel, BorderLayout.EAST);
  return panel;
}
项目:intellij-ce-playground    文件:MoveMembersRefactoringImpl.java   
MoveMembersRefactoringImpl(Project project, final PsiMember[] elements, final String targetClassQualifiedName, final String newVisibility, final boolean makeEnumConstants) {
  super(new MoveMembersProcessor(project, new MoveMembersOptions() {
    public PsiMember[] getSelectedMembers() {
      return elements;
    }

    public String getTargetClassName() {
      return targetClassQualifiedName;
    }

    public String getMemberVisibility() {
      return newVisibility;
    }

    public boolean makeEnumConstant() {
      return makeEnumConstants;
    }

  }));
}
项目:intellij-ce-playground    文件:MemberSelectionTable.java   
@Override
protected Icon getOverrideIcon(MemberInfo memberInfo) {
  PsiMember member = memberInfo.getMember();
  Icon overrideIcon = MemberSelectionTable.EMPTY_OVERRIDE_ICON;
  if (member instanceof PsiMethod) {
    if (Boolean.TRUE.equals(memberInfo.getOverrides())) {
      overrideIcon = AllIcons.General.OverridingMethod;
    }
    else if (Boolean.FALSE.equals(memberInfo.getOverrides())) {
      overrideIcon = AllIcons.General.ImplementingMethod;
    }
    else {
      overrideIcon = MemberSelectionTable.EMPTY_OVERRIDE_ICON;
    }
  }
  return overrideIcon;
}
项目:intellij-ce-playground    文件:UsesAndInterfacesDependencyMemberInfoModel.java   
public UsesAndInterfacesDependencyMemberInfoModel(PsiClass aClass, @Nullable PsiClass superClass, boolean recursive,
                                                  @NotNull final InterfaceContainmentVerifier interfaceContainmentVerifier) {
  super(new ANDCombinedMemberInfoModel<T, M>(
          new UsesDependencyMemberInfoModel<T, PsiClass, M>(aClass, superClass, recursive) {
            public int checkForProblems(@NotNull M memberInfo) {
              final int problem = super.checkForProblems(memberInfo);
              if (problem == OK) return OK;
              final PsiMember member = memberInfo.getMember();
              if (member instanceof PsiMethod) {
                if (interfaceContainmentVerifier.checkedInterfacesContain((PsiMethod)member)) return OK;
              }
              return problem;
            }
          },
          new InterfaceDependencyMemberInfoModel<T, M>(aClass))
  );
}
项目:intellij-ce-playground    文件:FindMethodDuplicatesBaseTest.java   
protected void doTest(final boolean shouldSucceed) throws Exception {
  final String filePath = getTestFilePath();
  configureByFile(filePath);
  final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
  assertTrue("<caret> is not on method name", targetElement instanceof PsiMember);
  final PsiMember psiMethod = (PsiMember)targetElement;

  try {
    MethodDuplicatesHandler.invokeOnScope(getProject(), psiMethod, new AnalysisScope(getFile()));
  }
  catch (RuntimeException e) {
    if (shouldSucceed) {
      fail("duplicates were not found");
    }
    return;
  }
  UIUtil.dispatchAllInvocationEvents();
  if (shouldSucceed) {
    checkResultByFile(filePath + ".after");
  }
  else {
    fail("duplicates found");
  }
}
项目:intellij-ce-playground    文件:MoveMembersTest.java   
private void performAction(String sourceClassName, String targetClassName, int[] memberIndices, final String visibility) throws Exception {
  PsiClass sourceClass = myJavaFacade.findClass(sourceClassName, ProjectScope.getProjectScope(myProject));
  assertNotNull("Class " + sourceClassName + " not found", sourceClass);
  PsiClass targetClass = myJavaFacade.findClass(targetClassName, ProjectScope.getProjectScope(myProject));
  assertNotNull("Class " + targetClassName + " not found", targetClass);

  PsiElement[] children = sourceClass.getChildren();
  ArrayList<PsiMember> members = new ArrayList<>();
  for (PsiElement child : children) {
    if (child instanceof PsiMember) {
      members.add(((PsiMember) child));
    }
  }

  LinkedHashSet<PsiMember> memberSet = new LinkedHashSet<>();
  for (int index : memberIndices) {
    PsiMember member = members.get(index);
    assertTrue(member.hasModifierProperty(PsiModifier.STATIC));
    memberSet.add(member);
  }

  MockMoveMembersOptions options = new MockMoveMembersOptions(targetClass.getQualifiedName(), memberSet);
  options.setMemberVisibility(visibility);
  new MoveMembersProcessor(myProject, null, options).run();
  FileDocumentManager.getInstance().saveAllDocuments();
}
项目:intellij-ce-playground    文件:GrMemberSelectionTable.java   
@Override
protected Icon getOverrideIcon(GrMemberInfo memberInfo) {
  PsiMember member = memberInfo.getMember();
  Icon overrideIcon = EMPTY_OVERRIDE_ICON;
  if (member instanceof PsiMethod) {
    if (Boolean.TRUE.equals(memberInfo.getOverrides())) {
      overrideIcon = AllIcons.General.OverridingMethod;
    }
    else if (Boolean.FALSE.equals(memberInfo.getOverrides())) {
      overrideIcon = AllIcons.General.ImplementingMethod;
    }
    else {
      overrideIcon = EMPTY_OVERRIDE_ICON;
    }
  }
  return overrideIcon;
}
项目:intellij-ce-playground    文件:GroovyInlineHandler.java   
@Override
@Nullable
public Settings prepareInlineElement(@NotNull final PsiElement element, @Nullable Editor editor, boolean invokedOnReference) {
  if (element instanceof GrField) {
    return GrInlineFieldUtil.inlineFieldSettings((GrField)element, editor, invokedOnReference);
  }
  else if (element instanceof GrMethod) {
    return GroovyInlineMethodUtil.inlineMethodSettings((GrMethod)element, editor, invokedOnReference);
  }
  else {
    if (element instanceof GrTypeDefinition || element instanceof GrClassSubstitution) {
      return null;      //todo inline to anonymous class, push members from super class
    }
  }

  if (element instanceof PsiMember) {
    String message = GroovyRefactoringBundle.message("cannot.inline.0.", getFullName(element));
    CommonRefactoringUtil.showErrorHint(element.getProject(), editor, message, "", HelpID.INLINE_FIELD);
    return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
  }
  return null;
}
项目:intellij-ce-playground    文件:ElementUtils.java   
/**
 * Gets the list of members to be put in the VelocityContext.
 *
 * @param members a list of {@link PsiMember} objects.
 * @param selectedNotNullMembers
 * @param useAccessors
 * @return a filtered list of only the fields as {@link FieldElement} objects.
 */
public static List<FieldElement> getOnlyAsFieldElements(Collection<? extends PsiMember> members,
                                                        Collection<? extends PsiMember> selectedNotNullMembers,
                                                        boolean useAccessors) {
    List<FieldElement> fieldElementList = new ArrayList<FieldElement>();

    for (PsiMember member : members) {
        if (member instanceof PsiField) {
            PsiField field = (PsiField) member;
            FieldElement fe = ElementFactory.newFieldElement(field, useAccessors);
            if (selectedNotNullMembers.contains(member)) {
                fe.setNotNull(true);
            }
            fieldElementList.add(fe);
        }
    }

    return fieldElementList;
}
项目:intellij-ce-playground    文件:ElementUtils.java   
/**
 * Gets the list of members to be put in the VelocityContext.
 *
 * @param members                  a list of {@link PsiMember} objects.
 * @param selectedNotNullMembers  a list of @NotNull objects
 * @param useAccessors
 * @return a filtered list of only the methods as a {@link FieldElement} or {@link MethodElement} objects.
 */
public static List<Element> getOnlyAsFieldAndMethodElements(Collection<? extends PsiMember> members,
                                                            Collection<? extends PsiMember> selectedNotNullMembers,
                                                            boolean useAccessors) {
    List<Element> elementList = new ArrayList<Element>();

    for (PsiMember member : members) {
        AbstractElement element = null;
        if (member instanceof PsiField) {
          element = ElementFactory.newFieldElement((PsiField) member, useAccessors);
        } else if (member instanceof PsiMethod) {
          element = ElementFactory.newMethodElement((PsiMethod) member);
        }

        if (element != null) {
          if (selectedNotNullMembers.contains(member)) {
            element.setNotNull(true);
          }
          elementList.add(element);
        }
    }
    return elementList;
}
项目:tools-idea    文件:AnnotatedMacro.java   
@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
  final Query<PsiMember> query = findAnnotated(context, params);

  if (query != null) {
    Set<LookupElement> set = new LinkedHashSet<LookupElement>();
    final String secondParamValue = params.length > 1 ? params[1].calculateResult(context).toString() : null;
    final boolean isShortName = secondParamValue != null && !Boolean.valueOf(secondParamValue);
    final Project project = context.getProject();
    final PsiClass findInClass = secondParamValue != null
                                 ? JavaPsiFacade.getInstance(project).findClass(secondParamValue, GlobalSearchScope.allScope(project))
                                 : null;

    for (PsiMember object : query.findAll()) {
      if (findInClass != null && !object.getContainingClass().equals(findInClass)) continue;
      boolean isClazz = object instanceof PsiClass;
      final String name = isShortName || !isClazz ? object.getName() : ((PsiClass) object).getQualifiedName();
      set.add(LookupElementBuilder.create(name));
    }

    return set.toArray(new LookupElement[set.size()]);
  }
  return LookupElement.EMPTY_ARRAY;
}
项目:tools-idea    文件:SamePsiMemberWeigher.java   
@Override
public Comparable weigh(@NotNull final PsiElement element, @NotNull final ProximityLocation location) {
  PsiElement position = location.getPosition();
  if (position == null){
    return null;
  }
  if (!INSIDE_PSI_MEMBER.getValue(location)) {
    return 0;
  }
  if (element.isPhysical()) {
    position = PHYSICAL_POSITION.getValue(location);
  }

  final PsiMember member = PsiTreeUtil.getContextOfType(PsiTreeUtil.findCommonContext(position, element), PsiMember.class, false);
  if (member instanceof PsiClass) return 1;
  if (member != null) return 2;
  return 0;
}
项目:tools-idea    文件:ExtractSuperclassDialog.java   
protected JComponent createCenterPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(RefactoringBundle.message("members.to.form.superclass"),
                                                                             myMemberInfos, RefactoringBundle.message("make.abstract"));
  panel.add(memberSelectionPanel, BorderLayout.CENTER);
  final MemberInfoModel<PsiMember, MemberInfo> memberInfoModel =
    new UsesAndInterfacesDependencyMemberInfoModel(mySourceClass, null, false, myContainmentVerifier) {
      public Boolean isFixedAbstract(MemberInfo member) {
        return Boolean.TRUE;
      }
    };
  memberInfoModel.memberInfoChanged(new MemberInfoChange<PsiMember, MemberInfo>(myMemberInfos));
  memberSelectionPanel.getTable().setMemberInfoModel(memberInfoModel);
  memberSelectionPanel.getTable().addMemberInfoChangeListener(memberInfoModel);

  panel.add(myDocCommentPanel, BorderLayout.EAST);

  return panel;
}
项目:tools-idea    文件:PushDownDialog.java   
protected JComponent createCenterPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(
    RefactoringBundle.message("members.to.be.pushed.down.panel.title"),
    myMemberInfos,
    RefactoringBundle.message("keep.abstract.column.header"));
  panel.add(memberSelectionPanel, BorderLayout.CENTER);

  myMemberInfoModel = new MyMemberInfoModel();
  myMemberInfoModel.memberInfoChanged(new MemberInfoChange<PsiMember, MemberInfo>(myMemberInfos));
  memberSelectionPanel.getTable().setMemberInfoModel(myMemberInfoModel);
  memberSelectionPanel.getTable().addMemberInfoChangeListener(myMemberInfoModel);


  myJavaDocPanel = new DocCommentPanel(RefactoringBundle.message("push.down.javadoc.panel.title"));
  myJavaDocPanel.setPolicy(JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC);
  panel.add(myJavaDocPanel, BorderLayout.EAST);
  return panel;
}
项目:tools-idea    文件:MoveMembersRefactoringImpl.java   
MoveMembersRefactoringImpl(Project project, final PsiMember[] elements, final String targetClassQualifiedName, final String newVisibility, final boolean makeEnumConstants) {
  super(new MoveMembersProcessor(project, new MoveMembersOptions() {
    public PsiMember[] getSelectedMembers() {
      return elements;
    }

    public String getTargetClassName() {
      return targetClassQualifiedName;
    }

    public String getMemberVisibility() {
      return newVisibility;
    }

    public boolean makeEnumConstant() {
      return makeEnumConstants;
    }

  }));
}
项目:tools-idea    文件:MemberSelectionTable.java   
@Override
protected Icon getOverrideIcon(MemberInfo memberInfo) {
  PsiMember member = memberInfo.getMember();
  Icon overrideIcon = MemberSelectionTable.EMPTY_OVERRIDE_ICON;
  if (member instanceof PsiMethod) {
    if (Boolean.TRUE.equals(memberInfo.getOverrides())) {
      overrideIcon = AllIcons.General.OverridingMethod;
    }
    else if (Boolean.FALSE.equals(memberInfo.getOverrides())) {
      overrideIcon = AllIcons.General.ImplementingMethod;
    }
    else {
      overrideIcon = MemberSelectionTable.EMPTY_OVERRIDE_ICON;
    }
  }
  return overrideIcon;
}
项目:tools-idea    文件:UsesAndInterfacesDependencyMemberInfoModel.java   
public UsesAndInterfacesDependencyMemberInfoModel(PsiClass aClass, @Nullable PsiClass superClass, boolean recursive,
                                                  @NotNull final InterfaceContainmentVerifier interfaceContainmentVerifier) {
  super(new ANDCombinedMemberInfoModel<PsiMember, MemberInfo>(
          new UsesDependencyMemberInfoModel<PsiMember, PsiClass, MemberInfo>(aClass, superClass, recursive) {
            public int checkForProblems(@NotNull MemberInfo memberInfo) {
              final int problem = super.checkForProblems(memberInfo);
              if (problem == OK) return OK;
              final PsiMember member = memberInfo.getMember();
              if (member instanceof PsiMethod) {
                if (interfaceContainmentVerifier.checkedInterfacesContain((PsiMethod)member)) return OK;
              }
              return problem;
            }
          },
          new InterfaceDependencyMemberInfoModel(aClass))
  );
}
项目:tools-idea    文件:FindMethodDuplicatesBaseTest.java   
protected void doTest(final boolean shouldSucceed) throws Exception {
  final String filePath = getTestFilePath();
  configureByFile(filePath);
  final PsiElement targetElement = TargetElementUtilBase.findTargetElement(getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
  assertTrue("<caret> is not on method name", targetElement instanceof PsiMember);
  final PsiMember psiMethod = (PsiMember)targetElement;

  try {
    MethodDuplicatesHandler.invokeOnScope(getProject(), psiMethod, new AnalysisScope(getFile()));
  }
  catch (RuntimeException e) {
    if (shouldSucceed) {
      fail("duplicates were not found");
    }
    return;
  }
  UIUtil.dispatchAllInvocationEvents();
  if (shouldSucceed) {
    checkResultByFile(filePath + ".after");
  }
  else {
    fail("duplicates found");
  }
}
项目:tools-idea    文件:MoveMembersTest.java   
private void performAction(String sourceClassName, String targetClassName, int[] memberIndices, final String visibility) throws Exception {
  PsiClass sourceClass = myJavaFacade.findClass(sourceClassName, ProjectScope.getProjectScope(myProject));
  assertNotNull("Class " + sourceClassName + " not found", sourceClass);
  PsiClass targetClass = myJavaFacade.findClass(targetClassName, ProjectScope.getProjectScope(myProject));
  assertNotNull("Class " + targetClassName + " not found", targetClass);

  PsiElement[] children = sourceClass.getChildren();
  ArrayList<PsiMember> members = new ArrayList<PsiMember>();
  for (PsiElement child : children) {
    if (child instanceof PsiMember) {
      members.add(((PsiMember) child));
    }
  }

  LinkedHashSet<PsiMember> memberSet = new LinkedHashSet<PsiMember>();
  for (int index : memberIndices) {
    PsiMember member = members.get(index);
    assertTrue(member.hasModifierProperty(PsiModifier.STATIC));
    memberSet.add(member);
  }

  MockMoveMembersOptions options = new MockMoveMembersOptions(targetClass.getQualifiedName(), memberSet);
  options.setMemberVisibility(visibility);
  new MoveMembersProcessor(myProject, null, options).run();
  FileDocumentManager.getInstance().saveAllDocuments();
}
项目:tools-idea    文件:AddToTestsPatternAction.java   
@Override
public void update(AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  presentation.setVisible(false);
  final DataContext dataContext = e.getDataContext();
  final PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
  if (psiElements != null) {
    final Set<PsiMember> foundMembers = PatternConfigurationProducer.collectTestMembers(psiElements);
    if (foundMembers.isEmpty()) return;
    final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    if (project != null) {
      final List<JUnitConfiguration> foundConfigurations = collectPatternConfigurations(foundMembers, project);
      if (!foundConfigurations.isEmpty()) {
        presentation.setVisible(true);
        if (foundConfigurations.size() == 1) {
          presentation.setText("Add to temp suite: " + foundConfigurations.get(0).getName());
        }
      }
    }
  }
}
项目:tools-idea    文件:GrModifierFix.java   
public static String initText(final PsiMember member, final boolean showContainingClass, final String modifier, final boolean doSet) {
  String name;
  if (showContainingClass) {
    final PsiClass containingClass = member.getContainingClass();
    String containingClassName;
    if (containingClass != null) {
      containingClassName = containingClass.getName() + ".";
    }
    else {
      containingClassName = "";
    }

    name = containingClassName + member.getName();
  }
  else {
    name = member.getName();
  }
  String modifierText = toPresentableText(modifier);

  if (doSet) {
    return GroovyBundle.message("change.modifier", name, modifierText);
  }
  else {
    return GroovyBundle.message("change.modifier.not", name, modifierText);
  }
}
项目:tools-idea    文件:GroovyInlineHandler.java   
@Nullable
public Settings prepareInlineElement(@NotNull final PsiElement element, @Nullable Editor editor, boolean invokedOnReference) {
  if (element instanceof GrField) {
    return GrInlineFieldUtil.inlineFieldSettings((GrField)element, editor, invokedOnReference);
  }
  else if (element instanceof GrMethod) {
    return GroovyInlineMethodUtil.inlineMethodSettings((GrMethod)element, editor, invokedOnReference);
  }
  else {
    if (element instanceof GrTypeDefinition || element instanceof GrClassSubstitution) {
      return null;      //todo inline to anonymous class, push members from super class
    }
  }

  if (element instanceof PsiMember) {
    String message = GroovyRefactoringBundle.message("cannot.inline.0.", getFullName(element));
    CommonRefactoringUtil.showErrorHint(element.getProject(), editor, message, "", HelpID.INLINE_FIELD);
    return InlineHandler.Settings.CANNOT_INLINE_SETTINGS;
  }
  return null;
}
项目:tools-idea    文件:ElementUtils.java   
/**
 * Gets the list of members to be put in the VelocityContext.
 *
 * @param members a list of {@link com.intellij.psi.PsiMember} objects.
 * @return a filtered list of only the methods as a {@link FieldElement} or {@link MethodElement} objects.
 */
public static List<Element> getOnlyAsFieldAndMethodElements(Collection<PsiMember> members) {
    List<Element> elementList = new ArrayList<Element>();

    for (PsiMember member : members) {
        if (member instanceof PsiField) {
            PsiField field = (PsiField) member;
            FieldElement fe = ElementFactory.newFieldElement(field);
            elementList.add(fe);
        } else if (member instanceof PsiMethod) {
            PsiMethod method = (PsiMethod) member;
            MethodElement me = ElementFactory.newMethodElement(method);
            elementList.add(me);
        }
    }
    return elementList;
}
项目:intellij-haxe    文件:HaxeParameterModel.java   
public HaxeParameterModel(HaxeParameter parameter) {
  super(parameter);

  this.parameter = parameter;
  this.optional = UsefulPsiTreeUtil.getToken(parameter, "?") != null;

  final PsiMember parentPsi = PsiTreeUtil.getParentOfType(parameter, HaxeEnumValueDeclaration.class, HaxeMethod.class);
  if (parentPsi instanceof HaxeMethod) {
    memberModel = ((HaxeMethod)parentPsi).getModel();
  }
  else if (parentPsi instanceof HaxeEnumValueDeclaration) {
    memberModel = new HaxeFieldModel((HaxePsiField)parentPsi);
  }
  else {
    memberModel = null;
  }
}
项目:intellij-haxe    文件:ExtractSuperclassDialog.java   
protected JComponent createCenterPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(RefactoringBundle.message("members.to.form.superclass"),
                                                                             myMemberInfos, RefactoringBundle.message("make.abstract"));
  panel.add(memberSelectionPanel, BorderLayout.CENTER);
  final MemberInfoModel<PsiMember, MemberInfo> memberInfoModel =
    new UsesAndInterfacesDependencyMemberInfoModel<PsiMember, MemberInfo>(mySourceClass, null, false, myContainmentVerifier) {
      @Override
      public Boolean isFixedAbstract(MemberInfo member) {
        return Boolean.TRUE;
      }
    };
  memberInfoModel.memberInfoChanged(new MemberInfoChange<PsiMember, MemberInfo>(myMemberInfos));
  memberSelectionPanel.getTable().setMemberInfoModel(memberInfoModel);
  memberSelectionPanel.getTable().addMemberInfoChangeListener(memberInfoModel);

  panel.add(myDocCommentPanel, BorderLayout.EAST);

  return panel;
}
项目:intellij-haxe    文件:HaxePushDownDialog.java   
protected JComponent createCenterPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(
    RefactoringBundle.message("members.to.be.pushed.down.panel.title"),
    myMemberInfos,
    RefactoringBundle.message("keep.abstract.column.header"));
  panel.add(memberSelectionPanel, BorderLayout.CENTER);

  myMemberInfoModel = new MyMemberInfoModel();
  myMemberInfoModel.memberInfoChanged(new MemberInfoChange<PsiMember, MemberInfo>(myMemberInfos));
  memberSelectionPanel.getTable().setMemberInfoModel(myMemberInfoModel);
  memberSelectionPanel.getTable().addMemberInfoChangeListener(myMemberInfoModel);


  myJavaDocPanel = new DocCommentPanel(RefactoringBundle.message("push.down.javadoc.panel.title"));
  myJavaDocPanel.setPolicy(JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC);
  panel.add(myJavaDocPanel, BorderLayout.EAST);
  return panel;
}
项目:lombok-intellij-plugin    文件:DelegateHandler.java   
public <T extends PsiMember & PsiNamedElement> void generateElements(@NotNull T psiElement, @NotNull PsiType psiElementType, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) {
  final Project project = psiElement.getProject();
  final PsiManager manager = psiElement.getContainingFile().getManager();

  final Collection<Pair<PsiMethod, PsiSubstitutor>> includesMethods = new HashSet<Pair<PsiMethod, PsiSubstitutor>>();

  final Collection<PsiType> types = collectDelegateTypes(psiAnnotation, psiElementType);
  addMethodsOfTypes(types, includesMethods);

  final Collection<Pair<PsiMethod, PsiSubstitutor>> excludeMethods = new HashSet<Pair<PsiMethod, PsiSubstitutor>>();
  PsiClassType javaLangObjectType = PsiType.getJavaLangObject(manager, GlobalSearchScope.allScope(project));
  addMethodsOfType(javaLangObjectType, excludeMethods);

  final Collection<PsiType> excludes = collectExcludeTypes(psiAnnotation);
  addMethodsOfTypes(excludes, excludeMethods);

  final Collection<Pair<PsiMethod, PsiSubstitutor>> methodsToDelegate = findMethodsToDelegate(includesMethods, excludeMethods);
  if (!methodsToDelegate.isEmpty()) {
    final PsiClass psiClass = psiElement.getContainingClass();
    if (null != psiClass) {
      for (Pair<PsiMethod, PsiSubstitutor> pair : methodsToDelegate) {
        target.add(generateDelegateMethod(psiClass, psiElement, psiAnnotation, pair.getFirst(), pair.getSecond()));
      }
    }
  }
}
项目:consulo-java    文件:PushDownTest.java   
private void doTestImplements() {
  configureByFile(BASE_PATH + getTestName(false) + ".java");

  PsiClass currentClass = JavaPsiFacade.getInstance(getProject()).findClass("Test", GlobalSearchScope.projectScope(getProject()));
  MemberInfoStorage memberInfoStorage = new MemberInfoStorage(currentClass, new MemberInfo.Filter<PsiMember>() {
    @Override
    public boolean includeMember(PsiMember element) {
      return true;
    }
  });
  List<MemberInfo> members = memberInfoStorage.getClassMemberInfos(currentClass);
  for (MemberInfo member : members) {
    member.setChecked(true);
  }

  new PushDownProcessor(getProject(), members.toArray(new MemberInfo[members.size()]), currentClass,
                        new DocCommentPolicy(DocCommentPolicy.ASIS)) {
    @Override
    protected boolean showConflicts(MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
      return true;
    }
  }.run();

  checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
项目:consulo-java    文件:JavaPresentationUtil.java   
@Nullable
private static String getJavaSymbolContainerText(final PsiElement element) {
  final String result;
  PsiElement container = PsiTreeUtil.getParentOfType(element, PsiMember.class, PsiFile.class);

  if (container instanceof PsiClass) {
    String qName = ((PsiClass)container).getQualifiedName();
    if (qName != null) {
      result = qName;
    }
    else {
      result = ((PsiClass)container).getName();
    }
  }
  else if (container instanceof PsiJavaFile) {
    result = ((PsiJavaFile)container).getPackageName();
  }
  else {//TODO: local classes
    result = null;
  }
  if (result != null) {
    return PsiBundle.message("aux.context.display", result);
  }
  return null;
}
项目:consulo-java    文件:VisibilityUtil.java   
@PsiModifier.ModifierConstant
public static String getPossibleVisibility(final PsiMember psiMethod, final PsiElement place)
{
    Project project = psiMethod.getProject();
    if(PsiUtil.isAccessible(project, psiMethod, place, null))
    {
        return getVisibilityModifier(psiMethod.getModifierList());
    }
    if(JavaPsiFacade.getInstance(project).arePackagesTheSame(psiMethod, place))
    {
        return PsiModifier.PACKAGE_LOCAL;
    }
    if(InheritanceUtil.isInheritorOrSelf(PsiTreeUtil.getParentOfType(place, PsiClass.class), psiMethod.getContainingClass(), true))
    {
        return PsiModifier.PROTECTED;
    }
    return PsiModifier.PUBLIC;
}
项目:consulo-java    文件:VisibilityUtil.java   
@Nls
@NotNull
public static String getVisibilityStringToDisplay(@NotNull PsiMember member)
{
    if(member.hasModifierProperty(PsiModifier.PUBLIC))
    {
        return toPresentableText(PsiModifier.PUBLIC);
    }
    if(member.hasModifierProperty(PsiModifier.PROTECTED))
    {
        return toPresentableText(PsiModifier.PROTECTED);
    }
    if(member.hasModifierProperty(PsiModifier.PRIVATE))
    {
        return toPresentableText(PsiModifier.PRIVATE);
    }
    return toPresentableText(PsiModifier.PACKAGE_LOCAL);
}
项目:consulo-java    文件:InterfaceMemberDependencyGraph.java   
public String getElementTooltip(PsiMember member)
{
    final Set<? extends PsiMember> dependencies = getDependenciesOf(member);
    if(dependencies == null || dependencies.size() == 0)
    {
        return null;
    }
    StringBuilder buffer = new StringBuilder();
    buffer.append(RefactoringBundle.message("interface.member.dependency.required.by.interfaces",
            dependencies.size()));
    buffer.append(" ");
    for(Iterator<? extends PsiMember> iterator = dependencies.iterator(); iterator.hasNext(); )
    {
        PsiClass aClass = (PsiClass) iterator.next();
        buffer.append(aClass.getName());
        if(iterator.hasNext())
        {
            buffer.append(", ");
        }
    }
    return buffer.toString();
}
项目:consulo-java    文件:PsiLambdaNameHelper.java   
public static String getLambdaPrefix(@NotNull PsiLambdaExpression lambdaExpression)
{
    PsiMember member = PsiTreeUtil.getParentOfType(lambdaExpression, PsiMethod.class, PsiClass.class, PsiField.class);
    final String methodPrefix;
    if(member instanceof PsiMethod)
    {
        methodPrefix = member.getContainingClass() instanceof PsiAnonymousClass ? "" : "$" + member.getName();
    }
    else if(member instanceof PsiField && member.getContainingClass() instanceof PsiAnonymousClass)
    {
        methodPrefix = "";
    }
    else
    {
        //inside class initializer everywhere or field in a named class
        methodPrefix = "$new";
    }
    return methodPrefix;
}
项目:consulo-java    文件:ElementUtils.java   
/**
 * Gets the list of members to be put in the VelocityContext.
 *
 * @param members                a list of {@link PsiMember} objects.
 * @param selectedNotNullMembers
 * @param useAccessors
 * @return a filtered list of only the fields as {@link FieldElement} objects.
 */
public static List<FieldElement> getOnlyAsFieldElements(Collection<? extends PsiMember> members, Collection<? extends PsiMember> selectedNotNullMembers, boolean useAccessors)
{
    List<FieldElement> fieldElementList = new ArrayList<FieldElement>();

    for(PsiMember member : members)
    {
        if(member instanceof PsiField)
        {
            PsiField field = (PsiField) member;
            FieldElement fe = ElementFactory.newFieldElement(field, useAccessors);
            if(selectedNotNullMembers.contains(member))
            {
                fe.setNotNull(true);
            }
            fieldElementList.add(fe);
        }
    }

    return fieldElementList;
}
项目:consulo-java    文件:MoveMembersProcessor.java   
private void setCommandName(final PsiMember[] members)
{
    StringBuilder commandName = new StringBuilder();
    commandName.append(MoveHandler.REFACTORING_NAME);
    commandName.append(" ");
    boolean first = true;
    for(PsiMember member : members)
    {
        if(!first)
        {
            commandName.append(", ");
        }
        commandName.append(UsageViewUtil.getType(member));
        commandName.append(' ');
        commandName.append(UsageViewUtil.getShortName(member));
        first = false;
    }

    myCommandName = commandName.toString();
}