001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2009 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.java.bytecode.asm; 021 022 import java.util.Collection; 023 import java.util.HashMap; 024 import java.util.Map; 025 026 import org.objectweb.asm.Opcodes; 027 028 public class AsmClass extends AsmUnit { 029 030 private String className; 031 private Map<String, AsmMethod> methods = new HashMap<String, AsmMethod>(); 032 private Map<String, AsmField> fields = new HashMap<String, AsmField>(); 033 034 public AsmClass(int access, String className) { 035 super(access); 036 this.className = className; 037 } 038 039 boolean isAbstract() { 040 return (access & Opcodes.ACC_ABSTRACT) != 0; 041 } 042 043 boolean isInterface() { 044 return (access & Opcodes.ACC_INTERFACE) != 0; 045 } 046 047 String getClassName() { 048 return className; 049 } 050 051 void addMethod(AsmMethod asmMethod) { 052 methods.put(asmMethod.getKey(), asmMethod); 053 } 054 055 Collection<AsmMethod> getMethods() { 056 return methods.values(); 057 } 058 059 Collection<AsmField> getFields() { 060 return fields.values(); 061 } 062 063 void addField(AsmField field) { 064 fields.put(field.getName(), field); 065 } 066 067 AsmField getField(String fieldName) { 068 return fields.get(fieldName); 069 } 070 071 AsmMethod getMethod(String key) { 072 return methods.get(key); 073 } 074 }