コード例 #1
0
ファイル: Unit.java プロジェクト: etirelli/ceylon-spec
 @Override
 public boolean equals(Object obj) {
   if (obj instanceof Unit) {
     Unit that = (Unit) obj;
     return that.getPackage().equals(getPackage()) && that.getFilename().equals(getFilename());
   } else {
     return false;
   }
 }
コード例 #2
0
 @Override
 public void removeUnit(Unit unit) {
   synchronized (modelLoader) {
     if (lazyUnits.remove(unit)) {
       for (Declaration d : unit.getDeclarations()) {
         compiledDeclarations.remove(d);
         // TODO : remove the declaration from the declaration map in AbstractModelLoader
       }
       modelLoader.removeDeclarations(unit.getDeclarations());
     } else {
       super.removeUnit(unit);
     }
   }
 }
コード例 #3
0
 private CollectionLiteralAnnotationTerm startCollection(Tree.Term t) {
   Unit unit = t.getUnit();
   // Continue the visit to collect the elements
   ProducedType iteratedType = unit.getIteratedType(parameter().getType());
   TypeDeclaration declaration = iteratedType.getDeclaration();
   LiteralAnnotationTerm factory;
   if (unit.getStringDeclaration().equals(declaration)) {
     factory = StringLiteralAnnotationTerm.FACTORY;
   } else if (unit.getIntegerDeclaration().equals(declaration)) {
     factory = IntegerLiteralAnnotationTerm.FACTORY;
   } else if (unit.getCharacterDeclaration().equals(declaration)) {
     factory = CharacterLiteralAnnotationTerm.FACTORY;
   } else if (unit.getBooleanDeclaration().equals(declaration)) {
     factory = BooleanLiteralAnnotationTerm.FACTORY;
   } else if (unit.getFloatDeclaration().equals(declaration)) {
     factory = FloatLiteralAnnotationTerm.FACTORY;
   } else if (Decl.isEnumeratedTypeWithAnonCases(iteratedType)) {
     factory = ObjectLiteralAnnotationTerm.FACTORY;
   } else if (Decl.isAnnotationClass(declaration)) {
     t.addError(
         "compiler bug: iterables of annotation classes or annotation constructors not supported as literal "
             + (checkingDefaults ? "defaulted parameters" : "arguments"));
     return null;
   } else if (iteratedType.isSubtypeOf(
       ((TypeDeclaration) unit.getLanguageModuleDeclarationDeclaration("Declaration"))
           .getType())) {
     factory = DeclarationLiteralAnnotationTerm.FACTORY;
   } else {
     throw new RuntimeException();
   }
   CollectionLiteralAnnotationTerm result = this.elements;
   this.elements = new CollectionLiteralAnnotationTerm(factory);
   return result;
 }
コード例 #4
0
 private static void addPackageCompletions(
     final int offset,
     final String prefix,
     Node node,
     List<ICompletionProposal> result,
     final int len,
     String pfp,
     final CeylonParseController cpc,
     final boolean withBody) {
   // TODO: someday it would be nice to propose from all packages
   //      and auto-add the module dependency!
   /*TypeChecker tc = CeylonBuilder.getProjectTypeChecker(cpc.getProject().getRawProject());
   if (tc!=null) {
   for (Module m: tc.getContext().getModules().getListOfModules()) {*/
   // Set<Package> packages = new HashSet<Package>();
   Unit unit = node.getUnit();
   if (unit != null) { // a null unit can occur if we have not finished parsing the file
     Module module = unit.getPackage().getModule();
     for (final Package p : module.getAllPackages()) {
       // if (!packages.contains(p)) {
       // packages.add(p);
       // if ( p.getModule().equals(module) || p.isShared() ) {
       final String pkg = escapePackageName(p);
       if (!pkg.isEmpty() && pkg.startsWith(pfp)) {
         boolean already = false;
         if (!pfp.equals(pkg)) {
           // don't add already imported packages, unless
           // it is an exact match to the typed path
           for (ImportList il : node.getUnit().getImportLists()) {
             if (il.getImportedScope() == p) {
               already = true;
               break;
             }
           }
         }
         if (!already) {
           result.add(
               new PackageProposal(
                   offset, prefix, withBody, len, p, pkg + (withBody ? " { ... }" : ""), cpc));
         }
       }
       // }
     }
   }
 }
コード例 #5
0
 /**
  * Is the most-refined member with the given name, searching this type first, taking aliases into
  * account, followed by supertypes, ambiguous, because we could not construct a principal
  * instantiation for an intersection? TODO: this information should really be encoded into the
  * return value of getMember() but I'm leaving it like this for now to avoid breaking the backends
  */
 public boolean isMemberAmbiguous(
     String name, Unit unit, List<ProducedType> signature, boolean variadic) {
   // TODO: does not handle aliased members of supertypes
   Declaration d = unit.getImportedDeclaration(this, name, signature, variadic);
   if (d == null) {
     return getMemberInternal(name, signature, variadic).isAmbiguous();
   } else {
     return false;
   }
 }
コード例 #6
0
  private boolean isConstantValue(Declaration d) {
    if (d instanceof Value) {
      Value value = (Value) d;
      if (value.isShared() && !value.isVariable()) {
        Unit unit = value.getUnit();
        TypeDeclaration type = value.getTypeDeclaration();

        if (type == unit.getSequentialDeclaration()) {
          ProducedType elementType = unit.getIteratedType(value.getType());
          type = elementType.getDeclaration();
        }

        if (unit.getStringDeclaration().equals(type)
            || unit.getIntegerDeclaration().equals(type)
            || unit.getFloatDeclaration().equals(type)
            || unit.getCharacterDeclaration().equals(type)) {
          return true;
        }
      }
    }
    return false;
  }
コード例 #7
0
 public String getProducedTypeName(boolean abbreviate) {
   if (getDeclaration() == null) {
     // unknown type
     return null;
   }
   if (abbreviate && getDeclaration() instanceof UnionType) {
     UnionType ut = (UnionType) getDeclaration();
     if (ut.getCaseTypes().size() == 2) {
       Unit unit = getDeclaration().getUnit();
       if (Util.isElementOfUnion(ut, unit.getNothingDeclaration())) {
         return unit.getDefiniteType(this).getProducedTypeName() + "?";
       }
       if (Util.isElementOfUnion(ut, unit.getEmptyDeclaration())
           && Util.isElementOfUnion(ut, unit.getSequenceDeclaration())) {
         return unit.getElementType(this).getProducedTypeName() + "[]";
       }
     }
   }
   String producedTypeName = "";
   if (getDeclaration().isMember()) {
     producedTypeName += getQualifyingType().getProducedTypeName(abbreviate);
     producedTypeName += ".";
   }
   producedTypeName += getDeclaration().getName();
   if (!getTypeArgumentList().isEmpty()) {
     producedTypeName += "<";
     for (ProducedType t : getTypeArgumentList()) {
       if (t == null) {
         producedTypeName += "unknown,";
       } else {
         producedTypeName += t.getProducedTypeName(abbreviate) + ",";
       }
     }
     producedTypeName += ">";
     producedTypeName = producedTypeName.replace(",>", ">");
   }
   return producedTypeName;
 }