Пример #1
0
 @Override
 public Object[] getChildren(Object element) {
   if (element instanceof CeylonOutlineNode) {
     if (mode) {
       boolean includeParameters = !CeylonPlugin.getPreferences().getBoolean(PARAMS_IN_OUTLINES);
       CeylonOutlineNode node = (CeylonOutlineNode) element;
       CompilationUnit rootNode = getEditor().getParseController().getLastCompilationUnit();
       Node treeNode = Nodes.findNode(rootNode, node.getStartOffset(), node.getEndOffset());
       TypeDeclaration td;
       if (treeNode instanceof ClassOrInterface) {
         ClassOrInterface ci = (ClassOrInterface) treeNode;
         td = ci.getDeclarationModel();
       } else if (treeNode instanceof ObjectDefinition) {
         ObjectDefinition od = (ObjectDefinition) treeNode;
         td = od.getDeclarationModel().getTypeDeclaration();
       } else {
         return super.getChildren(element);
       }
       List<Declaration> list = new ArrayList<Declaration>();
       String filter = getFilterText().getText();
       for (int i = 0; i < filter.length(); i++) {
         char ch = filter.charAt(i);
         if (ch == '*' || i > 0 && Character.isUpperCase(ch)) {
           filter = filter.substring(0, i);
           break;
         }
       }
       Collection<DeclarationWithProximity> members =
           td.getMatchingMemberDeclarations(rootNode.getUnit(), td, filter, 0, null).values();
       for (DeclarationWithProximity dwp : members) {
         for (Declaration dec : overloads(dwp.getDeclaration())) {
           if (!(dec instanceof TypeParameter)) {
             if (includeParameters || !dec.isParameter()) {
               list.add(dec);
             }
           }
         }
       }
       if (!lexicalSortingAction.isChecked()) {
         Collections.sort(
             list,
             new Comparator<Declaration>() {
               public int compare(Declaration x, Declaration y) {
                 String xn = x.getContainer().getQualifiedNameString();
                 String yn = y.getContainer().getQualifiedNameString();
                 return xn.compareTo(yn);
               }
             });
       }
       return list.toArray();
     } else {
       return super.getChildren(element);
     }
   } else {
     return null;
   }
 }
 public static List<DeclarationWithProximity> getSortedProposedValues(
     Scope scope, Unit unit, final String exactName) {
   Map<String, DeclarationWithProximity> map = scope.getMatchingDeclarations(unit, "", 0, null);
   if (exactName != null) {
     for (DeclarationWithProximity dwp : new ArrayList<DeclarationWithProximity>(map.values())) {
       if (!dwp.isUnimported() && !dwp.isAlias() && isNameMatching(dwp.getName(), exactName)) {
         map.put(dwp.getName(), new DeclarationWithProximity(dwp.getDeclaration(), -5));
       }
     }
   }
   List<DeclarationWithProximity> results = new ArrayList<DeclarationWithProximity>(map.values());
   Collections.sort(results, new ArgumentProposalComparator(exactName));
   return results;
 }
 @Override
 public int compare(DeclarationWithProximity x, DeclarationWithProximity y) {
   String xname = x.getName();
   String yname = y.getName();
   if (exactName != null) {
     boolean xhit = xname.equals(exactName);
     boolean yhit = yname.equals(exactName);
     if (xhit && !yhit) {
       return -1;
     }
     if (yhit && !xhit) {
       return 1;
     }
     xhit = isNameMatching(xname, exactName);
     yhit = isNameMatching(yname, exactName);
     if (xhit && !yhit) {
       return -1;
     }
     if (yhit && !xhit) {
       return 1;
     }
   }
   Declaration xd = x.getDeclaration();
   Declaration yd = y.getDeclaration();
   boolean xdepr = xd.isDeprecated();
   boolean ydepr = yd.isDeprecated();
   if (xdepr && !ydepr) {
     return 1;
   }
   if (!xdepr && ydepr) {
     return -1;
   }
   int xp = x.getProximity();
   int yp = y.getProximity();
   int p = xp - yp;
   if (p != 0) {
     return p;
   }
   int c = xname.compareTo(yname);
   if (c != 0) {
     return c;
   }
   return xd.getQualifiedNameString().compareTo(yd.getQualifiedNameString());
 }
  @Deprecated
  // replaced by RefineFormalMembersQuickFix.ceylon
  private void refineFormalMembers(IDocument document) throws ExecutionException {
    if (rootNode == null) return;
    TextChange change = new DocumentChange("Refine Members", document);
    change.setEdit(new MultiTextEdit());
    // TODO: copy/pasted from CeylonQuickFixAssistant
    Tree.Body body;
    int offset;
    if (node instanceof Tree.ClassDefinition) {
      ClassDefinition classDefinition = (Tree.ClassDefinition) node;
      body = classDefinition.getClassBody();
      offset = -1;
    } else if (node instanceof Tree.InterfaceDefinition) {
      Tree.InterfaceDefinition interfaceDefinition = (Tree.InterfaceDefinition) node;
      body = interfaceDefinition.getInterfaceBody();
      offset = -1;
    } else if (node instanceof Tree.ObjectDefinition) {
      Tree.ObjectDefinition objectDefinition = (Tree.ObjectDefinition) node;
      body = objectDefinition.getClassBody();
      offset = -1;
    } else if (node instanceof Tree.ObjectExpression) {
      Tree.ObjectExpression objectExpression = (Tree.ObjectExpression) node;
      body = objectExpression.getClassBody();
      offset = -1;
    } else if (node instanceof Tree.ClassBody || node instanceof Tree.InterfaceBody) {
      body = (Tree.Body) node;
      IEditorPart editor = getCurrentEditor();
      if (editor instanceof CeylonEditor) {
        CeylonEditor ce = (CeylonEditor) editor;
        offset = ce.getSelection().getOffset();
      } else {
        offset = -1;
      }
    } else {
      return;
    }
    if (body == null) {
      return;
    }
    boolean isInterface = body instanceof Tree.InterfaceBody;
    List<Tree.Statement> statements = body.getStatements();
    String indent;
    //        String bodyIndent = getIndent(body, document);
    String bodyIndent = utilJ2C().indents().getIndent(node, document);
    String delim = utilJ2C().indents().getDefaultLineDelimiter(document);
    if (statements.isEmpty()) {
      indent = delim + bodyIndent + utilJ2C().indents().getDefaultIndent();
      if (offset < 0) {
        offset = body.getStartIndex() + 1;
      }
    } else {
      Tree.Statement statement = statements.get(statements.size() - 1);
      indent = delim + utilJ2C().indents().getIndent(statement, document);
      if (offset < 0) {
        offset = statement.getEndIndex();
      }
    }
    StringBuilder result = new StringBuilder();
    Set<Declaration> already = new HashSet<Declaration>();
    ClassOrInterface ci = (ClassOrInterface) node.getScope();
    Unit unit = node.getUnit();
    Set<String> ambiguousNames = new HashSet<String>();
    // TODO: does not return unrefined overloaded
    //      versions of a method with one overlaad
    //      already refined
    Collection<DeclarationWithProximity> proposals =
        ci.getMatchingMemberDeclarations(unit, ci, "", 0).values();
    for (DeclarationWithProximity dwp : proposals) {
      Declaration dec = dwp.getDeclaration();
      for (Declaration d : overloads(dec)) {
        try {
          if (d.isFormal() && ci.isInheritedFromSupertype(d)) {
            appendRefinementText(isInterface, indent, result, ci, unit, d);
            importProposals().importSignatureTypes(d, rootNode, already);
            ambiguousNames.add(d.getName());
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    for (TypeDeclaration superType : ci.getSupertypeDeclarations()) {
      for (Declaration m : superType.getMembers()) {
        try {
          if (m.getName() != null && m.isShared()) {
            Declaration r = ci.getMember(m.getName(), null, false);
            if ((r == null || !r.refines(m) && !r.getContainer().equals(ci))
                && ambiguousNames.add(m.getName())) {
              appendRefinementText(isInterface, indent, result, ci, unit, m);
              importProposals().importSignatureTypes(m, rootNode, already);
            }
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }

    try {
      if (document.getChar(offset) == '}' && result.length() > 0) {
        result.append(delim).append(bodyIndent);
      }
    } catch (BadLocationException e) {
      e.printStackTrace();
    }
    importProposals().applyImports(change, already, rootNode, document);
    change.addEdit(new InsertEdit(offset, result.toString()));
    change.initializeValidationData(null);
    try {
      getWorkspace().run(new PerformChangeOperation(change), new NullProgressMonitor());
    } catch (CoreException ce) {
      ce.printStackTrace();
    }
  }