コード例 #1
0
 /**
  * Called when getters and setters are to be kept together in pairs. Searches the list of entries
  * for any getter/setter methods that matches this getter method. Normally there is only one
  * setter per getter, but one could have a "getXXX", "isXXX" and "setXXX" trio which need to be
  * related. In this case, the first getter encountered finds the other getter and setter and the
  * three will be emitted in that order.
  *
  * @param possibleMethods entry list, possibly containing the corresponding setter for this
  *     getter.
  * @param settings
  */
 public void determineSetter(
     final List<ClassContentsEntry> possibleMethods, RearrangerSettings settings) {
   if (!isGetter()) // wasted assertion, already checked before calling
   {
     return;
   }
   final PsiMethod thisMethod = (PsiMethod) myEnd;
   String thisProperty = MethodUtil.getPropertyName(thisMethod);
   if (isGetter() && !myKeptWithProperty) {
     if (settings.isKeepGettersSettersWithProperty()) {
       hookGetterToProperty(possibleMethods);
     }
   }
   for (ClassContentsEntry o : possibleMethods) {
     if (o instanceof RelatableEntry) {
       MethodEntry me = (MethodEntry) o;
       // don't use a setter twice (could be two methods which both look like getters; assign the
       // setter
       // to only one of them.)  Also, associate all getter/setter methods for the same property
       // with the
       // first one encountered.
       if ((me.isSetter() || me.isGetter())
           && me.myCorrespondingGetterSetters.size() == 0
           && me != this) {
         PsiMethod m = (PsiMethod) me.myEnd;
         String otherProperty = MethodUtil.getPropertyName(m);
         if (thisProperty.equals(otherProperty)) {
           LOG.debug(
               "method " + thisMethod.toString() + " is getter; its setter is " + m.toString());
           // place getters ahead of setters
           if (me.isGetter()) {
             myCorrespondingGetterSetters.add(0, me);
             // clear the getter flag and set the setter flag; this causes the method to be emitted
             // under the first getter encountered.
             me.setGetter(false);
             me.setSetter(true);
           } else {
             myCorrespondingGetterSetters.add(me);
           }
           me.myCorrespondingGetterSetters.add(this);
         }
       }
     }
   }
 }
コード例 #2
0
 public DefaultMutableTreeNode addToPopupTree(
     DefaultMutableTreeNode parent, RearrangerSettings settings) {
   DefaultMutableTreeNode node = new RearrangerTreeNode(this, myName);
   parent.add(node);
   ListIterator li;
   for (MethodEntry methodEntry : sortedMethods) {
     if (methodEntry.isSetter() && methodEntry.myCalledByMethods.size() > 0) {
       // setters are arranged with getters when "keep getters/setters together" option is checked.
       // but setters are not really called by getters.  So attach them to the upper level.
       methodEntry.addToPopupTree(parent, settings);
     } else {
       methodEntry.addToPopupTree(node, settings);
     }
   }
   for (MethodEntry methodEntry : myOverloadedMethods) {
     methodEntry.addToPopupTree(node, settings);
   }
   return node;
 }