2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements;
18 import com.intellij.openapi.project.Project;
19 import org.jetbrains.annotations.Nullable;
20 import org.jetbrains.plugins.groovy.annotator.intentions.QuickfixUtil;
21 import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManager;
22 import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.MyPair;
27 * User: Dmitry.Krasilschikov
30 public class DClassElement implements DNamedElement {
32 public Set<DPropertyElement> myProperties = new HashSet<DPropertyElement>();
33 public Set<DMethodElement> myMethods = new HashSet<DMethodElement>();
35 public DClassElement(Project project, String name) {
37 DynamicManager.getInstance(project).getRootElement().mergeAddClass(this);
40 public void addMethod(DMethodElement methodElement) {
41 myMethods.add(methodElement);
44 void addMethods(Collection<DMethodElement> methods) {
45 myMethods.addAll(methods);
48 public void addProperty(DPropertyElement propertyElement) {
49 myProperties.add(propertyElement);
52 protected void addProperties(Collection<DPropertyElement> properties) {
53 for (DPropertyElement property : properties) {
54 addProperty(property);
59 public DPropertyElement getPropertyByName(String propertyName) {
60 for (final DPropertyElement property : myProperties) {
61 if (propertyName.equals(property.getName())) {
68 public Collection<DPropertyElement> getProperties() {
72 public Set<DMethodElement> getMethods() {
76 public String getName() {
80 public void setName(String name) {
84 public void removeProperty(DPropertyElement name) {
85 myProperties.remove(name);
88 public boolean removeMethod(DMethodElement methodElement) {
89 return myMethods.remove(methodElement);
92 public boolean equals(Object o) {
93 if (this == o) return true;
94 if (o == null || getClass() != o.getClass()) return false;
96 DClassElement that = (DClassElement) o;
98 if (myName != null ? !myName.equals(that.myName) : that.myName != null) return false;
103 public int hashCode() {
105 result = (myName != null ? myName.hashCode() : 0);
106 result = 31 * result + (myProperties != null ? myProperties.hashCode() : 0);
107 result = 31 * result + (myMethods != null ? myMethods.hashCode() : 0);
112 public DMethodElement getMethod(String methodName, String[] parametersTypes) {
113 for (DMethodElement method : myMethods) {
114 final List<MyPair> myPairList = method.getPairs();
115 if (method.getName().equals(methodName)
116 && Arrays.equals(QuickfixUtil.getArgumentsTypes(myPairList), parametersTypes)) return method;
121 public boolean containsElement(DItemElement itemElement){
122 //noinspection SuspiciousMethodCalls
123 return myProperties.contains(itemElement) ||
124 (itemElement instanceof DMethodElement && myMethods.contains(itemElement));