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

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/code/TokenUtils.java

Issue 10825190: Don't infer non-final field types (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tests for 'const' Created 8 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: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/code/TokenUtils.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/code/TokenUtils.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/code/TokenUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..cbd83ef91076aab94f04f2a77d1ac6fceb12a049
--- /dev/null
+++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/code/TokenUtils.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2012, the Dart project authors.
+ *
+ * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.dart.tools.internal.corext.refactoring.code;
+
+import com.google.common.collect.Lists;
+import com.google.dart.engine.scanner.Keyword;
+import com.google.dart.engine.scanner.KeywordToken;
+import com.google.dart.engine.scanner.StringScanner;
+import com.google.dart.engine.scanner.Token;
+import com.google.dart.engine.scanner.TokenType;
+import com.google.dart.tools.internal.corext.refactoring.util.ExecutionUtils;
+import com.google.dart.tools.internal.corext.refactoring.util.RunnableEx;
+
+import java.util.List;
+
+/**
+ * Utilities to work with {@link Token}s.
+ *
+ * @coverage dart.editor.ui.refactoring.core
+ */
+public class TokenUtils {
+ /**
+ * @return the {@link Token} with given {@link Keyword}, may be <code>null</code> if not found.
+ */
+ public static KeywordToken findKeywordToken(List<Token> tokens, Keyword keyword) {
+ for (int i = 0; i < tokens.size(); i++) {
+ Token token = tokens.get(i);
+ if (token instanceof KeywordToken) {
+ KeywordToken keywordToken = (KeywordToken) token;
+ if (keywordToken.getKeyword() == keyword) {
+ return keywordToken;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return {@link Token}s of the given Dart source.
+ */
+ public static List<Token> getTokens(final String s) {
+ final List<Token> tokens = Lists.newArrayList();
+ ExecutionUtils.runIgnore(new RunnableEx() {
+ @Override
+ public void run() throws Exception {
+ StringScanner scanner = new StringScanner(null, s, null);
+ com.google.dart.engine.scanner.Token token = scanner.tokenize();
+ while (token.getType() != TokenType.EOF) {
+ tokens.add(token);
+ token = token.getNext();
+ }
+ }
+ });
+ return tokens;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698