@Override
 public void visit(Tree.AttributeDeclaration that) {
   if (that.getDeclarationModel() == declaration) {
     Tree.SpecifierOrInitializerExpression sie = that.getSpecifierOrInitializerExpression();
     if (sie != null) {
       super.visit(that);
       specify();
     } else {
       super.visit(that);
       if (declaration.isToplevel() && !isNativeHeader(declaration) && !isLate()) {
         if (isVariable()) {
           that.addError(
               "toplevel variable value must be initialized: '" + declaration.getName() + "'");
         } else {
           that.addError("toplevel value must be specified: '" + declaration.getName() + "'");
         }
       } else if (declaration.isClassOrInterfaceMember()
           && !isNativeHeader(declaration)
           && !declaration.isFormal()
           && that.getDeclarationModel().getInitializerParameter() == null
           && !that.getDeclarationModel().isLate()
           && declarationSection) {
         that.addError(
             "forward declaration may not occur in declaration section: '"
                 + declaration.getName()
                 + "'",
             1450);
       }
     }
   } else {
     super.visit(that);
   }
 }
 @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;
 }
示例#3
0
 private boolean hidesToplevel(Declaration dec) {
   for (Declaration d : unit.getDeclarations()) {
     String n = d.getName();
     if (d.isToplevel() && n != null && dec.getName().equals(n)) {
       return true;
     }
   }
   return false;
 }
示例#4
0
 public static boolean canMoveDeclaration(CeylonEditor editor) {
   Node node = editor.getSelectedNode();
   if (node instanceof Tree.Declaration) {
     Declaration d = ((Tree.Declaration) node).getDeclarationModel();
     return d != null && d.isToplevel();
   } else {
     return false;
   }
 }
 @Override
 public void visit(Tree.MethodDeclaration that) {
   if (that.getDeclarationModel() == declaration) {
     if (that.getSpecifierExpression() != null) {
       specify();
       super.visit(that);
     } else {
       super.visit(that);
       if (declaration.isToplevel() && !isNativeHeader(declaration)) {
         that.addError(
             "toplevel function must be specified: '"
                 + declaration.getName()
                 + "' may not be forward declared");
       } else if (declaration.isClassMember()
           && !isNativeHeader(declaration)
           && isInNativeContainer(declaration)) {
         that.addError(
             "member in native container must be native: '" + declaration.getName() + "'", 1450);
       } else if (declaration.isClassMember()
           && !isNativeHeader(declaration)
           && !declaration.isFormal()
           && that.getDeclarationModel().getInitializerParameter() == null
           && declarationSection) {
         that.addError(
             "forward declaration may not occur in declaration section: '"
                 + declaration.getName()
                 + "'",
             1450);
       } else if (declaration.isInterfaceMember()
           && !isNativeHeader(declaration)
           && !declaration.isFormal()) {
         that.addError(
             "interface method must be formal or specified: '" + declaration.getName() + "'",
             1400);
       }
     }
   } else {
     super.visit(that);
   }
 }
示例#6
0
 private boolean checkForHiddenToplevel(Tree.Identifier id, Import i, Tree.Alias alias) {
   for (Declaration d : unit.getDeclarations()) {
     String n = d.getName();
     Declaration idec = i.getDeclaration();
     if (d.isToplevel()
         && n != null
         && i.getAlias().equals(n)
         && !idec.equals(d)
         &&
         // it is legal to import an object declaration
         // in the current package without providing an
         // alias:
         !isLegalAliasFreeImport(d, idec)) {
       if (alias == null) {
         id.addError("toplevel declaration with this name declared in this unit: '" + n + "'");
       } else {
         alias.addError("toplevel declaration with this name declared in this unit: '" + n + "'");
       }
       return true;
     }
   }
   return false;
 }
