Ejemplo n.º 1
0
 private boolean isSharedDeclarationUninitialized() {
   return (declaration.isShared() || declaration.getOtherInstanceAccess())
       && !declaration.isFormal()
       && !isNativeHeader(declaration)
       && !isLate()
       && !specified.definitely;
 }
 @Override
 public boolean isAffectingOtherFiles() {
   if (declaration == null) {
     return false;
   }
   if (declaration.isToplevel() || declaration.isShared()) {
     return true;
   }
   if (declaration.isParameter()) {
     FunctionOrValue fov = (FunctionOrValue) declaration;
     Declaration container = fov.getInitializerParameter().getDeclaration();
     if (container.isToplevel() || container.isShared()) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 3
0
 private void importAllMembers(
     TypeDeclaration importedType, Set<String> ignoredMembers, ImportList til) {
   for (Declaration dec : importedType.getMembers()) {
     if (dec.isShared()
         && (dec.isStaticallyImportable() || isConstructor(dec))
         && isResolvable(dec)
         && !ignoredMembers.contains(dec.getName())) {
       addWildcardImport(til, dec, importedType);
     }
   }
 }
Ejemplo n.º 4
0
 private void importAllMembers(
     Package importedPackage, Set<String> ignoredMembers, ImportList il) {
   for (Declaration dec : importedPackage.getMembers()) {
     if (dec.isShared()
         && isResolvable(dec)
         && !ignoredMembers.contains(dec.getName())
         && !isNonimportable(importedPackage, dec.getName())) {
       addWildcardImport(il, dec);
     }
   }
 }
Ejemplo n.º 5
0
 @Override
 public boolean select(Viewer viewer, Object parentElement, Object element) {
   if (element instanceof CeylonOutlineNode) {
     CeylonOutlineNode node = (CeylonOutlineNode) element;
     return node.isShared();
   } else if (element instanceof Declaration) {
     Declaration dec = (Declaration) element;
     return dec.isShared();
   } else {
     return true;
   }
 }
Ejemplo n.º 6
0
 public static Declaration getRefinedDeclaration(Declaration declaration) {
   // Reproduces the algorithm used to build the type hierarchy
   // first walk up the superclass hierarchy
   if (declaration.isClassOrInterfaceMember() && declaration.isShared()) {
     TypeDeclaration dec = (TypeDeclaration) declaration.getContainer();
     List<Type> signature = getSignature(declaration);
     Declaration refined = declaration.getRefinedDeclaration();
     while (dec != null) {
       Type extended = dec.getExtendedType();
       if (extended != null) {
         TypeDeclaration superDec = extended.getDeclaration();
         Declaration superMemberDec =
             superDec.getDirectMember(declaration.getName(), signature, false);
         if (superMemberDec != null) {
           Declaration superRefined = superMemberDec.getRefinedDeclaration();
           if (superRefined != null
               && refined != null
               && !isAbstraction(superMemberDec)
               && superRefined.equals(refined)) {
             return superMemberDec;
           }
         }
         dec = superDec;
       } else {
         dec = null;
       }
     }
     // now look at the very top of the hierarchy, even if it is an interface
     Declaration refinedDeclaration = refined;
     if (refinedDeclaration != null && !declaration.equals(refinedDeclaration)) {
       List<Declaration> directlyInheritedMembers =
           getInterveningRefinements(
               declaration.getName(),
               signature,
               refinedDeclaration,
               (TypeDeclaration) declaration.getContainer(),
               (TypeDeclaration) refinedDeclaration.getContainer());
       directlyInheritedMembers.remove(refinedDeclaration);
       // TODO: do something for the case of
       //      multiple intervening interfaces?
       if (directlyInheritedMembers.size() == 1) {
         // exactly one intervening interface
         return directlyInheritedMembers.get(0);
       } else {
         // no intervening interfaces
         return refinedDeclaration;
       }
     }
   }
   return null;
 }
Ejemplo n.º 7
0
 public static boolean isUnsharedUsedLocally(
     Tree.Declaration node, IFile originalFile, String originalPackage, String targetPackage) {
   Declaration dec = node.getDeclarationModel();
   if (!dec.isShared() && !originalPackage.equals(targetPackage)) {
     for (PhasedUnit pu : getAllUnits(originalFile.getProject())) {
       Tree.CompilationUnit cu = pu.getCompilationUnit();
       String pn = cu.getUnit().getPackage().getNameAsString();
       if (pn.equals(originalPackage) && isUsedInUnit(cu, dec)) {
         return true;
       }
     }
   }
   return false;
 }
Ejemplo n.º 8
0
 private String importMember(
     Tree.ImportMemberOrType member, Package importedPackage, ImportList il) {
   Tree.Identifier id = member.getIdentifier();
   if (id == null) {
     return null;
   }
   Import i = new Import();
   member.setImportModel(i);
   Tree.Alias alias = member.getAlias();
   String name = name(id);
   if (alias == null) {
     i.setAlias(name);
   } else {
     i.setAlias(name(alias.getIdentifier()));
   }
   if (isNonimportable(importedPackage, name)) {
     id.addError("root type may not be imported");
     return name;
   }
   Declaration d = importedPackage.getMember(name, null, false);
   if (d == null) {
     String correction = correct(importedPackage, unit, name);
     String message = correction == null ? "" : " (did you mean '" + correction + "'?)";
     id.addError("imported declaration not found: '" + name + "'" + message, 100);
     unit.getUnresolvedReferences().add(id);
   } else {
     if (!declaredInPackage(d, unit)) {
       if (!d.isShared()) {
         id.addError("imported declaration is not shared: '" + name + "'", 400);
       } else if (d.isPackageVisibility()) {
         id.addError("imported package private declaration is not visible: '" + name + "'");
       } else if (d.isProtectedVisibility()) {
         id.addError("imported protected declaration is not visible: '" + name + "'");
       }
     }
     i.setDeclaration(d);
     member.setDeclarationModel(d);
     if (il.hasImport(d)) {
       id.addError("already imported: '" + name + "'");
     } else if (!checkForHiddenToplevel(id, i, alias)) {
       addImport(member, il, i);
     }
     checkAliasCase(alias, d);
   }
   if (d != null) {
     importMembers(member, d);
   }
   return name;
 }
Ejemplo n.º 9
0
 private String importMember(Tree.ImportMemberOrType member, TypeDeclaration td, ImportList il) {
   Tree.Identifier id = member.getIdentifier();
   if (id == null) {
     return null;
   }
   Import i = new Import();
   member.setImportModel(i);
   Tree.Alias alias = member.getAlias();
   String name = name(id);
   if (alias == null) {
     i.setAlias(name);
   } else {
     i.setAlias(name(alias.getIdentifier()));
   }
   Declaration m = td.getMember(name, null, false);
   if (m == null) {
     String correction = correct(td, null, unit, name);
     String message = correction == null ? "" : " (did you mean '" + correction + "'?)";
     id.addError(
         "imported declaration not found: '" + name + "' of '" + td.getName() + "'" + message,
         100);
     unit.getUnresolvedReferences().add(id);
   } else {
     List<Declaration> members = m.getContainer().getMembers();
     for (Declaration d : members) {
       String dn = d.getName();
       if (dn != null && dn.equals(name) && !d.sameKind(m) && !d.isAnonymous()) {
         // crazy interop cases like isOpen() + open()
         id.addError("ambiguous member declaration: '" + name + "' of '" + td.getName() + "'");
         return null;
       }
     }
     if (!m.isShared()) {
       id.addError(
           "imported declaration is not shared: '" + name + "' of '" + td.getName() + "'", 400);
     } else if (!declaredInPackage(m, unit)) {
       if (m.isPackageVisibility()) {
         id.addError(
             "imported package private declaration is not visible: '"
                 + name
                 + "' of '"
                 + td.getName()
                 + "'");
       } else if (m.isProtectedVisibility()) {
         id.addError(
             "imported protected declaration is not visible: '"
                 + name
                 + "' of '"
                 + td.getName()
                 + "'");
       }
     }
     i.setTypeDeclaration(td);
     if (!m.isStaticallyImportable()
         && !isToplevelClassConstructor(td, m)
         && !isToplevelAnonymousClass(m.getContainer())) {
       if (alias == null) {
         member.addError("does not specify an alias");
       }
     }
     i.setDeclaration(m);
     member.setDeclarationModel(m);
     if (il.hasImport(m)) {
       id.addError("already imported: '" + name + "' of '" + td.getName() + "'");
     } else {
       if (m.isStaticallyImportable()
           || isToplevelClassConstructor(td, m)
           || isToplevelAnonymousClass(m.getContainer())) {
         if (!checkForHiddenToplevel(id, i, alias)) {
           addImport(member, il, i);
         }
       } else {
         addMemberImport(member, il, i);
       }
     }
     checkAliasCase(alias, m);
   }
   if (m != null) {
     importMembers(member, m);
   }
   // imtl.addError("member aliases may not have member aliases");
   return name;
 }
  @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();
    }
  }