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
.facet
.Facet
;
20 import com
.intellij
.facet
.impl
.autodetecting
.model
.DetectedFacetInfo
;
21 import com
.intellij
.facet
.impl
.autodetecting
.model
.FacetInfo2
;
22 import com
.intellij
.facet
.impl
.autodetecting
.model
.FacetInfoBackedByFacet
;
23 import com
.intellij
.facet
.pointers
.FacetPointer
;
24 import com
.intellij
.facet
.pointers
.FacetPointersManager
;
25 import com
.intellij
.openapi
.module
.Module
;
26 import com
.intellij
.openapi
.diagnostic
.Logger
;
27 import com
.intellij
.util
.SmartList
;
28 import com
.intellij
.util
.fileIndex
.FileIndexEntry
;
29 import org
.jetbrains
.annotations
.Nullable
;
31 import java
.io
.DataInputStream
;
32 import java
.io
.DataOutputStream
;
33 import java
.io
.IOException
;
34 import java
.util
.Collection
;
35 import java
.util
.HashSet
;
36 import java
.util
.List
;
42 public class FacetDetectionIndexEntry
extends FileIndexEntry
{
43 private static final Logger LOG
= Logger
.getInstance("#com.intellij.facet.impl.autodetecting.FacetDetectionIndexEntry");
44 private SmartList
<FacetPointer
> myFacets
;
45 private SmartList
<Integer
> myDetectedFacetIds
;
47 public FacetDetectionIndexEntry(final long timestamp
) {
51 public FacetDetectionIndexEntry(final DataInputStream stream
, final FacetPointersManager facetPointersManager
) throws IOException
{
53 int size
= stream
.readInt();
56 String id
= stream
.readUTF();
57 if (id
.startsWith("/")) {
58 if (myDetectedFacetIds
== null) {
59 myDetectedFacetIds
= new SmartList
<Integer
>();
61 myDetectedFacetIds
.add(Integer
.parseInt(id
.substring(1)));
64 if (myFacets
== null) {
65 myFacets
= new SmartList
<FacetPointer
>();
67 myFacets
.add(facetPointersManager
.create(id
));
74 public SmartList
<FacetPointer
> getFacets() {
79 public SmartList
<Integer
> getDetectedFacetIds() {
80 return myDetectedFacetIds
;
83 public void write(final DataOutputStream stream
) throws IOException
{
85 int number
= (myFacets
!= null ? myFacets
.size() : 0) + (myDetectedFacetIds
!= null ? myDetectedFacetIds
.size() : 0);
86 stream
.writeInt(number
);
87 if (myFacets
!= null) {
88 for (FacetPointer facetPointer
: myFacets
) {
89 stream
.writeUTF(facetPointer
.getId());
92 if (myDetectedFacetIds
!= null) {
93 for (Integer id
: myDetectedFacetIds
) {
94 stream
.writeUTF("/" + id
);
100 public Collection
<Integer
> update(final FacetPointersManager facetPointersManager
, final @Nullable List
<FacetInfo2
<Module
>> detectedFacets
) {
101 if (detectedFacets
== null || detectedFacets
.isEmpty()) {
102 SmartList
<Integer
> old
= myDetectedFacetIds
;
104 myDetectedFacetIds
= null;
108 if (myFacets
== null) {
109 myFacets
= new SmartList
<FacetPointer
>();
115 if (myDetectedFacetIds
== null) {
116 myDetectedFacetIds
= new SmartList
<Integer
>();
119 Set
<Integer
> toRemove
= new HashSet
<Integer
>(myDetectedFacetIds
);
120 for (FacetInfo2
<Module
> info
: detectedFacets
) {
121 if (info
instanceof FacetInfoBackedByFacet
) {
122 FacetPointer
<Facet
> pointer
= facetPointersManager
.create(((FacetInfoBackedByFacet
)info
).getFacet());
123 LOG
.assertTrue(pointer
.getModuleName().length() > 0);//IDEADEV-34200
124 myFacets
.add(pointer
);
127 Integer id
= ((DetectedFacetInfo
)info
).getId();
128 boolean removed
= toRemove
.remove(id
);
130 myDetectedFacetIds
.add(id
);
134 myDetectedFacetIds
.removeAll(toRemove
);
138 public void remove(final FacetPointer facetPointer
) {
139 if (myFacets
!= null) {
140 myFacets
.remove(facetPointer
);
144 public void remove(final Integer id
) {
145 if (myDetectedFacetIds
!= null) {
146 myDetectedFacetIds
.remove(id
);
150 public void add(final FacetPointer
<Facet
> pointer
) {
151 if (myFacets
== null) {
152 myFacets
= new SmartList
<FacetPointer
>();
154 LOG
.assertTrue(pointer
.getModuleName().length() > 0);//IDEADEV-34200
155 myFacets
.add(pointer
);