@Override IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) { org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration); if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) { AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization; return getMethodBinding(allocationExpression.binding); } } return null; }
IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) { org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration); if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) { AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization; return getMethodBinding(allocationExpression.binding); } } return null; }
IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) { org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration); if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) { AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization; return getMethodBinding(allocationExpression.binding); } } return null; }
IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) { org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration); if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) { AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization; return getMethodBinding(allocationExpression.binding); } } return null; }
IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) { org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration); if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) { AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization; return getMethodBinding(allocationExpression.binding); } } return null; }
IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) { org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration); if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) { AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization; return getMethodBinding(allocationExpression.binding); } } return null; }
public RecoveredElement updateOnOpeningBrace(int braceStart, int braceEnd){ if (this.fieldDeclaration.declarationSourceEnd == 0 && (this.fieldDeclaration.type instanceof ArrayTypeReference || this.fieldDeclaration.type instanceof ArrayQualifiedTypeReference) && !this.alreadyCompletedFieldInitialization){ this.bracketBalance++; return null; // no update is necessary (array initializer) } if (this.fieldDeclaration.declarationSourceEnd == 0 && this.fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT){ this.bracketBalance++; return null; // no update is necessary (enum constant) } // might be an array initializer this.updateSourceEndIfNecessary(braceStart - 1, braceEnd - 1); return this.parent.updateOnOpeningBrace(braceStart, braceEnd); } public void updateParseTree(){
public RecoveredElement add(Statement statement, int bracketBalanceValue) { if (this.alreadyCompletedFieldInitialization || !(statement instanceof Expression)) { return super.add(statement, bracketBalanceValue); } else { if (statement.sourceEnd > 0) this.alreadyCompletedFieldInitialization = true; // else we may still be inside the initialization, having parsed only a part of it yet if (!(statement instanceof AllocationExpression) && this.fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { AllocationExpression alloc = new AllocationExpression(); alloc.arguments = new Expression[] {(Expression) statement}; this.fieldDeclaration.initialization = alloc; } else { this.fieldDeclaration.initialization = (Expression) statement; this.fieldDeclaration.declarationSourceEnd = statement.sourceEnd; this.fieldDeclaration.declarationEnd = statement.sourceEnd; } return this; } } /*
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) { // no local used this.maxLocals = 0; // generate all enum constants SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass; TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope; FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, this); } } } return_(); } public void generateSyntheticBodyForFieldReadAccess(SyntheticMethodBinding accessMethod) {
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) { // no local used this.maxLocals = 0; // generate all enum constants SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass; TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope; FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, this); } } } return_(); } public void generateSyntheticBodyForFieldReadAccess(SyntheticMethodBinding accessMethod) {
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) { // no local used this.maxLocals = 0; // generate all enum constants SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass; TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope; FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, this); } } } return_(); } public void generateSyntheticBodyForFieldReadAccess(SyntheticMethodBinding accessMethod) {
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) { // no local used this.maxLocals = 0; // generate all enum constants SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass; TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope; FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, this); } } } return_(); } public void generateSyntheticBodyForFieldReadAccess(SyntheticMethodBinding accessMethod) {
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) { // no local used this.maxLocals = 0; // generate all enum constants SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass; TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope; FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, this); } } } return_(); } public void generateSyntheticBodyForFieldReadAccess(SyntheticMethodBinding accessMethod) {
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) { // no local used this.maxLocals = 0; // generate all enum constants SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass; TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope; FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, this); } } } return_(); } public void generateSyntheticBodyForFieldReadAccess(SyntheticMethodBinding accessMethod) {
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) { // no local used this.maxLocals = 0; // generate all enum constants SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass; TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope; FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, this); } } } return_(); } public void generateSyntheticBodyForFieldReadAccess(SyntheticMethodBinding accessMethod) {
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) { // no local used this.maxLocals = 0; // generate all enum constants SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass; TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope; FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, this); } } } return_(); } public void generateSyntheticBodyForFieldReadAccess(SyntheticMethodBinding accessMethod) {
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) { // no local used this.maxLocals = 0; // generate all enum constants SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass; TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope; FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, this); } } } return_(); } public void generateSyntheticBodyForFieldReadAccess(SyntheticMethodBinding accessMethod) {
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) { // no local used this.maxLocals = 0; // generate all enum constants SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass; TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext; BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope; FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) { FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, this); } } } return_(); } public void generateSyntheticBodyForFieldReadAccess(SyntheticMethodBinding accessMethod) {
public int match(FieldDeclaration node, MatchingNodeSet nodeSet) { int referencesLevel = IMPOSSIBLE_MATCH; if (this.pattern.findReferences) // must be a write only access with an initializer if (this.pattern.writeAccess && !this.pattern.readAccess && node.initialization != null) if (matchesName(this.pattern.name, node.name)) referencesLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH; int declarationsLevel = IMPOSSIBLE_MATCH; if (this.pattern.findDeclarations) { switch (node.getKind()) { case AbstractVariableDeclaration.FIELD : case AbstractVariableDeclaration.ENUM_CONSTANT : if (matchesName(this.pattern.name, node.name)) if (matchesTypeReference(((FieldPattern)this.pattern).typeSimpleName, node.type)) declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH; break; } } return nodeSet.addMatch(node, referencesLevel >= declarationsLevel ? referencesLevel : declarationsLevel); // use the stronger match } //public int match(MethodDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
public int match(FieldDeclaration node, MatchingNodeSet nodeSet) { int referencesLevel = IMPOSSIBLE_MATCH; if (this.pattern.findReferences) // must be a write only access with an initializer if (this.pattern.writeAccess && !this.pattern.readAccess && node.initialization != null) if (matchesName(this.pattern.name, node.name)) referencesLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH; int declarationsLevel = IMPOSSIBLE_MATCH; if (this.pattern.findDeclarations) { switch (node.getKind()) { case AbstractVariableDeclaration.FIELD : case AbstractVariableDeclaration.ENUM_CONSTANT : if (matchesName(this.pattern.name, node.name)) if (matchesTypeReference(((FieldPattern)this.pattern).typeSimpleName, node.type)) declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH; break; } } return nodeSet.addMatch(node, referencesLevel >= declarationsLevel ? referencesLevel : declarationsLevel); // use the stronger match } //public int match(MethodDeclaration node, MatchingNodeSet nodeSet) - SKIP IT