1 /******************************************************************************* 2 * Copyright (c) 2000, 2014 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 * Stephan Herrmann - Contribution for 11 * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) 12 * Bug 427438 - [1.8][compiler] NPE at org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.generateCode(ConditionalExpression.java:280) 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.compiler.ast; 15 16 import org.eclipse.jdt.internal.compiler.flow.FlowContext; 17 import org.eclipse.jdt.internal.compiler.flow.FlowInfo; 18 import org.eclipse.jdt.internal.compiler.lookup.BlockScope; 19 import org.eclipse.jdt.internal.compiler.lookup.InferenceContext18; 20 import org.eclipse.jdt.internal.compiler.lookup.InvocationSite; 21 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; 22 import org.eclipse.jdt.internal.compiler.lookup.Scope; 23 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; 24 25 public abstract class AbstractVariableDeclaration extends Statement implements InvocationSite { 26 public int declarationEnd; 27 /** 28 * For local declarations (outside of for statement initialization) and field declarations, 29 * the declarationSourceEnd covers multiple locals if any. 30 * For local declarations inside for statement initialization, this is not the case. 31 */ 32 public int declarationSourceEnd; 33 public int declarationSourceStart; 34 public int hiddenVariableDepth; // used to diagnose hiding scenarii 35 public Expression initialization; 36 public int modifiers; 37 public int modifiersSourceStart; 38 public Annotation[] annotations; 39 40 public char[] name; 41 42 public TypeReference type; 43 analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo)44 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { 45 return flowInfo; 46 } 47 48 public static final int FIELD = 1; 49 public static final int INITIALIZER = 2; 50 public static final int ENUM_CONSTANT = 3; 51 public static final int LOCAL_VARIABLE = 4; 52 public static final int PARAMETER = 5; 53 public static final int TYPE_PARAMETER = 6; 54 55 56 /** 57 * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#genericTypeArguments() 58 */ genericTypeArguments()59 public TypeBinding[] genericTypeArguments() { 60 return null; 61 } 62 63 /** 64 * Returns the constant kind of this variable declaration 65 */ getKind()66 public abstract int getKind(); 67 freshInferenceContext(Scope scope)68 public InferenceContext18 freshInferenceContext(Scope scope) { 69 return null; 70 } 71 72 /* (non-Javadoc) 73 * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isSuperAccess() 74 */ isSuperAccess()75 public boolean isSuperAccess() { 76 return false; 77 } 78 79 /* (non-Javadoc) 80 * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#isTypeAccess() 81 */ isTypeAccess()82 public boolean isTypeAccess() { 83 return false; 84 } 85 printStatement(int indent, StringBuffer output)86 public StringBuffer printStatement(int indent, StringBuffer output) { 87 printAsExpression(indent, output); 88 switch(getKind()) { 89 case ENUM_CONSTANT: 90 return output.append(','); 91 default: 92 return output.append(';'); 93 } 94 } 95 printAsExpression(int indent, StringBuffer output)96 public StringBuffer printAsExpression(int indent, StringBuffer output) { 97 printIndent(indent, output); 98 printModifiers(this.modifiers, output); 99 if (this.annotations != null) { 100 printAnnotations(this.annotations, output); 101 output.append(' '); 102 } 103 104 if (this.type != null) { 105 this.type.print(0, output).append(' '); 106 } 107 output.append(this.name); 108 switch(getKind()) { 109 case ENUM_CONSTANT: 110 if (this.initialization != null) { 111 this.initialization.printExpression(indent, output); 112 } 113 break; 114 default: 115 if (this.initialization != null) { 116 output.append(" = "); //$NON-NLS-1$ 117 this.initialization.printExpression(indent, output); 118 } 119 } 120 return output; 121 } 122 resolve(BlockScope scope)123 public void resolve(BlockScope scope) { 124 // do nothing by default (redefined for local variables) 125 } 126 127 /* (non-Javadoc) 128 * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#setActualReceiverType(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) 129 */ setActualReceiverType(ReferenceBinding receiverType)130 public void setActualReceiverType(ReferenceBinding receiverType) { 131 // do nothing by default 132 } 133 134 /* (non-Javadoc) 135 * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#setDepth(int) 136 */ setDepth(int depth)137 public void setDepth(int depth) { 138 139 this.hiddenVariableDepth = depth; 140 } 141 142 /* (non-Javadoc) 143 * @see org.eclipse.jdt.internal.compiler.lookup.InvocationSite#setFieldIndex(int) 144 */ setFieldIndex(int depth)145 public void setFieldIndex(int depth) { 146 // do nothing by default 147 } 148 } 149