/** * Build a string representing a sequence of method calls needed to reach a particular child * method. * * @param allMethods previous method call sequence * @param newMethods names of each of the methods in callingMethods * @param callingMethods MethodEntry objects for each method * @param currentMethod current method being handled * @param rms contains setting determining if depth-first or breadth-first traversal has taken * place. * @return */ private String appendMN( String allMethods, String[] newMethods, List callingMethods, MethodEntry currentMethod, RelatedMethodsSettings rms) { StringBuffer result = new StringBuffer(allMethods.length() + 80); result.append(allMethods); if (rms.isDepthFirstOrdering()) { if (newMethods.length > 0) { if (result.length() > 0) result.append('.'); } int index = callingMethods.indexOf(currentMethod); result.append(newMethods[index]); result.append("()"); } else { if (newMethods.length > 0) { if (result.length() > 0) result.append('.'); if (newMethods.length > 1) { result.append('['); } for (int i = 0; i < newMethods.length; i++) { if (i > 0) result.append(','); result.append(newMethods[i]); result.append("()"); } if (newMethods.length > 1) { result.append(']'); } } } return result.toString(); }
public void buildIndex(JavaCommandLineSource source) { int sourceNum = sources.indexOf(source); for (char c : source.getName().toCharArray()) { c = Character.toLowerCase(c); BitSet charSources = index.get(c); if (charSources == null) { charSources = new BitSet(sources.size()); index.put(c, charSources); } charSources.set(sourceNum); } }
@Nullable private Modifier getWrappersFromStub() { final StubElement parentStub = getStub().getParentStub(); final List childrenStubs = parentStub.getChildrenStubs(); int index = childrenStubs.indexOf(getStub()); if (index >= 0 && index < childrenStubs.size() - 1) { StubElement nextStub = (StubElement) childrenStubs.get(index + 1); if (nextStub instanceof PyTargetExpressionStub) { final PyTargetExpressionStub targetExpressionStub = (PyTargetExpressionStub) nextStub; if (targetExpressionStub.getInitializerType() == PyTargetExpressionStub.InitializerType.CallExpression) { final QualifiedName qualifiedName = targetExpressionStub.getInitializer(); if (QualifiedName.fromComponents(PyNames.CLASSMETHOD).equals(qualifiedName)) { return CLASSMETHOD; } if (QualifiedName.fromComponents(PyNames.STATICMETHOD).equals(qualifiedName)) { return STATICMETHOD; } } } } return null; }
/** * If setting indicates, move all overloaded methods (of the same name) adjacent with the first * encountered. Sort in the configured order (original order, or by number of parameters). */ public static void handleOverloadedMethods( List<ClassContentsEntry> contents, RearrangerSettings settings) { if (!settings.isKeepOverloadedMethodsTogether()) return; /** * first, detect overloaded methods and move them to the first method's list of overloaded * methods. Make two passes, first for extracted methods, then for non-extracted methods. This * will organize any overloaded methods for extracted methods with them (as opposed to whichever * was seen first.) */ cullOverloadedMethods(contents, true); LOG.debug("entered handleOverloadedMethods(): move overloaded methods together"); cullOverloadedMethods(contents, false); List<ClassContentsEntry> copy = new ArrayList<ClassContentsEntry>(contents); for (ClassContentsEntry rangeEntry : copy) { if (rangeEntry instanceof RelatableEntry) { MethodEntry current = (MethodEntry) rangeEntry; if (current.myOverloadedMethods.size() > 0) { List<MethodEntry> newList = new ArrayList<MethodEntry>(current.myOverloadedMethods.size() + 1); newList.add(current); /** * we are looking at the head of a list of overloaded methods. We need to sort the list if * necessary and, if the head of the list has changed, replace it in the contents array. */ switch (settings.getOverloadedOrder()) { case RearrangerSettings.OVERLOADED_ORDER_RETAIN_ORIGINAL: // list is already in original order, except perhaps that the top-most extracted // method // comes first (if there is one). newList.addAll(current.myOverloadedMethods); break; case RearrangerSettings.OVERLOADED_ORDER_ASCENDING_PARAMETERS: case RearrangerSettings.OVERLOADED_ORDER_DESCENDING_PARAMETERS: for (MethodEntry entry : current.myOverloadedMethods) { boolean inserted = false; for (int index = 0; index < newList.size(); index++) { MethodEntry me = newList.get(index); if (settings.getOverloadedOrder() == RearrangerSettings.OVERLOADED_ORDER_ASCENDING_PARAMETERS ? me.getnParameters() > entry.getnParameters() : me.getnParameters() < entry.getnParameters()) { newList.add(index, entry); inserted = true; break; } } if (!inserted) { newList.add(entry); } } break; } current.myOverloadedMethods.clear(); /** * if the head of the arraylist is not the same as "current", then the sort operation * moved another method to the head of the list. Replace that in the contents array. Then * assign a new ordered list. */ int index = contents.indexOf(current); if (newList.get(0) != current) { contents.set(index, ((MethodEntry) newList.get(0))); } /** insert the remaining overloaded methods after the current entry. */ newList.remove(0); for (int j = 0; j < newList.size(); j++) { contents.add(index + j + 1, ((MethodEntry) newList.get(j))); } } } } }
@Override public void valueChanged(MapEvent<String, Integer> e) { int index = types.indexOf(e.getKey()); nodeChanged(getChildAt(index)); }
@Override public void keyRemoved(MapEvent<String, Integer> e) { int index = types.indexOf(e.getKey()); types.remove(index); removeNodeFromParent((MutableTreeNode) getChildAt(index)); }