Debian Codegraph @

src/com/google/javascript/jscomp/JqueryCodingConvention.java

raw symbols SCIP
1 /*
2 * Copyright 2011 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 * This describes the jQuery specific JavaScript coding conventions.
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 }