001/*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
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 */
020package org.sonar.api.resources;
021
022public class Method extends Resource {
023
024  public static final String SCOPE = Scopes.BLOCK_UNIT;
025
026  protected String qualifier;
027  protected Language language;
028
029  protected Method(String key, String qualifier, Language language) {
030    setKey(key);
031    this.qualifier = qualifier;
032    this.language = language;
033  }
034
035  @Override
036  public String getName() {
037    return getKey();
038  }
039
040  @Override
041  public String getLongName() {
042    return getKey();
043  }
044
045  @Override
046  public String getDescription() {
047    return null;
048  }
049
050  @Override
051  public final Language getLanguage() {
052    return language;
053  }
054
055  @Override
056  public final String getScope() {
057    return SCOPE;
058  }
059
060  @Override
061  public final String getQualifier() {
062    return qualifier;
063  }
064
065  @Override
066  public Resource getParent() {
067    return null;
068  }
069
070  @Override
071  public final boolean matchFilePattern(String antPattern) {
072    return false;
073  }
074
075  @Override
076  public final boolean equals(Object o) {
077    if (this == o) {
078      return true;
079    }
080    if (!(o instanceof Method)) {
081      return false;
082    }
083    Method method = (Method) o;
084    if (!getKey().equals(method.getKey())) {
085      return false;
086    }
087    if (!qualifier.equals(method.qualifier)) {
088      return false;
089    }
090    return true;
091  }
092
093  @Override
094  public final int hashCode() {
095    int result = super.hashCode();
096    result = 31 * result + qualifier.hashCode();
097    result = 31 * result + getKey().hashCode();
098    return result;
099  }
100
101  public static Method createMethod(String key, Language language) {
102    return new Method(key, Qualifiers.METHOD, language);
103  }
104}