Chromium Code Reviews| Index: third_party/closure_compiler/runner/src/org/chromium/closure/compiler/ChromeCodingConvention.java |
| diff --git a/third_party/closure_compiler/runner/src/org/chromium/closure/compiler/ChromeCodingConvention.java b/third_party/closure_compiler/runner/src/org/chromium/closure/compiler/ChromeCodingConvention.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cab4ffe4471d7e6c174ef3d89832f1804fedede9 |
| --- /dev/null |
| +++ b/third_party/closure_compiler/runner/src/org/chromium/closure/compiler/ChromeCodingConvention.java |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.closure.compiler; |
| + |
| +import com.google.javascript.jscomp.CodingConvention; |
| +import com.google.javascript.jscomp.CodingConventions; |
| +import com.google.javascript.jscomp.DiagnosticType; |
| +import com.google.common.collect.ImmutableSet; |
| +import com.google.common.collect.Sets; |
| +import com.google.javascript.rhino.Node; |
| +import com.google.javascript.rhino.jstype.FunctionType; |
| +import com.google.javascript.rhino.jstype.ObjectType; |
| + |
| +import java.util.Collection; |
| +import java.util.List; |
|
Dan Beam
2014/07/29 18:05:11
^ unused
Vitaly Pavlenko
2014/07/29 18:53:46
Done.
|
| +import java.util.Set; |
| + |
| +public class ChromeCodingConvention extends CodingConventions.Proxy { |
| + |
| + private static final long serialVersionUID = 1L; |
|
Dan Beam
2014/07/29 18:05:11
^ unused?
Vitaly Pavlenko
2014/07/29 18:53:46
Done.
|
| + |
| + static final DiagnosticType OBJECTLIT_EXPECTED = DiagnosticType.warning( |
| + "JSC_REFLECT_OBJECTLIT_EXPECTED", |
| + "Object literal expected as second argument"); |
|
Dan Beam
2014/07/29 18:05:11
^ unused?
Vitaly Pavlenko
2014/07/29 18:53:46
Done.
|
| + |
| + private final Set<String> indirectlyDeclaredProperties; |
| + |
| + public ChromeCodingConvention() { |
| + this(CodingConventions.getDefault()); |
| + } |
| + |
| + public ChromeCodingConvention(CodingConvention wrapped) { |
| + super(wrapped); |
| + |
| + Set<String> props = Sets.newHashSet( |
| + "superClass_", |
|
Dan Beam
2014/07/29 18:05:11
why do we need superClass_?
Vitaly Pavlenko
2014/07/29 18:53:46
Done.
|
| + "instance_", |
| + "getInstance"); |
| + props.addAll(wrapped.getIndirectlyDeclaredProperties()); |
| + indirectlyDeclaredProperties = ImmutableSet.copyOf(props); |
| + } |
| + |
| + @Override |
| + public String getSingletonGetterClassName(Node callNode) { |
| + Node callArg = callNode.getFirstChild(); |
| + |
| + // Use both the original name and the post-CollapseProperties name. |
|
Dan Beam
2014/07/29 18:05:11
^ remove after removing $ version
Vitaly Pavlenko
2014/07/29 18:53:46
Done.
|
| + if (!(callArg.matchesQualifiedName("cr.addSingletonGetter") || |
| + callArg.matchesQualifiedName("cr$addSingletonGetter")) || |
|
Dan Beam
2014/07/29 18:05:11
^ don't need the $ version
Vitaly Pavlenko
2014/07/29 18:53:46
Done.
|
| + callNode.getChildCount() != 2) { |
| + return super.getSingletonGetterClassName(callNode); |
| + } |
| + |
| + return callArg.getNext().getQualifiedName(); |
| + } |
| + |
| + @Override |
| + public void applySingletonGetter(FunctionType functionType, |
| + FunctionType getterType, ObjectType objectType) { |
| + super.applySingletonGetter(functionType, getterType, objectType); |
| + functionType.defineDeclaredProperty("getInstance", getterType, |
| + functionType.getSource()); |
| + functionType.defineDeclaredProperty("instance_", objectType, |
| + functionType.getSource()); |
| + } |
| + |
| + @Override |
| + public Collection<String> getIndirectlyDeclaredProperties() { |
| + return indirectlyDeclaredProperties; |
| + } |
| + |
| +} |