Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(72)

Delta Between Two Patch Sets: src/com/google/gwt/inject/rebind/binding/BindConstantBinding.java

Issue 90085: Fixed enum binding support (issue #49) (Closed) SVN Base: http://google-gin.googlecode.com/svn/trunk/
Left Patch Set: Created 5 months ago
Right Patch Set: Using getEnclosingClass Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * Copyright 2008 Google Inc. 2 * Copyright 2008 Google Inc.
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of 5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at 6 * the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 valueToOutput = instance.toString(); // Includes int & short. 85 valueToOutput = instance.toString(); // Includes int & short.
86 } else if (instance instanceof Enum) { 86 } else if (instance instanceof Enum) {
87 String className = instance.getClass().getName(); 87 String className = instance.getClass().getName();
88 88
89 // Enums become anonymous inner classes if they have a custom 89 // Enums become anonymous inner classes if they have a custom
90 // implementation. Their classname is then of the form "com.foo.Bar$1". 90 // implementation. Their classname is then of the form "com.foo.Bar$1".
91 // We need to be careful here to not clobber inner enums (which also 91 // We need to be careful here to not clobber inner enums (which also
92 // have a $ in their classname). The regex below matches any classname 92 // have a $ in their classname). The regex below matches any classname
93 // that terminates in a $ followed by a number, i.e. an anonymous class. 93 // that terminates in a $ followed by a number, i.e. an anonymous class.
94 if (className.matches(".+\\$\\d+\\z")) { 94 if (className.matches(".+\\$\\d+\\z")) {
95 className = className.substring(0, className.lastIndexOf("$")); 95 className = instance.getClass().getEnclosingClass().getName();
Brian_Stoler 2009/07/02 04:16:03 Can you just check if getEnclosingClass is non-nul
Aragos 2009/07/02 20:34:57 On 2009/07/02 04:16:03, Brian_Stoler wrote: > Can
96 } 96 }
97 className = nameGenerator.binaryNameToSourceName(className); 97 className = nameGenerator.binaryNameToSourceName(className);
98 98
99 valueToOutput = className + "." + ((Enum) instance).name(); 99 valueToOutput = className + "." + ((Enum) instance).name();
100 } else { 100 } else {
101 throw new IllegalArgumentException("Attempted to create a constant binding with a " 101 throw new IllegalArgumentException("Attempted to create a constant binding with a "
102 + "non-constant type: " + type); 102 + "non-constant type: " + type);
103 } 103 }
104 } 104 }
105 105
106 public void writeCreatorMethods(SourceWriter writer, String creatorMethodSigna ture) { 106 public void writeCreatorMethods(SourceWriter writer, String creatorMethodSigna ture) {
107 assert valueToOutput != null; 107 assert valueToOutput != null;
108 108
109 sourceWriteUtil.writeMethod(writer, creatorMethodSignature, "return " + valu eToOutput + ";"); 109 sourceWriteUtil.writeMethod(writer, creatorMethodSignature, "return " + valu eToOutput + ";");
110 } 110 }
111 111
112 public RequiredKeys getRequiredKeys() { 112 public RequiredKeys getRequiredKeys() {
113 return new RequiredKeys(Collections.<Key<?>>emptySet()); 113 return new RequiredKeys(Collections.<Key<?>>emptySet());
114 } 114 }
115 } 115 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497