示例#7
0
 static void generateCallable(
     final Tree.QualifiedMemberOrTypeExpression that, String name, final GenerateJsVisitor gen) {
   final Declaration d = that.getDeclaration();
   if (that.getPrimary() instanceof Tree.BaseTypeExpression) {
     // it's a static method ref
     if (name == null) {
       name = gen.memberAccess(that, "");
     }
     if (TypeUtils.isConstructor(d)) {
       Constructor cd = TypeUtils.getConstructor(d);
       final boolean hasTargs =
           BmeGenerator.hasTypeParameters((Tree.BaseTypeExpression) that.getPrimary());
       if (hasTargs) {
         if (that.getDirectlyInvoked()) {
           gen.out(
               gen.qualifiedPath(that, cd),
               gen.getNames().constructorSeparator(cd),
               gen.getNames().name(cd));
         } else {
           BmeGenerator.printGenericMethodReference(
               gen,
               (Tree.BaseTypeExpression) that.getPrimary(),
               "0",
               gen.qualifiedPath(that, cd)
                   + gen.getNames().constructorSeparator(cd)
                   + gen.getNames().name(cd));
         }
       } else {
         gen.qualify(that, cd);
         gen.out(gen.getNames().name(cd));
         if (cd.isValueConstructor()) {
           gen.out("()");
         }
       }
     } else if (d.isStatic()) {
       BmeGenerator.generateStaticReference(that, d, gen);
     } else {
       gen.out("function(x){return ");
       if (BmeGenerator.hasTypeParameters(that)) {
         BmeGenerator.printGenericMethodReference(gen, that, "x", "x." + name);
       } else {
         gen.out(gen.getClAlias(), "jsc$3(x,x.", name, ")");
       }
       gen.out(";}");
     }
     return;
   }
   if (d.isToplevel() && d instanceof Function) {
     // Just output the name
     gen.out(gen.getNames().name(d));
     return;
   }
   String primaryVar = gen.createRetainedTempVar();
   gen.out("(", primaryVar, "=");
   that.getPrimary().visit(gen);
   if (!(that.getStaticMethodReferencePrimary()
       && !TypeUtils.isConstructor(that.getDeclaration()))) {
     gen.out(",");
     final String member =
         (name == null) ? gen.memberAccess(that, primaryVar) : (primaryVar + "." + name);
     if (that.getDeclaration() instanceof Function
         && !((Function) that.getDeclaration()).getTypeParameters().isEmpty()) {
       // Function ref with type parameters
       BmeGenerator.printGenericMethodReference(gen, that, primaryVar, member);
     } else {
       if (that.getUnit().isOptionalType(that.getPrimary().getTypeModel())) {
         gen.out(
             gen.getClAlias(),
             "jsc$3(",
             primaryVar,
             ",",
             gen.getClAlias(),
             "nn$(",
             primaryVar,
             ")?",
             member,
             ":null)");
       } else {
         gen.out(gen.getClAlias(), "jsc$3(", primaryVar, ",", member, ")");
       }
     }
   }
   gen.out(")");
 }
 private boolean isForwardReferenceable() {
   return declarationSection || declaration.isToplevel() || declaration.isInterfaceMember();
 }
 protected void refactorJavaReferences(IProgressMonitor pm, final CompositeChange cc) {
   final Map<IResource, TextChange> changes = new HashMap<IResource, TextChange>();
   SearchEngine searchEngine = new SearchEngine();
   IProject[] projects = getProjectAndReferencingProjects(project);
   final String pattern;
   try {
     pattern = getJavaNameOfDeclaration(declaration);
   } catch (Exception e) {
     return;
   }
   boolean anonymous = pattern.endsWith(".get_");
   if (!anonymous) {
     SearchPattern searchPattern = createSearchPattern(declaration, REFERENCES);
     if (searchPattern == null) return;
     SearchRequestor requestor =
         new SearchRequestor() {
           @Override
           public void acceptSearchMatch(SearchMatch match) {
             String filename = match.getResource().getName();
             boolean isJavaFile = JavaCore.isJavaLikeFileName(filename);
             if (isJavaFile) {
               TextChange change = canonicalChange(cc, changes, match);
               if (change != null) {
                 int loc = pattern.lastIndexOf('.') + 1;
                 String oldName = pattern.substring(loc);
                 if (declaration instanceof Value) {
                   change.addEdit(
                       new ReplaceEdit(
                           match.getOffset() + 3,
                           oldName.length() - 3,
                           escaping_.get_().toInitialUppercase(newName)));
                 } else {
                   change.addEdit(
                       new ReplaceEdit(
                           match.getOffset(),
                           oldName.length(),
                           oldName.startsWith("$") ? '$' + newName : newName));
                 }
               }
             }
           }
         };
     runSearch(pm, searchEngine, searchPattern, projects, requestor);
   }
   if (anonymous || declaration instanceof FunctionOrValue && declaration.isToplevel()) {
     int loc = pattern.lastIndexOf('.');
     SearchPattern searchPattern =
         createPattern(pattern.substring(0, loc), CLASS_AND_INTERFACE, REFERENCES, R_EXACT_MATCH);
     SearchRequestor requestor =
         new SearchRequestor() {
           @Override
           public void acceptSearchMatch(SearchMatch match) {
             TextChange change = canonicalChange(cc, changes, match);
             if (change != null) {
               int end = pattern.lastIndexOf("_.");
               int start = pattern.substring(0, end).lastIndexOf('.') + 1;
               String oldName = pattern.substring(start, end);
               change.addEdit(new ReplaceEdit(match.getOffset(), oldName.length(), newName));
             }
           }
         };
     runSearch(pm, searchEngine, searchPattern, projects, requestor);
   }
 }