2 * Copyright (c) 2004 JetBrains s.r.o. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * -Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * -Redistribution in binary form must reproduct the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the distribution.
15 * Neither the name of JetBrains or IntelliJ IDEA
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * This software is provided "AS IS," without a warranty of any kind. ALL
20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
21 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
22 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT
23 * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
24 * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
25 * DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST
26 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
27 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
28 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
29 * IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 package com
.intellij
.pom
.java
.impl
;
34 import com
.intellij
.lang
.java
.JavaLanguage
;
35 import com
.intellij
.openapi
.components
.ProjectComponent
;
36 import com
.intellij
.openapi
.roots
.LanguageLevelProjectExtension
;
37 import com
.intellij
.pom
.PomModel
;
38 import com
.intellij
.pom
.PomModelAspect
;
39 import com
.intellij
.pom
.event
.PomModelEvent
;
40 import com
.intellij
.pom
.java
.LanguageLevel
;
41 import com
.intellij
.pom
.java
.PomJavaAspect
;
42 import com
.intellij
.pom
.java
.events
.JavaTreeChanged
;
43 import com
.intellij
.pom
.java
.events
.PomJavaAspectChangeSet
;
44 import com
.intellij
.pom
.tree
.TreeAspect
;
45 import com
.intellij
.pom
.tree
.events
.TreeChangeEvent
;
46 import com
.intellij
.psi
.PsiFile
;
47 import com
.intellij
.psi
.PsiManager
;
48 import org
.jetbrains
.annotations
.NotNull
;
50 import java
.util
.Collections
;
52 public class PomJavaAspectImpl
extends PomJavaAspect
implements ProjectComponent
{
53 private final PsiManager myPsiManager
;
54 private final PomModel myPomModel
;
56 public PomJavaAspectImpl(PsiManager psiManager
, TreeAspect treeAspect
, PomModel pomModel
) {
57 myPsiManager
= psiManager
;
58 myPomModel
= pomModel
;
59 pomModel
.registerAspect(PomJavaAspect
.class, this, Collections
.singleton((PomModelAspect
)treeAspect
));
62 public LanguageLevel
getLanguageLevel() {
63 return LanguageLevelProjectExtension
.getInstance(myPsiManager
.getProject()).getLanguageLevel();
66 public void projectOpened() {
69 public void projectClosed() {
73 public String
getComponentName() {
74 return "PomJavaModel";
77 public void initComponent() { }
79 public void disposeComponent() {
82 public void update(PomModelEvent event
) {
83 final TreeChangeEvent changeSet
= (TreeChangeEvent
)event
.getChangeSet(myPomModel
.getModelAspect(TreeAspect
.class));
84 if(changeSet
== null) return;
85 final PsiFile containingFile
= changeSet
.getRootElement().getPsi().getContainingFile();
86 if(!(containingFile
.getLanguage() instanceof JavaLanguage
)) return;
87 final PomJavaAspectChangeSet set
= new PomJavaAspectChangeSet(myPomModel
, containingFile
);
88 set
.addChange(new JavaTreeChanged(containingFile
));
89 event
.registerChangeSet(this, set
);