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

Side by Side Diff: editor/util/plugins/com.google.dart.java2dart/src/com/google/dart/java2dart/Context.java

Issue 16983008: Fix build after analyzer_experimental changes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, the Dart project authors. 2 * Copyright (c) 2012, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 import static com.google.dart.java2dart.util.ASTFactory.thisExpression; 64 import static com.google.dart.java2dart.util.ASTFactory.thisExpression;
65 import static com.google.dart.java2dart.util.TokenFactory.token; 65 import static com.google.dart.java2dart.util.TokenFactory.token;
66 66
67 import org.apache.commons.io.FileUtils; 67 import org.apache.commons.io.FileUtils;
68 import org.apache.commons.lang3.ArrayUtils; 68 import org.apache.commons.lang3.ArrayUtils;
69 import org.eclipse.core.runtime.Assert; 69 import org.eclipse.core.runtime.Assert;
70 import org.eclipse.jdt.core.JavaCore; 70 import org.eclipse.jdt.core.JavaCore;
71 import org.eclipse.jdt.core.dom.AST; 71 import org.eclipse.jdt.core.dom.AST;
72 import org.eclipse.jdt.core.dom.ASTParser; 72 import org.eclipse.jdt.core.dom.ASTParser;
73 import org.eclipse.jdt.core.dom.FileASTRequestor; 73 import org.eclipse.jdt.core.dom.FileASTRequestor;
74 import org.eclipse.jdt.core.dom.IBinding;
74 import org.eclipse.jdt.core.dom.IMethodBinding; 75 import org.eclipse.jdt.core.dom.IMethodBinding;
75 import org.eclipse.jdt.core.dom.ITypeBinding; 76 import org.eclipse.jdt.core.dom.ITypeBinding;
76 77
77 import java.io.File; 78 import java.io.File;
78 import java.util.Collection; 79 import java.util.Collection;
79 import java.util.Collections; 80 import java.util.Collections;
80 import java.util.List; 81 import java.util.List;
81 import java.util.Map; 82 import java.util.Map;
82 import java.util.Map.Entry; 83 import java.util.Map.Entry;
83 import java.util.Set; 84 import java.util.Set;
(...skipping 18 matching lines...) Expand all
102 this.binding = binding; 103 this.binding = binding;
103 } 104 }
104 } 105 }
105 106
106 private static final String[] JAVA_EXTENSION = {"java"}; 107 private static final String[] JAVA_EXTENSION = {"java"};
107 private final List<File> classpathFiles = Lists.newArrayList(); 108 private final List<File> classpathFiles = Lists.newArrayList();
108 private final List<File> sourceFolders = Lists.newArrayList(); 109 private final List<File> sourceFolders = Lists.newArrayList();
109 private final List<File> sourceFiles = Lists.newArrayList(); 110 private final List<File> sourceFiles = Lists.newArrayList();
110 111
111 private final Map<String, String> renameMap = Maps.newHashMap(); 112 private final Map<String, String> renameMap = Maps.newHashMap();
113 private final Set<String> notPropertySet = Sets.newHashSet();
112 114
113 private final CompilationUnit dartUniverse = compilationUnit(); 115 private final CompilationUnit dartUniverse = compilationUnit();
114 private final Map<File, List<CompilationUnitMember>> fileToMembers = Maps.newH ashMap(); 116 private final Map<File, List<CompilationUnitMember>> fileToMembers = Maps.newH ashMap();
115 private final Map<CompilationUnitMember, File> memberToFile = Maps.newHashMap( ); 117 private final Map<CompilationUnitMember, File> memberToFile = Maps.newHashMap( );
116 // information about names 118 // information about names
117 private static final Set<String> forbiddenNames = Sets.newHashSet(); 119 private static final Set<String> forbiddenNames = Sets.newHashSet();
118 private final Set<String> usedNames = Sets.newHashSet(); 120 private final Set<String> usedNames = Sets.newHashSet();
119 private final Set<ClassMember> privateClassMembers = Sets.newHashSet(); 121 private final Set<ClassMember> privateClassMembers = Sets.newHashSet();
120 private final Map<SimpleIdentifier, String> identifierToName = Maps.newHashMap (); 122 private final Map<SimpleIdentifier, String> identifierToName = Maps.newHashMap ();
121 private final Map<String, Object> signatureToBinding = Maps.newHashMap(); 123 private final Map<String, Object> signatureToBinding = Maps.newHashMap();
122 private final Map<Object, List<SimpleIdentifier>> bindingToIdentifiers = Maps. newHashMap(); 124 private final Map<Object, List<SimpleIdentifier>> bindingToIdentifiers = Maps. newHashMap();
123 private final Map<ASTNode, Object> nodeToBinding = Maps.newHashMap(); 125 private final Map<ASTNode, IBinding> nodeToBinding = Maps.newHashMap();
124 private final Map<ASTNode, ITypeBinding> nodeToTypeBinding = Maps.newHashMap() ; 126 private final Map<ASTNode, ITypeBinding> nodeToTypeBinding = Maps.newHashMap() ;
125 private final Map<InstanceCreationExpression, ClassDeclaration> anonymousDecla rations = Maps.newHashMap(); 127 private final Map<InstanceCreationExpression, ClassDeclaration> anonymousDecla rations = Maps.newHashMap();
126 private final Set<SimpleIdentifier> innerClassNames = Sets.newHashSet(); 128 private final Set<SimpleIdentifier> innerClassNames = Sets.newHashSet();
127 // information about constructors 129 // information about constructors
128 private int technicalConstructorIndex; 130 private int technicalConstructorIndex;
129 private final Map<IMethodBinding, ConstructorDescription> bindingToConstructor = Maps.newHashMap(); 131 private final Map<IMethodBinding, ConstructorDescription> bindingToConstructor = Maps.newHashMap();
130 private final Map<ConstructorDeclaration, IMethodBinding> constructorToBinding = Maps.newHashMap(); 132 private final Map<ConstructorDeclaration, IMethodBinding> constructorToBinding = Maps.newHashMap();
131 // information about inner classes 133 // information about inner classes
132 private int technicalInnerClassIndex; 134 private int technicalInnerClassIndex;
133 private int technicalAnonymousClassIndex; 135 private int technicalAnonymousClassIndex;
(...skipping 10 matching lines...) Expand all
144 * Specifies that given {@link File} should be added to Java classpath. 146 * Specifies that given {@link File} should be added to Java classpath.
145 */ 147 */
146 public void addClasspathFile(File file) { 148 public void addClasspathFile(File file) {
147 Assert.isLegal(file.exists(), "File '" + file + "' does not exist."); 149 Assert.isLegal(file.exists(), "File '" + file + "' does not exist.");
148 Assert.isLegal(file.isFile(), "File '" + file + "' is not a regular file."); 150 Assert.isLegal(file.isFile(), "File '" + file + "' is not a regular file.");
149 file = file.getAbsoluteFile(); 151 file = file.getAbsoluteFile();
150 classpathFiles.add(file); 152 classpathFiles.add(file);
151 } 153 }
152 154
153 /** 155 /**
154 * Specifies that field with given signature should be renamed before normaliz ing member names. 156 * Specifies that the method with given signature should not be converted to g etter/setter.
157 */
158 public void addNotProperty(String signature) {
159 notPropertySet.add(signature);
160 }
161
162 /**
163 * Specifies that method with given signature should be renamed before normali zing member names.
155 */ 164 */
156 public void addRename(String signature, String newName) { 165 public void addRename(String signature, String newName) {
157 renameMap.put(signature, newName); 166 renameMap.put(signature, newName);
158 } 167 }
159 168
160 /** 169 /**
161 * Specifies that given {@link File} should be translated. 170 * Specifies that given {@link File} should be translated.
162 */ 171 */
163 public void addSourceFile(File file) { 172 public void addSourceFile(File file) {
164 Assert.isLegal(file.exists(), "File '" + file + "' does not exist."); 173 Assert.isLegal(file.exists(), "File '" + file + "' does not exist.");
(...skipping 17 matching lines...) Expand all
182 * Specifies that given folder is a source folder (root of Java packages hiera rchy). 191 * Specifies that given folder is a source folder (root of Java packages hiera rchy).
183 */ 192 */
184 public void addSourceFolder(File folder) { 193 public void addSourceFolder(File folder) {
185 Assert.isLegal(folder.exists(), "Folder '" + folder + "' does not exist."); 194 Assert.isLegal(folder.exists(), "Folder '" + folder + "' does not exist.");
186 Assert.isLegal(folder.isDirectory(), "Folder '" + folder + "' is not a folde r."); 195 Assert.isLegal(folder.isDirectory(), "Folder '" + folder + "' is not a folde r.");
187 folder = folder.getAbsoluteFile(); 196 folder = folder.getAbsoluteFile();
188 sourceFolders.add(folder); 197 sourceFolders.add(folder);
189 } 198 }
190 199
191 /** 200 /**
201 * @return {@code true} if the method with the given signature (which could be made getter or
202 * setter) is allowed to be converted into getter/setter.
203 */
204 public boolean canMakeProperty(SimpleIdentifier identifier) {
205 IBinding binding = getNodeBinding(identifier);
206 String signature = JavaUtils.getJdtSignature(binding);
207 return !notPropertySet.contains(signature);
208 }
209
210 /**
192 * In Java we can have method parameter "foo" and invoke method named "foo", a nd parameter will 211 * In Java we can have method parameter "foo" and invoke method named "foo", a nd parameter will
193 * not shadow invoked method. But in Dart it will. 212 * not shadow invoked method. But in Dart it will.
194 */ 213 */
195 public void ensureMethodParameterDoesNotHide(CompilationUnit unit) { 214 public void ensureMethodParameterDoesNotHide(CompilationUnit unit) {
196 unit.accept(new RecursiveASTVisitor<Void>() { 215 unit.accept(new RecursiveASTVisitor<Void>() {
197 @Override 216 @Override
198 public Void visitMethodDeclaration(MethodDeclaration node) { 217 public Void visitMethodDeclaration(MethodDeclaration node) {
199 FormalParameterList parameterList = node.getParameters(); 218 FormalParameterList parameterList = node.getParameters();
200 if (parameterList != null) { 219 if (parameterList != null) {
201 for (FormalParameter parameter : parameterList.getParameters()) { 220 for (FormalParameter parameter : parameterList.getParameters()) {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 return name; 561 return name;
543 } 562 }
544 563
545 public Map<CompilationUnitMember, File> getMemberToFile() { 564 public Map<CompilationUnitMember, File> getMemberToFile() {
546 return memberToFile; 565 return memberToFile;
547 } 566 }
548 567
549 /** 568 /**
550 * @return some Java binding for the given Dart {@link ASTNode}. 569 * @return some Java binding for the given Dart {@link ASTNode}.
551 */ 570 */
552 public Object getNodeBinding(ASTNode node) { 571 public IBinding getNodeBinding(ASTNode node) {
553 return nodeToBinding.get(node); 572 return nodeToBinding.get(node);
554 } 573 }
555 574
556 /** 575 /**
557 * @return some Java {@link ITypeBinding} for the given Dart {@link ASTNode}. 576 * @return some Java {@link ITypeBinding} for the given Dart {@link ASTNode}.
558 */ 577 */
559 public ITypeBinding getNodeTypeBinding(ASTNode node) { 578 public ITypeBinding getNodeTypeBinding(ASTNode node) {
560 return nodeToTypeBinding.get(node); 579 return nodeToTypeBinding.get(node);
561 } 580 }
562 581
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 * Remembers that given {@link SimpleIdentifier} is the name of inner class an d all references to 733 * Remembers that given {@link SimpleIdentifier} is the name of inner class an d all references to
715 * it should be renamed. 734 * it should be renamed.
716 */ 735 */
717 void putInnerClassName(SimpleIdentifier identifier) { 736 void putInnerClassName(SimpleIdentifier identifier) {
718 innerClassNames.add(identifier); 737 innerClassNames.add(identifier);
719 } 738 }
720 739
721 /** 740 /**
722 * Remembers some Java binding for the given Dart {@link ASTNode}. 741 * Remembers some Java binding for the given Dart {@link ASTNode}.
723 */ 742 */
724 void putNodeBinding(ASTNode node, Object binding) { 743 void putNodeBinding(ASTNode node, IBinding binding) {
725 nodeToBinding.put(node, binding); 744 nodeToBinding.put(node, binding);
726 } 745 }
727 746
728 /** 747 /**
729 * Remembers Java {@link ITypeBinding} for the given Dart {@link ASTNode}. 748 * Remembers Java {@link ITypeBinding} for the given Dart {@link ASTNode}.
730 */ 749 */
731 void putNodeTypeBinding(ASTNode node, ITypeBinding binding) { 750 void putNodeTypeBinding(ASTNode node, ITypeBinding binding) {
732 nodeToTypeBinding.put(node, binding); 751 nodeToTypeBinding.put(node, binding);
733 } 752 }
734 753
735 /** 754 /**
736 * Remembers that given {@link ClassMember} was created for private Java eleme nt. 755 * Remembers that given {@link ClassMember} was created for private Java eleme nt.
737 */ 756 */
738 void putPrivateClassMember(ClassMember member) { 757 void putPrivateClassMember(ClassMember member) {
739 privateClassMembers.add(member); 758 privateClassMembers.add(member);
740 } 759 }
741 760
742 /** 761 /**
743 * Remembers that "identifier" is reference to the given Java binding. 762 * Remembers that "identifier" is reference to the given Java binding.
744 */ 763 */
745 void putReference(SimpleIdentifier identifier, Object binding, String bindingS ignature) { 764 void putReference(SimpleIdentifier identifier, IBinding binding, String bindin gSignature) {
746 if (binding != null) { 765 if (binding != null) {
747 signatureToBinding.put(bindingSignature, binding); 766 signatureToBinding.put(bindingSignature, binding);
748 identifierToName.put(identifier, identifier.getName()); 767 identifierToName.put(identifier, identifier.getName());
749 // remember binding for reference 768 // remember binding for reference
750 nodeToBinding.put(identifier, binding); 769 nodeToBinding.put(identifier, binding);
751 // add reference to binding 770 // add reference to binding
752 List<SimpleIdentifier> identifiers = bindingToIdentifiers.get(binding); 771 List<SimpleIdentifier> identifiers = bindingToIdentifiers.get(binding);
753 if (identifiers == null) { 772 if (identifiers == null) {
754 identifiers = Lists.newLinkedList(); 773 identifiers = Lists.newLinkedList();
755 bindingToIdentifiers.put(binding, identifiers); 774 bindingToIdentifiers.put(binding, identifiers);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 } 1091 }
1073 } 1092 }
1074 } 1093 }
1075 } 1094 }
1076 } 1095 }
1077 } 1096 }
1078 } 1097 }
1079 }); 1098 });
1080 } 1099 }
1081 } 1100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698