2 * Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved.
5 package com
.intellij
.facet
.impl
.autodetecting
;
7 import com
.intellij
.facet
.Facet
;
8 import com
.intellij
.facet
.impl
.autodetecting
.model
.DetectedFacetInfo
;
9 import com
.intellij
.facet
.impl
.autodetecting
.model
.FacetInfo2
;
10 import com
.intellij
.facet
.impl
.autodetecting
.model
.FacetInfoBackedByFacet
;
11 import com
.intellij
.facet
.pointers
.FacetPointer
;
12 import com
.intellij
.facet
.pointers
.FacetPointersManager
;
13 import com
.intellij
.openapi
.module
.Module
;
14 import com
.intellij
.util
.SmartList
;
15 import com
.intellij
.util
.fileIndex
.FileIndexEntry
;
16 import org
.jetbrains
.annotations
.Nullable
;
18 import java
.io
.DataInputStream
;
19 import java
.io
.DataOutputStream
;
20 import java
.io
.IOException
;
21 import java
.util
.Collection
;
22 import java
.util
.HashSet
;
23 import java
.util
.List
;
29 public class FacetDetectionIndexEntry
extends FileIndexEntry
{
30 private SmartList
<FacetPointer
> myFacets
;
31 private SmartList
<Integer
> myDetectedFacetIds
;
33 public FacetDetectionIndexEntry(final long timestamp
) {
37 public FacetDetectionIndexEntry(final DataInputStream stream
, final FacetPointersManager facetPointersManager
) throws IOException
{
39 int size
= stream
.readInt();
42 String id
= stream
.readUTF();
43 if (id
.startsWith("/")) {
44 if (myDetectedFacetIds
== null) {
45 myDetectedFacetIds
= new SmartList
<Integer
>();
47 myDetectedFacetIds
.add(Integer
.parseInt(id
.substring(1)));
50 if (myFacets
== null) {
51 myFacets
= new SmartList
<FacetPointer
>();
53 myFacets
.add(facetPointersManager
.create(id
));
60 public SmartList
<FacetPointer
> getFacets() {
65 public SmartList
<Integer
> getDetectedFacetIds() {
66 return myDetectedFacetIds
;
69 public void write(final DataOutputStream stream
) throws IOException
{
71 int number
= (myFacets
!= null ? myFacets
.size() : 0) + (myDetectedFacetIds
!= null ? myDetectedFacetIds
.size() : 0);
72 stream
.writeInt(number
);
73 if (myFacets
!= null) {
74 for (FacetPointer facetPointer
: myFacets
) {
75 stream
.writeUTF(facetPointer
.getId());
78 if (myDetectedFacetIds
!= null) {
79 for (Integer id
: myDetectedFacetIds
) {
80 stream
.writeUTF("/" + id
);
86 public Collection
<Integer
> update(final FacetPointersManager facetPointersManager
, final @Nullable List
<FacetInfo2
<Module
>> detectedFacets
) {
87 if (detectedFacets
== null || detectedFacets
.isEmpty()) {
88 SmartList
<Integer
> old
= myDetectedFacetIds
;
90 myDetectedFacetIds
= null;
94 if (myFacets
== null) {
95 myFacets
= new SmartList
<FacetPointer
>();
101 if (myDetectedFacetIds
== null) {
102 myDetectedFacetIds
= new SmartList
<Integer
>();
105 Set
<Integer
> toRemove
= new HashSet
<Integer
>(myDetectedFacetIds
);
106 for (FacetInfo2
<Module
> info
: detectedFacets
) {
107 if (info
instanceof FacetInfoBackedByFacet
) {
108 FacetPointer
<Facet
> pointer
= facetPointersManager
.create(((FacetInfoBackedByFacet
)info
).getFacet());
109 myFacets
.add(pointer
);
112 Integer id
= ((DetectedFacetInfo
)info
).getId();
113 boolean removed
= toRemove
.remove(id
);
115 myDetectedFacetIds
.add(id
);
119 myDetectedFacetIds
.removeAll(toRemove
);
123 public void remove(final FacetPointer facetPointer
) {
124 if (myFacets
!= null) {
125 myFacets
.remove(facetPointer
);
129 public void remove(final Integer id
) {
130 if (myDetectedFacetIds
!= null) {
131 myDetectedFacetIds
.remove(id
);
135 public void add(final FacetPointer
<Facet
> pointer
) {
136 if (myFacets
== null) {
137 myFacets
= new SmartList
<FacetPointer
>();
139 myFacets
.add(pointer
);