| OLD | NEW |
| 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 29 matching lines...) Expand all Loading... |
| 40 import com.google.dart.engine.ast.SimpleIdentifier; | 40 import com.google.dart.engine.ast.SimpleIdentifier; |
| 41 import com.google.dart.engine.ast.SuperConstructorInvocation; | 41 import com.google.dart.engine.ast.SuperConstructorInvocation; |
| 42 import com.google.dart.engine.ast.ThisExpression; | 42 import com.google.dart.engine.ast.ThisExpression; |
| 43 import com.google.dart.engine.ast.VariableDeclaration; | 43 import com.google.dart.engine.ast.VariableDeclaration; |
| 44 import com.google.dart.engine.ast.VariableDeclarationList; | 44 import com.google.dart.engine.ast.VariableDeclarationList; |
| 45 import com.google.dart.engine.ast.visitor.GeneralizingASTVisitor; | 45 import com.google.dart.engine.ast.visitor.GeneralizingASTVisitor; |
| 46 import com.google.dart.engine.ast.visitor.RecursiveASTVisitor; | 46 import com.google.dart.engine.ast.visitor.RecursiveASTVisitor; |
| 47 import com.google.dart.engine.scanner.Keyword; | 47 import com.google.dart.engine.scanner.Keyword; |
| 48 import com.google.dart.engine.scanner.KeywordToken; | 48 import com.google.dart.engine.scanner.KeywordToken; |
| 49 import com.google.dart.engine.scanner.TokenType; | 49 import com.google.dart.engine.scanner.TokenType; |
| 50 import com.google.dart.java2dart.util.Bindings; |
| 50 import com.google.dart.java2dart.util.JavaUtils; | 51 import com.google.dart.java2dart.util.JavaUtils; |
| 51 | 52 |
| 52 import static com.google.dart.java2dart.util.ASTFactory.assignmentExpression; | 53 import static com.google.dart.java2dart.util.ASTFactory.assignmentExpression; |
| 53 import static com.google.dart.java2dart.util.ASTFactory.block; | 54 import static com.google.dart.java2dart.util.ASTFactory.block; |
| 54 import static com.google.dart.java2dart.util.ASTFactory.blockFunctionBody; | 55 import static com.google.dart.java2dart.util.ASTFactory.blockFunctionBody; |
| 55 import static com.google.dart.java2dart.util.ASTFactory.compilationUnit; | 56 import static com.google.dart.java2dart.util.ASTFactory.compilationUnit; |
| 56 import static com.google.dart.java2dart.util.ASTFactory.constructorDeclaration; | 57 import static com.google.dart.java2dart.util.ASTFactory.constructorDeclaration; |
| 57 import static com.google.dart.java2dart.util.ASTFactory.expressionStatement; | 58 import static com.google.dart.java2dart.util.ASTFactory.expressionStatement; |
| 58 import static com.google.dart.java2dart.util.ASTFactory.formalParameterList; | 59 import static com.google.dart.java2dart.util.ASTFactory.formalParameterList; |
| 59 import static com.google.dart.java2dart.util.ASTFactory.identifier; | 60 import static com.google.dart.java2dart.util.ASTFactory.identifier; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 index++; | 325 index++; |
| 325 } | 326 } |
| 326 } | 327 } |
| 327 }); | 328 }); |
| 328 } | 329 } |
| 329 | 330 |
| 330 public void ensureUniqueClassMemberNames(CompilationUnit unit) { | 331 public void ensureUniqueClassMemberNames(CompilationUnit unit) { |
| 331 unit.accept(new RecursiveASTVisitor<Void>() { | 332 unit.accept(new RecursiveASTVisitor<Void>() { |
| 332 private final Set<ClassMember> untouchableMethods = Sets.newHashSet(); | 333 private final Set<ClassMember> untouchableMethods = Sets.newHashSet(); |
| 333 private final Map<String, ClassMember> usedClassMembers = Maps.newHashMap(
); | 334 private final Map<String, ClassMember> usedClassMembers = Maps.newHashMap(
); |
| 335 private final Set<String> superNames = Sets.newHashSet(); |
| 336 private final Map<String, List<IMethodBinding>> superMembers = Maps.newHas
hMap(); |
| 334 | 337 |
| 335 @Override | 338 @Override |
| 336 public Void visitClassDeclaration(ClassDeclaration node) { | 339 public Void visitClassDeclaration(ClassDeclaration node) { |
| 340 untouchableMethods.clear(); |
| 337 usedClassMembers.clear(); | 341 usedClassMembers.clear(); |
| 342 superNames.clear(); |
| 343 superMembers.clear(); |
| 338 // fill "static" methods from super classes | 344 // fill "static" methods from super classes |
| 339 { | 345 { |
| 340 org.eclipse.jdt.core.dom.ITypeBinding binding = getNodeTypeBinding(nod
e); | 346 org.eclipse.jdt.core.dom.ITypeBinding binding = getNodeTypeBinding(nod
e); |
| 341 if (binding != null) { | 347 if (binding != null) { |
| 342 binding = binding.getSuperclass(); | 348 binding = binding.getSuperclass(); |
| 343 while (binding != null) { | 349 while (binding != null) { |
| 344 for (org.eclipse.jdt.core.dom.IMethodBinding method : binding.getD
eclaredMethods()) { | 350 for (org.eclipse.jdt.core.dom.IMethodBinding method : binding.getD
eclaredMethods()) { |
| 345 if (org.eclipse.jdt.core.dom.Modifier.isStatic(method.getModifie
rs())) { | 351 if (org.eclipse.jdt.core.dom.Modifier.isStatic(method.getModifie
rs())) { |
| 346 usedClassMembers.put(method.getName(), null); | 352 usedClassMembers.put(method.getName(), null); |
| 353 } else { |
| 354 addSuperMember(method); |
| 347 } | 355 } |
| 348 } | 356 } |
| 349 binding = binding.getSuperclass(); | 357 binding = binding.getSuperclass(); |
| 350 } | 358 } |
| 351 } | 359 } |
| 352 } | 360 } |
| 353 // fill "untouchable" methods | 361 // fill "untouchable" methods |
| 354 for (ClassMember member : node.getMembers()) { | 362 for (ClassMember member : node.getMembers()) { |
| 355 if (member instanceof MethodDeclaration) { | 363 if (member instanceof MethodDeclaration) { |
| 356 MethodDeclaration methodDeclaration = (MethodDeclaration) member; | 364 MethodDeclaration methodDeclaration = (MethodDeclaration) member; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 373 { | 381 { |
| 374 ClassMember otherMember = usedClassMembers.get(method.getName().ge
tName()); | 382 ClassMember otherMember = usedClassMembers.get(method.getName().ge
tName()); |
| 375 if (otherMember instanceof MethodDeclaration) { | 383 if (otherMember instanceof MethodDeclaration) { |
| 376 MethodDeclaration otherMethod = (MethodDeclaration) otherMember; | 384 MethodDeclaration otherMethod = (MethodDeclaration) otherMember; |
| 377 if (method.isGetter() && otherMethod.isSetter() || method.isSett
er() | 385 if (method.isGetter() && otherMethod.isSetter() || method.isSett
er() |
| 378 && otherMethod.isGetter()) { | 386 && otherMethod.isGetter()) { |
| 379 continue; | 387 continue; |
| 380 } | 388 } |
| 381 } | 389 } |
| 382 } | 390 } |
| 391 // may be overloaded method |
| 392 { |
| 393 Object binding = nodeToBinding.get(method); |
| 394 if (binding instanceof IMethodBinding) { |
| 395 IMethodBinding methodBinding = (IMethodBinding) binding; |
| 396 String name = methodBinding.getName(); |
| 397 if (superNames.contains(name)) { |
| 398 IMethodBinding over = Bindings.findOverriddenMethod(methodBind
ing, false); |
| 399 if (over == null) { |
| 400 usedClassMembers.put(name, null); |
| 401 } |
| 402 } |
| 403 } |
| 404 } |
| 383 // ensure unique name | 405 // ensure unique name |
| 384 ensureUniqueName(method.getName(), method); | 406 ensureUniqueName(method.getName(), method); |
| 385 } | 407 } |
| 386 } | 408 } |
| 387 // ensure unique field names (if name is already used be method) | 409 // ensure unique field names (if name is already used be method) |
| 388 for (ClassMember member : node.getMembers()) { | 410 for (ClassMember member : node.getMembers()) { |
| 389 if (member instanceof FieldDeclaration) { | 411 if (member instanceof FieldDeclaration) { |
| 390 FieldDeclaration fieldDeclaration = (FieldDeclaration) member; | 412 FieldDeclaration fieldDeclaration = (FieldDeclaration) member; |
| 391 for (VariableDeclaration field : fieldDeclaration.getFields().getVar
iables()) { | 413 for (VariableDeclaration field : fieldDeclaration.getFields().getVar
iables()) { |
| 392 ensureUniqueName(field.getName(), fieldDeclaration); | 414 ensureUniqueName(field.getName(), fieldDeclaration); |
| 393 } | 415 } |
| 394 } | 416 } |
| 395 } | 417 } |
| 396 // no recursion | 418 // no recursion |
| 397 return null; | 419 return null; |
| 398 } | 420 } |
| 399 | 421 |
| 422 private void addSuperMember(IMethodBinding binding) { |
| 423 String name = binding.getName(); |
| 424 superNames.add(name); |
| 425 List<IMethodBinding> members = superMembers.get(name); |
| 426 if (members == null) { |
| 427 members = Lists.newArrayList(); |
| 428 superMembers.put(name, members); |
| 429 } |
| 430 members.add(binding); |
| 431 } |
| 432 |
| 400 private void ensureUniqueName(Identifier declarationName, ClassMember memb
er) { | 433 private void ensureUniqueName(Identifier declarationName, ClassMember memb
er) { |
| 401 if (declarationName instanceof SimpleIdentifier) { | 434 if (declarationName instanceof SimpleIdentifier) { |
| 402 SimpleIdentifier declarationIdentifier = (SimpleIdentifier) declaratio
nName; | 435 SimpleIdentifier declarationIdentifier = (SimpleIdentifier) declaratio
nName; |
| 403 String name = declarationIdentifier.getName(); | 436 String name = declarationIdentifier.getName(); |
| 404 if (!isUniqueClassMemberName(name)) { | 437 if (!isUniqueClassMemberName(name)) { |
| 405 String newName = generateUniqueName(name); | 438 String newName = generateUniqueName(name); |
| 406 // rename binding | 439 // rename binding |
| 407 if (!newName.equals(name)) { | 440 if (!newName.equals(name)) { |
| 408 renameIdentifier(declarationIdentifier, newName); | 441 renameIdentifier(declarationIdentifier, newName); |
| 409 name = newName; | 442 name = newName; |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 } | 1025 } |
| 993 } | 1026 } |
| 994 } | 1027 } |
| 995 } | 1028 } |
| 996 } | 1029 } |
| 997 } | 1030 } |
| 998 } | 1031 } |
| 999 }); | 1032 }); |
| 1000 } | 1033 } |
| 1001 } | 1034 } |
| OLD | NEW |