OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 * no identifier in the AST when the parser could not distinguish between a me thod invocation and | 188 * no identifier in the AST when the parser could not distinguish between a me thod invocation and |
189 * an invocation of a top-level function imported with a prefix. | 189 * an invocation of a top-level function imported with a prefix. |
190 */ | 190 */ |
191 private static class SyntheticIdentifier extends Identifier { | 191 private static class SyntheticIdentifier extends Identifier { |
192 /** | 192 /** |
193 * The name of the synthetic identifier. | 193 * The name of the synthetic identifier. |
194 */ | 194 */ |
195 private final String name; | 195 private final String name; |
196 | 196 |
197 /** | 197 /** |
198 * The identifier to be highlighted in case of an error | |
199 */ | |
200 private final Identifier identifier; | |
Paul Berry
2014/11/04 23:07:41
Nit: although the comment makes it clear what this
Brian Wilkerson
2014/11/05 17:05:25
I renamed it.
| |
201 | |
202 /** | |
198 * Initialize a newly created synthetic identifier to have the given name. | 203 * Initialize a newly created synthetic identifier to have the given name. |
199 * | 204 * |
200 * @param name the name of the synthetic identifier | 205 * @param name the name of the synthetic identifier |
206 * @param identifier the identifier to be highlighted in case of an error | |
201 */ | 207 */ |
202 private SyntheticIdentifier(String name) { | 208 private SyntheticIdentifier(String name, Identifier identifier) { |
203 this.name = name; | 209 this.name = name; |
210 this.identifier = identifier; | |
204 } | 211 } |
205 | 212 |
206 @Override | 213 @Override |
207 public <R> R accept(AstVisitor<R> visitor) { | 214 public <R> R accept(AstVisitor<R> visitor) { |
208 return null; | 215 return null; |
209 } | 216 } |
210 | 217 |
211 @Override | 218 @Override |
212 public Token getBeginToken() { | 219 public Token getBeginToken() { |
213 return null; | 220 return null; |
214 } | 221 } |
215 | 222 |
216 @Override | 223 @Override |
217 public Element getBestElement() { | 224 public Element getBestElement() { |
218 return null; | 225 return null; |
219 } | 226 } |
220 | 227 |
221 @Override | 228 @Override |
222 public Token getEndToken() { | 229 public Token getEndToken() { |
223 return null; | 230 return null; |
224 } | 231 } |
225 | 232 |
226 @Override | 233 @Override |
234 public int getLength() { | |
235 return identifier.getLength(); | |
236 } | |
237 | |
238 @Override | |
227 public String getName() { | 239 public String getName() { |
228 return name; | 240 return name; |
229 } | 241 } |
230 | 242 |
231 @Override | 243 @Override |
244 public int getOffset() { | |
245 return identifier.getOffset(); | |
246 } | |
247 | |
248 @Override | |
232 public int getPrecedence() { | 249 public int getPrecedence() { |
233 return 16; | 250 return 16; |
234 } | 251 } |
235 | 252 |
236 @Override | 253 @Override |
237 public Element getPropagatedElement() { | 254 public Element getPropagatedElement() { |
238 return null; | 255 return null; |
239 } | 256 } |
240 | 257 |
241 @Override | 258 @Override |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1169 return null; | 1186 return null; |
1170 } | 1187 } |
1171 // | 1188 // |
1172 // Check to see whether the prefix is really a prefix. | 1189 // Check to see whether the prefix is really a prefix. |
1173 // | 1190 // |
1174 Element prefixElement = prefix.getStaticElement(); | 1191 Element prefixElement = prefix.getStaticElement(); |
1175 if (prefixElement instanceof PrefixElement) { | 1192 if (prefixElement instanceof PrefixElement) { |
1176 Element element = resolver.getNameScope().lookup(node, definingLibrary); | 1193 Element element = resolver.getNameScope().lookup(node, definingLibrary); |
1177 if (element == null && identifier.inSetterContext()) { | 1194 if (element == null && identifier.inSetterContext()) { |
1178 element = resolver.getNameScope().lookup( | 1195 element = resolver.getNameScope().lookup( |
1179 new SyntheticIdentifier(node.getName() + "="), | 1196 new SyntheticIdentifier(node.getName() + "=", node), |
1180 definingLibrary); | 1197 definingLibrary); |
1181 } | 1198 } |
1182 if (element == null) { | 1199 if (element == null) { |
1183 if (identifier.inSetterContext()) { | 1200 if (identifier.inSetterContext()) { |
1184 resolver.reportErrorForNode( | 1201 resolver.reportErrorForNode( |
1185 StaticWarningCode.UNDEFINED_SETTER, | 1202 StaticWarningCode.UNDEFINED_SETTER, |
1186 identifier, | 1203 identifier, |
1187 identifier.getName(), | 1204 identifier.getName(), |
1188 prefixElement.getName()); | 1205 prefixElement.getName()); |
1189 } else if (node.getParent() instanceof Annotation) { | 1206 } else if (node.getParent() instanceof Annotation) { |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1703 * @param identifier the identifier that might have been imported using a pref ix | 1720 * @param identifier the identifier that might have been imported using a pref ix |
1704 * @return the element that was found | 1721 * @return the element that was found |
1705 */ | 1722 */ |
1706 private Element findImportWithoutPrefix(SimpleIdentifier identifier) { | 1723 private Element findImportWithoutPrefix(SimpleIdentifier identifier) { |
1707 Element element = null; | 1724 Element element = null; |
1708 Scope nameScope = resolver.getNameScope(); | 1725 Scope nameScope = resolver.getNameScope(); |
1709 for (ImportElement importElement : definingLibrary.getImports()) { | 1726 for (ImportElement importElement : definingLibrary.getImports()) { |
1710 PrefixElement prefixElement = importElement.getPrefix(); | 1727 PrefixElement prefixElement = importElement.getPrefix(); |
1711 if (prefixElement != null) { | 1728 if (prefixElement != null) { |
1712 Identifier prefixedIdentifier = new SyntheticIdentifier(prefixElement.ge tName() + "." | 1729 Identifier prefixedIdentifier = new SyntheticIdentifier(prefixElement.ge tName() + "." |
1713 + identifier.getName()); | 1730 + identifier.getName(), identifier); |
1714 Element importedElement = nameScope.lookup(prefixedIdentifier, definingL ibrary); | 1731 Element importedElement = nameScope.lookup(prefixedIdentifier, definingL ibrary); |
1715 if (importedElement != null) { | 1732 if (importedElement != null) { |
1716 if (element == null) { | 1733 if (element == null) { |
1717 element = importedElement; | 1734 element = importedElement; |
1718 } else { | 1735 } else { |
1719 element = MultiplyDefinedElementImpl.fromElements( | 1736 element = MultiplyDefinedElementImpl.fromElements( |
1720 definingLibrary.getContext(), | 1737 definingLibrary.getContext(), |
1721 element, | 1738 element, |
1722 importedElement); | 1739 importedElement); |
1723 } | 1740 } |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2813 Element element = lookUpMethod(target, targetType, methodName.getName()); | 2830 Element element = lookUpMethod(target, targetType, methodName.getName()); |
2814 if (element == null) { | 2831 if (element == null) { |
2815 // | 2832 // |
2816 // If there's no method, then it's possible that 'm' is a getter that re turns a function. | 2833 // If there's no method, then it's possible that 'm' is a getter that re turns a function. |
2817 // | 2834 // |
2818 // TODO (collinsn): need to add union type support here too, in the styl e of [lookUpMethod]. | 2835 // TODO (collinsn): need to add union type support here too, in the styl e of [lookUpMethod]. |
2819 element = lookUpGetter(target, targetType, methodName.getName()); | 2836 element = lookUpGetter(target, targetType, methodName.getName()); |
2820 } | 2837 } |
2821 return element; | 2838 return element; |
2822 } else if (target instanceof SimpleIdentifier) { | 2839 } else if (target instanceof SimpleIdentifier) { |
2823 Element targetElement = ((SimpleIdentifier) target).getStaticElement(); | 2840 SimpleIdentifier identifier = (SimpleIdentifier) target; |
2841 Element targetElement = identifier.getStaticElement(); | |
2824 if (targetElement instanceof PrefixElement) { | 2842 if (targetElement instanceof PrefixElement) { |
2825 // | 2843 // |
2826 // Look to see whether the name of the method is really part of a prefix ed identifier for an | 2844 // Look to see whether the name of the method is really part of a prefix ed identifier for an |
2827 // imported top-level function or top-level getter that returns a functi on. | 2845 // imported top-level function or top-level getter that returns a functi on. |
2828 // | 2846 // |
2829 final String name = ((SimpleIdentifier) target).getName() + "." + method Name; | 2847 final String name = identifier.getName() + "." + methodName; |
2830 Identifier functionName = new SyntheticIdentifier(name); | 2848 Identifier functionName = new SyntheticIdentifier(name, methodName); |
2831 Element element = resolver.getNameScope().lookup(functionName, definingL ibrary); | 2849 Element element = resolver.getNameScope().lookup(functionName, definingL ibrary); |
2832 if (element != null) { | 2850 if (element != null) { |
2833 // TODO(brianwilkerson) This isn't a method invocation, it's a functio n invocation where | 2851 // TODO(brianwilkerson) This isn't a method invocation, it's a functio n invocation where |
2834 // the function name is a prefixed identifier. Consider re-writing the AST. | 2852 // the function name is a prefixed identifier. Consider re-writing the AST. |
2835 return element; | 2853 return element; |
2836 } | 2854 } |
2837 } | 2855 } |
2838 } | 2856 } |
2839 // TODO(brianwilkerson) Report this error. | 2857 // TODO(brianwilkerson) Report this error. |
2840 return null; | 2858 return null; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2994 setter = lookUpSetter(null, enclosingClass.getType(), node.getName() ); | 3012 setter = lookUpSetter(null, enclosingClass.getType(), node.getName() ); |
2995 } | 3013 } |
2996 } | 3014 } |
2997 if (setter != null) { | 3015 if (setter != null) { |
2998 element = setter; | 3016 element = setter; |
2999 } | 3017 } |
3000 } | 3018 } |
3001 } else if (element == null | 3019 } else if (element == null |
3002 && (node.inSetterContext() || node.getParent() instanceof CommentReferen ce)) { | 3020 && (node.inSetterContext() || node.getParent() instanceof CommentReferen ce)) { |
3003 element = resolver.getNameScope().lookup( | 3021 element = resolver.getNameScope().lookup( |
3004 new SyntheticIdentifier(node.getName() + "="), | 3022 new SyntheticIdentifier(node.getName() + "=", node), |
3005 definingLibrary); | 3023 definingLibrary); |
3006 } | 3024 } |
3007 ClassElement enclosingClass = resolver.getEnclosingClass(); | 3025 ClassElement enclosingClass = resolver.getEnclosingClass(); |
3008 if (element == null && enclosingClass != null) { | 3026 if (element == null && enclosingClass != null) { |
3009 InterfaceType enclosingType = enclosingClass.getType(); | 3027 InterfaceType enclosingType = enclosingClass.getType(); |
3010 if (element == null | 3028 if (element == null |
3011 && (node.inSetterContext() || node.getParent() instanceof CommentRefer ence)) { | 3029 && (node.inSetterContext() || node.getParent() instanceof CommentRefer ence)) { |
3012 element = lookUpSetter(null, enclosingType, node.getName()); | 3030 element = lookUpSetter(null, enclosingType, node.getName()); |
3013 } | 3031 } |
3014 if (element == null && node.inGetterContext()) { | 3032 if (element == null && node.inGetterContext()) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3097 * @param member the result of the look-up | 3115 * @param member the result of the look-up |
3098 * @return {@code true} if we should report an error | 3116 * @return {@code true} if we should report an error |
3099 */ | 3117 */ |
3100 private boolean shouldReportMissingMember(Type type, Element member) { | 3118 private boolean shouldReportMissingMember(Type type, Element member) { |
3101 if (member != null || type == null || type.isDynamic() || type.isBottom()) { | 3119 if (member != null || type == null || type.isDynamic() || type.isBottom()) { |
3102 return false; | 3120 return false; |
3103 } | 3121 } |
3104 return true; | 3122 return true; |
3105 } | 3123 } |
3106 } | 3124 } |
OLD | NEW |