1 /* |
1 /* |
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
31 import com.sun.tools.javac.code.*; |
31 import com.sun.tools.javac.code.*; |
32 import com.sun.tools.javac.code.Scope.WriteableScope; |
32 import com.sun.tools.javac.code.Scope.WriteableScope; |
33 import com.sun.tools.javac.tree.*; |
33 import com.sun.tools.javac.tree.*; |
34 import com.sun.tools.javac.util.*; |
34 import com.sun.tools.javac.util.*; |
35 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
35 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
36 import com.sun.tools.javac.util.JCDiagnostic.Error; |
36 |
37 |
37 import com.sun.tools.javac.code.Symbol.*; |
38 import com.sun.tools.javac.code.Symbol.*; |
38 import com.sun.tools.javac.code.Type.*; |
39 import com.sun.tools.javac.code.Type.*; |
39 import com.sun.tools.javac.resources.CompilerProperties.Errors; |
40 import com.sun.tools.javac.resources.CompilerProperties.Errors; |
40 import com.sun.tools.javac.tree.JCTree.*; |
41 import com.sun.tools.javac.tree.JCTree.*; |
303 } |
304 } |
304 |
305 |
305 v.pos = tree.pos; |
306 v.pos = tree.pos; |
306 } |
307 } |
307 // where |
308 // where |
308 void checkType(JCTree tree, Type type, String diag) { |
309 void checkType(JCTree tree, Type type, Error errorKey) { |
309 if (!tree.type.isErroneous() && !types.isSameType(tree.type, type)) { |
310 if (!tree.type.isErroneous() && !types.isSameType(tree.type, type)) { |
310 log.error(tree, diag, type, tree.type); |
311 log.error(tree, errorKey); |
311 } |
312 } |
312 } |
313 } |
313 void checkReceiver(JCVariableDecl tree, Env<AttrContext> localEnv) { |
314 void checkReceiver(JCVariableDecl tree, Env<AttrContext> localEnv) { |
314 attr.attribExpr(tree.nameexpr, localEnv); |
315 attr.attribExpr(tree.nameexpr, localEnv); |
315 MethodSymbol m = localEnv.enclMethod.sym; |
316 MethodSymbol m = localEnv.enclMethod.sym; |
318 if (outertype.hasTag(TypeTag.METHOD)) { |
319 if (outertype.hasTag(TypeTag.METHOD)) { |
319 // we have a local inner class |
320 // we have a local inner class |
320 outertype = m.owner.owner.owner.type; |
321 outertype = m.owner.owner.owner.type; |
321 } |
322 } |
322 if (outertype.hasTag(TypeTag.CLASS)) { |
323 if (outertype.hasTag(TypeTag.CLASS)) { |
323 checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); |
324 checkType(tree.vartype, outertype, Errors.IncorrectConstructorReceiverType(outertype, tree.vartype.type)); |
324 checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); |
325 checkType(tree.nameexpr, outertype, Errors.IncorrectConstructorReceiverName(outertype, tree.nameexpr.type)); |
325 } else { |
326 } else { |
326 log.error(tree, Errors.ReceiverParameterNotApplicableConstructorToplevelClass); |
327 log.error(tree, Errors.ReceiverParameterNotApplicableConstructorToplevelClass); |
327 } |
328 } |
328 } else { |
329 } else { |
329 checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); |
330 checkType(tree.vartype, m.owner.type, Errors.IncorrectReceiverType(m.owner.type, tree.vartype.type)); |
330 checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); |
331 checkType(tree.nameexpr, m.owner.type, Errors.IncorrectReceiverName(m.owner.type, tree.nameexpr.type)); |
331 } |
332 } |
332 } |
333 } |
333 |
334 |
334 public boolean needsLazyConstValue(JCTree tree) { |
335 public boolean needsLazyConstValue(JCTree tree) { |
335 InitTreeVisitor initTreeVisitor = new InitTreeVisitor(); |
336 InitTreeVisitor initTreeVisitor = new InitTreeVisitor(); |