Package com.google.gwt.core.ext.typeinfo

Examples of com.google.gwt.core.ext.typeinfo.CompilationUnitProvider


    checkForErrors(logger, false);

    // Find the newest of all these.
    //
    lastModified = 0;
    CompilationUnitProvider newestCup = null;
    for (int i = 0; i < goldenCuds.length; i++) {
      CompilationUnitDeclaration cud = goldenCuds[i];
      ICompilationUnitAdapter icua = (ICompilationUnitAdapter) cud.compilationResult.compilationUnit;
      CompilationUnitProvider cup = icua.getCompilationUnitProvider();
      long cupLastModified = cup.getLastModified();
      if (cupLastModified > lastModified) {
        newestCup = cup;
        lastModified = cupLastModified;
      }
    }
View Full Code Here


        for (Iterator iter = committedGeneratedCups.iterator(); iter.hasNext();) {
          GeneratedCompilationUnitProvider gcup = (GeneratedCompilationUnitProvider) iter.next();
          String typeName = gcup.getTypeName();
          String genTypeName = gcup.getPackageName() + "." + typeName;
          genTypeNames.add(genTypeName);
          CompilationUnitProvider cup = writeSource(logger, gcup, typeName);
          builder.addCompilationUnit(cup);
          cacheManager.addGeneratedCup(cup);
         
          if (subBranch != null) {
            subBranch.log(TreeLogger.DEBUG, cup.getLocation(), null);
          }
        }
       
        builder.build(branch);
      }

      // Return the generated types.
      JClassType[] genTypes = new JClassType[genTypeNames.size()];
      int next = 0;
      for (Iterator iter = genTypeNames.iterator(); iter.hasNext();) {
        String genTypeName = (String) iter.next();
        try {
          genTypes[next++] = typeOracle.getType(genTypeName);
        } catch (NotFoundException e) {
          String msg = "Unable to find recently-generated type '" + genTypeName;
          logger.log(TreeLogger.ERROR, msg, null);
          throw new UnableToCompleteException();
        }
      }
      return genTypes;
    } finally {

      // Remind the user if there uncommitted cups.
      if (!uncommittedGeneratedCupsByPrintWriter.isEmpty()) {
        String msg = "For the following type(s), generated source was never committed (did you forget to call commit()?)";
        logger = logger.branch(TreeLogger.WARN, msg, null);

        for (Iterator iter = uncommittedGeneratedCupsByPrintWriter.values().iterator(); iter.hasNext();) {
          StaticCompilationUnitProvider cup = (StaticCompilationUnitProvider) iter.next();
          String typeName = cup.getPackageName() + "." + cup.getTypeName();
          logger.log(TreeLogger.WARN, typeName, null);
        }
      }

      uncommittedGeneratedCupsByPrintWriter.clear();
View Full Code Here

    }

    // Otherwise, it's a regular translatable type, but we want to make sure
    // its JSNI stuff, if any, gets handled.
    //
    CompilationUnitProvider jsnified = injector.inject(logger, existing);
    return jsnified;
  }
View Full Code Here

    checkForErrors(logger, false);

    // Find the newest of all these.
    //
    lastModified = 0;
    CompilationUnitProvider newestCup = null;
    for (int i = 0; i < goldenCuds.length; i++) {
      CompilationUnitDeclaration cud = goldenCuds[i];
      ICompilationUnitAdapter icua = (ICompilationUnitAdapter) cud.compilationResult.compilationUnit;
      CompilationUnitProvider cup = icua.getCompilationUnitProvider();
      long cupLastModified = cup.getLastModified();
      if (cupLastModified > lastModified) {
        newestCup = cup;
        lastModified = cupLastModified;
      }
    }
