Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: third_party/closure_compiler/runner/src/org/chromium/closure/compiler/ChromeCodingConvention.java

Issue 421253006: Add ChromeCodingConvention.java to Closure Compiler to preserve getInstance() type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@A_typechecking_about
Patch Set: rebase onto master Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b85f1ff6f829567ee1fa9311ebe71bfc4d02254b
--- /dev/null
+++ b/third_party/closure_compiler/runner/src/org/chromium/closure/compiler/ChromeCodingConvention.java
@@ -0,0 +1,63 @@
+// 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;
+import java.util.Set;
+
+public class ChromeCodingConvention extends CodingConventions.Proxy {
+
+ private final Set<String> indirectlyDeclaredProperties;
+
+ public ChromeCodingConvention() {
+ this(CodingConventions.getDefault());
+ }
+
+ public ChromeCodingConvention(CodingConvention wrapped) {
+ super(wrapped);
+
+ Set<String> props = Sets.newHashSet("instance_", "getInstance");
+ props.addAll(wrapped.getIndirectlyDeclaredProperties());
+ indirectlyDeclaredProperties = ImmutableSet.copyOf(props);
+ }
+
+ @Override
+ public String getSingletonGetterClassName(Node callNode) {
+ Node callArg = callNode.getFirstChild();
+
+ if (!(callArg.matchesQualifiedName("cr.addSingletonGetter")) ||
+ 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;
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698