ensure dispose, assert double dispose
[fedora-idea.git] / platform / lang-api / src / com / intellij / facet / Facet.java
blob61a68e9438b8d71c316b28152c7bd68e154fc666
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;
19 import com.intellij.openapi.Disposable;
20 import com.intellij.openapi.util.Disposer;
21 import com.intellij.openapi.util.UserDataHolderBase;
22 import com.intellij.openapi.util.UserDataHolder;
23 import com.intellij.openapi.module.Module;
24 import org.jetbrains.annotations.NotNull;
26 /**
27 * Represents a specific instance of facet
29 * @see FacetType
31 * @author nik
33 public class Facet<C extends FacetConfiguration> extends UserDataHolderBase implements UserDataHolder, Disposable {
34 public static final Facet[] EMPTY_ARRAY = new Facet[0];
35 @NotNull private final FacetType myFacetType;
36 @NotNull private final Module myModule;
37 @NotNull private final C myConfiguration;
38 private final Facet myUnderlyingFacet;
39 private String myName;
40 private boolean myImplicit;
41 private boolean isDisposed;
43 public Facet(@NotNull final FacetType facetType, @NotNull final Module module, @NotNull final String name, @NotNull final C configuration, Facet underlyingFacet) {
44 myName = name;
45 myFacetType = facetType;
46 myModule = module;
47 myConfiguration = configuration;
48 myUnderlyingFacet = underlyingFacet;
49 Disposer.register(myModule, this);
52 @NotNull
53 public final FacetType getType() {
54 return myFacetType;
57 public final FacetTypeId getTypeId() {
58 return myFacetType.getId();
61 public final Facet getUnderlyingFacet() {
62 return myUnderlyingFacet;
65 @NotNull
66 public final C getConfiguration() {
67 return myConfiguration;
70 @NotNull
71 public final Module getModule() {
72 return myModule;
75 @Deprecated
76 public final boolean isImplicit() {
77 return myImplicit;
80 @Deprecated
81 public final void setImplicit(final boolean implicit) {
82 myImplicit = implicit;
85 /**
86 * Called when the module containing this facet is initialized
88 public void initFacet() {
91 /**
92 * Called when the module containing this facet is disposed
94 public void disposeFacet() {
97 public final void dispose() {
98 assert !isDisposed;
99 isDisposed = true;
100 disposeFacet();
103 public final int hashCode() {
104 return super.hashCode();
107 @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"})
108 public final boolean equals(Object obj) {
109 return super.equals(obj);
112 @NotNull
113 public final String getName() {
114 return myName;
118 * Use {@link com.intellij.facet.ModifiableFacetModel#rename} to rename facets
120 final void setName(@NotNull final String name) {
121 myName = name;