View Full Code Here

  public final CompilationUnitProvider findCompilationUnit(TreeLogger logger,
      String typeName) throws UnableToCompleteException {

    // Check the cache first.
    //
    CompilationUnitProvider cup = (CompilationUnitProvider) cupsByTypeName.get(typeName);

    if (cup != null) {
      // Found in cache.
      //
      return cup;
    }

    // See if the type oracle can find it.
    //
    JClassType type = typeOracle.findType(typeName);
    if (type != null) {
      // All type oracle types are supposed to know their compilation unit.
      //
      cup = type.getCompilationUnit();
      assert (cup != null);
    }

    // Give the subclass a chance to replace the source. This used for JSNI in
    // hosted mode at present but could be used for any source rewriting trick.
    //
    if (cup != null) {
      try {
        CompilationUnitProvider specialCup = doFilterCompilationUnit(logger,
            typeName, cup);

        if (specialCup != null) {
          // Use the cup that the subclass returned instead. Note that even
          // though this file may not exist on disk, it is special so we don't
View Full Code Here

      //
      int pos = qname.indexOf('$');
      if (pos >= 0) {
        qname = qname.substring(0, pos);
      }
      CompilationUnitProvider cup;
      try {
        cup = sourceOracle.findCompilationUnit(logger, qname);
        if (cup != null) {
          logger.log(TreeLogger.SPAM, "Found type in compilation unit: "
              + cup.getLocation(), null);
          ICompilationUnitAdapter unit = new ICompilationUnitAdapter(cup);
          NameEnvironmentAnswer out = new NameEnvironmentAnswer(unit, null);
          nameEnvironmentAnswerForTypeName.put(qname, out);
          return out;
        } else {
View Full Code Here

    Set addedCups = cacheManager.getAddedCups();
    TypeOracle oracle = cacheManager.getTypeOracle();
    // Make a copy that we can sort.
    //
    for (Iterator iter = addedCups.iterator(); iter.hasNext();) {
      CompilationUnitProvider cup = (CompilationUnitProvider) iter.next();
      String location = cup.getLocation();
      if (!((location.indexOf("http://") != -1) || (location.indexOf("ftp://") != -1))) {
        location = Util.findFileName(location);
        if (!(new File(location).exists() || cup.isTransient())) {
          iter.remove();
          logger.log(
              TreeLogger.TRACE,
              "The file "
                  + location
                  + " was removed by the user.  All types therein are now unavailable.",
              null);
        }
      }
    }
    CompilationUnitProvider[] cups = (CompilationUnitProvider[]) Util.toArray(
        CompilationUnitProvider.class, addedCups);
    Arrays.sort(cups, CompilationUnitProvider.LOCATION_COMPARATOR);

    // Make sure we can find the java.lang.Object compilation unit.
    //
    boolean foundJavaLangPackage = oracle.findPackage("java.lang") != null;

    // Adapt to JDT idioms.
    //
    ICompilationUnit[] units = new ICompilationUnit[cups.length];
    for (int i = 0; i < cups.length; i++) {
      if (!foundJavaLangPackage && cups[i].getPackageName().equals("java.lang")) {
        foundJavaLangPackage = true;
      }
      units[i] = cacheManager.findUnitForCup(cups[i]);
    }

    // Error if no java.lang.
    if (!foundJavaLangPackage) {
      Util.logMissingTypeErrorWithHints(logger, "java.lang.Object");
      throw new UnableToCompleteException();
    }
    cacheManager.invalidateOnRefresh(oracle);
    CompilationUnitDeclaration[] cuds = cacheManager.getAstCompiler().getCompilationUnitDeclarations(
        logger, units);

    // Build a list that makes it easy to remove problems.
    //
    final Map cudsByFileName = new HashMap();
    for (int i = 0; i < cuds.length; i++) {
      CompilationUnitDeclaration cud = cuds[i];
      char[] location = cud.getFileName();
      cudsByFileName.put(String.valueOf(location), cud);
    }
    cacheManager.getCudsByFileName().putAll(cudsByFileName);

    // Remove bad cuds and all the other cuds that are affected.
    //
    removeUnitsWithErrors(logger, cudsByFileName);

    // Also remove any compilation units that we've seen before.
    //
    for (Iterator iter = cudsByFileName.values().iterator(); iter.hasNext();) {
      CompilationUnitDeclaration cud = (CompilationUnitDeclaration) iter.next();
      // If we've seen this compilation unit before, the type oracle will
      // tell us about it and so we don't assimilate it again.
      //
      ICompilationUnit unit = cud.compilationResult.compilationUnit;
      ICompilationUnitAdapter adapter = ((ICompilationUnitAdapter) unit);
      CompilationUnitProvider cup = adapter.getCompilationUnitProvider();
      JClassType[] seen = oracle.getTypesInCompilationUnit(cup);
      if (seen.length > 0) {
        // This compilation unit has already been assimilated.
        //
        iter.remove();
View Full Code Here

    }

    String jpkgName = getPackage(typeDecl);
    JPackage pkg = oracle.getOrCreatePackage(jpkgName);
    final boolean jclassIsIntf = isInterface(typeDecl);
    CompilationUnitProvider cup = getCup(typeDecl);

    int declStart = typeDecl.declarationSourceStart;
    int declEnd = typeDecl.declarationSourceEnd;
    int bodyStart = typeDecl.bodyStart;
    int bodyEnd = typeDecl.bodyEnd;
View Full Code Here

    List newUnits = new ArrayList();

    // Check for newer units that need to be processed.
    for (Iterator iter = allUnits.iterator(); iter.hasNext();) {
      ICompilationUnitAdapter adapter = (ICompilationUnitAdapter) iter.next();
      CompilationUnitProvider cup = adapter.getCompilationUnitProvider();
      String location = cup.getLocation();
      if (!(cachedResults.containsKey(location))) {
        newUnits.add(adapter);
      }
    }
    ICompilationUnit[] toBeProcessed = new ICompilationUnit[newUnits.size()];
View Full Code Here

      return unit;
    }

    // Not cached, so actually look for it.
    //
    CompilationUnitProvider cup = sourceOracle.findCompilationUnit(logger, top);
    if (cup == null) {
      // Could not find the starting type.
      //
      String s = "Unable to find compilation unit for type '" + top + "'";
      logger.log(TreeLogger.WARN, s, null);
View Full Code Here

TOP

Related Classes of com.google.gwt.core.ext.typeinfo.CompilationUnitProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.