org.plovr
Class AbstractJsInput

java.lang.Object
  extended by org.plovr.AbstractJsInput
All Implemented Interfaces:
com.google.javascript.jscomp.SourceFile.Generator, JsInput
Direct Known Subclasses:
LocalFileJsInput, ResourceJsInput

public abstract class AbstractJsInput
extends java.lang.Object
implements JsInput

AbstractJsInput provides the default logic for extracting goog.provide() and goog.require() information.

Author:
bolinfest@gmail.com (Michael Bolin)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.plovr.JsInput
JsInput.CodeWithEtag
 
Field Summary
protected  java.util.List<java.lang.String> provides
           
protected  java.util.List<java.lang.String> requires
           
 
Method Summary
protected  java.lang.String calculateEtagFor(java.lang.String code)
          Must return a stable ETag for the supplied code.
abstract  java.lang.String getCode()
           
 JsInput.CodeWithEtag getCodeWithEtag()
          If JsInput.supportsEtags() returns true, then this returns the value returned by JsInput.getCode() along with an ETag; otherwise, it throws an UnsupportedOperationException.
 java.lang.String getName()
           
 java.util.List<java.lang.String> getProvides()
           
 java.util.List<java.lang.String> getRequires()
           
 java.lang.String getTemplateCode()
           
protected  boolean hasInputChanged()
           
 boolean isSoyFile()
           
protected  void processProvidesAndRequires()
           
 boolean supportsEtags()
          Whether this input can calculate a stable ETag value for itself.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

provides

protected java.util.List<java.lang.String> provides

requires

protected java.util.List<java.lang.String> requires
Method Detail

getCode

public abstract java.lang.String getCode()
Specified by:
getCode in interface com.google.javascript.jscomp.SourceFile.Generator
Specified by:
getCode in interface JsInput
Returns:
JavaScript code

supportsEtags

public boolean supportsEtags()
Description copied from interface: JsInput
Whether this input can calculate a stable ETag value for itself.

Specified by:
supportsEtags in interface JsInput
See Also:
JsInput.getCodeWithEtag()

getCodeWithEtag

public JsInput.CodeWithEtag getCodeWithEtag()
Description copied from interface: JsInput
If JsInput.supportsEtags() returns true, then this returns the value returned by JsInput.getCode() along with an ETag; otherwise, it throws an UnsupportedOperationException.

This is generally used as a performance optimization to prevent plovr from going to disk twice: once to read the code for JsInput.getCode() and then again to read the code and calculate its ETag. This ensures that the code and ETag are produced atomically.

Specified by:
getCodeWithEtag in interface JsInput

calculateEtagFor

protected final java.lang.String calculateEtagFor(java.lang.String code)
Must return a stable ETag for the supplied code. Note that for some JsInputs, such as Soy and CoffeeScript files, the ETag should be a function of the source code (the .soy or .coffee rather than the JS) as well as the options used to translate the source code to JS. For example, if a user loads a Soy file and an ETag is returned based on the content of the .soy, then the user modifies the Soy options in the plovr config and reloads, then the generated JS as well as the ETag must be different to reflect that change.


getName

public java.lang.String getName()
Specified by:
getName in interface JsInput
Returns:
name of a JsInput must be unique among the other inputs included in a compilation so that warnings and errors can be reported appropriately.

getProvides

public java.util.List<java.lang.String> getProvides()
Specified by:
getProvides in interface JsInput
Returns:
a list of the values passed to goog.provide() in this input

getRequires

public java.util.List<java.lang.String> getRequires()
Specified by:
getRequires in interface JsInput
Returns:
a list of the values passed to goog.require() in this input

hasInputChanged

protected boolean hasInputChanged()

isSoyFile

public boolean isSoyFile()
Specified by:
isSoyFile in interface JsInput
Returns:
a boolean indicating whether this is a Soy file. If true, then JsInput.getTemplateCode() must return the original Soy content.

getTemplateCode

public java.lang.String getTemplateCode()
Specified by:
getTemplateCode in interface JsInput
Returns:
the underlying template code if this is a Soy file

processProvidesAndRequires

protected void processProvidesAndRequires()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object