update copyright
[fedora-idea.git] / java / idea-ui / src / com / intellij / facet / impl / autodetecting / DisabledAutodetectionByTypeElement.java
blob0a157a2a982697956bc30d1e954e2021aec8836e
1 /*
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.
17 package com.intellij.facet.impl.autodetecting;
19 import com.intellij.util.xmlb.annotations.AbstractCollection;
20 import com.intellij.util.xmlb.annotations.Attribute;
21 import com.intellij.util.xmlb.annotations.Tag;
22 import com.intellij.openapi.util.SystemInfo;
23 import com.intellij.openapi.util.text.StringUtil;
24 import org.jetbrains.annotations.NotNull;
25 import org.jetbrains.annotations.Nullable;
27 import java.util.ArrayList;
28 import java.util.Iterator;
29 import java.util.List;
31 /**
32 * @author nik
34 @Tag("facet-type")
35 public class DisabledAutodetectionByTypeElement {
36 private String myFacetTypeId;
37 private List<DisabledAutodetectionInModuleElement> myModuleElements = new ArrayList<DisabledAutodetectionInModuleElement>();
39 public DisabledAutodetectionByTypeElement() {
42 public DisabledAutodetectionByTypeElement(final String facetTypeId) {
43 myFacetTypeId = facetTypeId;
46 public DisabledAutodetectionByTypeElement(String facetTypeId, String moduleName) {
47 this(facetTypeId);
48 myModuleElements.add(new DisabledAutodetectionInModuleElement(moduleName));
51 public DisabledAutodetectionByTypeElement(String facetTypeId, String moduleName, String url, final boolean recursively) {
52 this(facetTypeId);
53 myModuleElements.add(new DisabledAutodetectionInModuleElement(moduleName, url, recursively));
56 @Attribute("id")
57 public String getFacetTypeId() {
58 return myFacetTypeId;
61 @Tag("modules")
62 @AbstractCollection(surroundWithTag = false)
63 public List<DisabledAutodetectionInModuleElement> getModuleElements() {
64 return myModuleElements;
67 public void setFacetTypeId(final String facetTypeId) {
68 myFacetTypeId = facetTypeId;
71 public void setModuleElements(final List<DisabledAutodetectionInModuleElement> moduleElements) {
72 myModuleElements = moduleElements;
75 public void addDisabled(@NotNull String moduleName) {
76 if (myModuleElements.isEmpty()) return;
78 DisabledAutodetectionInModuleElement element = findElement(moduleName);
79 if (element != null) {
80 element.getFiles().clear();
81 element.getDirectories().clear();
82 return;
85 myModuleElements.add(new DisabledAutodetectionInModuleElement(moduleName));
88 public void disableInProject() {
89 myModuleElements.clear();
92 public void addDisabled(@NotNull String moduleName, @NotNull String fileUrl, final boolean recursively) {
93 if (myModuleElements.isEmpty()) return;
95 DisabledAutodetectionInModuleElement element = findElement(moduleName);
96 if (element != null) {
97 if (!element.isDisableInWholeModule()) {
98 if (recursively) {
99 element.getDirectories().add(fileUrl);
101 else {
102 element.getFiles().add(fileUrl);
105 return;
107 myModuleElements.add(new DisabledAutodetectionInModuleElement(moduleName, fileUrl, recursively));
110 @Nullable
111 public DisabledAutodetectionInModuleElement findElement(final @NotNull String moduleName) {
112 for (DisabledAutodetectionInModuleElement element : myModuleElements) {
113 if (moduleName.equals(element.getModuleName())) {
114 return element;
117 return null;
120 public boolean equals(final Object o) {
121 if (this == o) return true;
122 if (o == null || getClass() != o.getClass()) return false;
124 final DisabledAutodetectionByTypeElement that = (DisabledAutodetectionByTypeElement)o;
125 return myFacetTypeId.equals(that.myFacetTypeId) && myModuleElements.equals(that.myModuleElements);
129 public int hashCode() {
130 return myFacetTypeId.hashCode()+ 31 * myModuleElements.hashCode();
133 public boolean isDisabled(final String moduleName, final String url) {
134 if (myModuleElements.isEmpty()) return true;
136 DisabledAutodetectionInModuleElement element = findElement(moduleName);
137 if (element == null) return false;
139 if (element.isDisableInWholeModule() || element.getFiles().contains(url)) {
140 return true;
142 for (String directoryUrl : element.getDirectories()) {
143 if (!directoryUrl.endsWith("/")) {
144 directoryUrl += "/";
146 if (url.startsWith(directoryUrl) || !SystemInfo.isFileSystemCaseSensitive && StringUtil.startsWithIgnoreCase(url, directoryUrl)) {
147 return true;
150 return false;
153 public boolean removeDisabled(final String moduleName) {
154 Iterator<DisabledAutodetectionInModuleElement> iterator = myModuleElements.iterator();
155 while (iterator.hasNext()) {
156 DisabledAutodetectionInModuleElement element = iterator.next();
157 if (element.getModuleName().equals(moduleName)) {
158 iterator.remove();
159 break;
162 return myModuleElements.size() > 0;