| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp; |
| 18 |
|
| 19 |
import java.util.Set; |
| 20 |
|
| 21 |
import com.google.common.base.Preconditions; |
| 22 |
import com.google.common.collect.ImmutableSet; |
| 23 |
import com.google.javascript.rhino.Node; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class JqueryCodingConvention extends CodingConventions.Proxy { |
| 29 |
private static final long serialVersionUID = 1L; |
| 30 |
|
| 31 |
public JqueryCodingConvention() { |
| 32 |
this(CodingConventions.getDefault()); |
| 33 |
} |
| 34 |
|
| 35 |
public JqueryCodingConvention(CodingConvention wrapped) { |
| 36 |
super(wrapped); |
| 37 |
} |
| 38 |
|
| 39 |
@Override |
| 40 |
public String getGlobalObject() { |
| 41 |
return "window"; |
| 42 |
} |
| 43 |
|
| 44 |
private final static Set<String> propertyTestFunctions = ImmutableSet.of( |
| 45 |
"jQuery.isPlainObject", "jQuery.isFunction", "jQuery.isNumeric", |
| 46 |
"jQuery.isEmptyObject"); |
| 47 |
|
| 48 |
@Override |
| 49 |
public boolean isPropertyTestFunction(Node call) { |
| 50 |
Preconditions.checkArgument(call.isCall()); |
| 51 |
return propertyTestFunctions.contains( |
| 52 |
call.getFirstChild().getQualifiedName()); |
| 53 |
} |
| 54 |
|
| 55 |
private final static Set<String> prototypeAliases = ImmutableSet.of( |
| 56 |
"jQuery.fn", "jQuerySub.fn"); |
| 57 |
|
| 58 |
@Override |
| 59 |
public boolean isPrototypeAlias(Node getProp) { |
| 60 |
Preconditions.checkArgument(getProp.isGetProp()); |
| 61 |
return prototypeAliases.contains(getProp.getQualifiedName()); |
| 62 |
} |
| 63 |
} |