diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaASTFactory.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaASTFactory.java index 97c290e66cdc..9549f72b7ed1 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaASTFactory.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaASTFactory.java @@ -15,24 +15,13 @@ */ package com.intellij.psi.impl.source.tree; -import com.intellij.lang.ASTFactory; -import com.intellij.lang.DefaultASTFactory; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.psi.impl.source.Constants; import com.intellij.psi.impl.source.javadoc.PsiDocTagValueImpl; -import com.intellij.psi.impl.source.javadoc.PsiDocTokenImpl; -import com.intellij.psi.impl.source.tree.java.PsiIdentifierImpl; -import com.intellij.psi.impl.source.tree.java.PsiJavaTokenImpl; -import com.intellij.psi.impl.source.tree.java.PsiKeywordImpl; import com.intellij.psi.tree.IElementType; -import com.intellij.psi.tree.java.IJavaDocElementType; -import com.intellij.psi.tree.java.IJavaElementType; /** * @author max */ -public class JavaASTFactory extends ASTFactory implements Constants { - private final DefaultASTFactory myDefaultASTFactory = ServiceManager.getService(DefaultASTFactory.class); +public class JavaASTFactory extends CoreJavaASTFactory { @Override public CompositeElement createComposite(final IElementType type) { @@ -42,25 +31,4 @@ public class JavaASTFactory extends ASTFactory implements Constants { return null; } - - @Override - public LeafElement createLeaf(final IElementType type, final CharSequence text) { - if (type == C_STYLE_COMMENT || type == END_OF_LINE_COMMENT) { - return myDefaultASTFactory.createComment(type, text); - } - else if (type == IDENTIFIER) { - return new PsiIdentifierImpl(text); - } - else if (KEYWORD_BIT_SET.contains(type)) { - return new PsiKeywordImpl(type, text); - } - else if (type instanceof IJavaElementType) { - return new PsiJavaTokenImpl(type, text); - } - else if (type instanceof IJavaDocElementType) { - return new PsiDocTokenImpl(type, text); - } - - return null; - } } diff --git a/java/java-psi-impl/src/com/intellij/core/CoreJavaFileManager.java b/java/java-psi-impl/src/com/intellij/core/CoreJavaFileManager.java index 834c1eae042b..57e42dca74e9 100644 --- a/java/java-psi-impl/src/com/intellij/core/CoreJavaFileManager.java +++ b/java/java-psi-impl/src/com/intellij/core/CoreJavaFileManager.java @@ -15,6 +15,7 @@ */ package com.intellij.core; +import com.intellij.openapi.roots.PackageIndex; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem; import com.intellij.openapi.vfs.local.CoreLocalFileSystem; @@ -22,6 +23,8 @@ import com.intellij.psi.*; import com.intellij.psi.impl.file.PsiPackageImpl; import com.intellij.psi.impl.file.impl.JavaFileManager; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.CollectionQuery; +import com.intellij.util.Query; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,7 +37,7 @@ import java.util.List; /** * @author yole */ -public class CoreJavaFileManager implements JavaFileManager { +public class CoreJavaFileManager extends PackageIndex implements JavaFileManager { private final CoreLocalFileSystem myLocalFileSystem; private final CoreJarFileSystem myJarFileSystem; private final List myClasspath = new ArrayList(); @@ -48,14 +51,23 @@ public class CoreJavaFileManager implements JavaFileManager { @Override public PsiPackage findPackage(@NotNull String packageName) { + final List files = findDirectoriesByPackageName(packageName); + if (files.size() > 0) { + return new PsiPackageImpl(myPsiManager, packageName); + } + return null; + } + + private List findDirectoriesByPackageName(String packageName) { + List result = new ArrayList(); String dirName = packageName.replace(".", "/"); for (File file : myClasspath) { VirtualFile classDir = findUnderClasspathEntry(file, dirName); if (classDir != null) { - return new PsiPackageImpl(myPsiManager, packageName); + result.add(classDir); } } - return null; + return result; } @Nullable @@ -68,6 +80,16 @@ public class CoreJavaFileManager implements JavaFileManager { } } + @Override + public VirtualFile[] getDirectoriesByPackageName(@NotNull String packageName, boolean includeLibrarySources) { + return getDirsByPackageName(packageName, includeLibrarySources).toArray(VirtualFile.EMPTY_ARRAY); + } + + @Override + public Query getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) { + return new CollectionQuery(findDirectoriesByPackageName(packageName)); + } + @Override public PsiClass findClass(@NotNull String qName, @NotNull GlobalSearchScope scope) { for (File file : myClasspath) { diff --git a/java/java-psi-impl/src/com/intellij/core/CorePsiPackageImplementationHelper.java b/java/java-psi-impl/src/com/intellij/core/CorePsiPackageImplementationHelper.java new file mode 100644 index 000000000000..752b1660d121 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/core/CorePsiPackageImplementationHelper.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.core; + +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiPackage; +import com.intellij.psi.impl.file.PsiPackageImplementationHelper; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.ArrayUtil; + +/** + * @author yole + */ +public class CorePsiPackageImplementationHelper extends PsiPackageImplementationHelper { + @Override + public GlobalSearchScope adjustAllScope(PsiPackage psiPackage, GlobalSearchScope globalSearchScope) { + return globalSearchScope; + } + + @Override + public VirtualFile[] occursInPackagePrefixes(PsiPackage psiPackage) { + return VirtualFile.EMPTY_ARRAY; + } + + @Override + public void handleQualifiedNameChange(PsiPackage psiPackage, String newQualifiedName) { + } + + @Override + public void navigate(PsiPackage psiPackage, boolean requestFocus) { + } + + @Override + public boolean packagePrefixExists(PsiPackage psiPackage) { + return false; + } + + @Override + public Object[] getDirectoryCachedValueDependencies(PsiPackage cachedValueProvider) { + return ArrayUtil.EMPTY_OBJECT_ARRAY; + } +} diff --git a/java/java-psi-impl/src/com/intellij/core/JavaCoreEnvironment.java b/java/java-psi-impl/src/com/intellij/core/JavaCoreEnvironment.java index 92000b6aee8d..373a014e4a02 100644 --- a/java/java-psi-impl/src/com/intellij/core/JavaCoreEnvironment.java +++ b/java/java-psi-impl/src/com/intellij/core/JavaCoreEnvironment.java @@ -16,9 +16,15 @@ package com.intellij.core; import com.intellij.ide.highlighter.JavaClassFileType; +import com.intellij.ide.highlighter.JavaFileType; +import com.intellij.lang.LanguageASTFactory; +import com.intellij.lang.LanguageParserDefinitions; +import com.intellij.lang.java.JavaLanguage; +import com.intellij.lang.java.JavaParserDefinition; import com.intellij.openapi.Disposable; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.openapi.roots.PackageIndex; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.impl.EmptySubstitutorImpl; @@ -28,7 +34,9 @@ import com.intellij.psi.impl.PsiElementFactoryImpl; import com.intellij.psi.impl.compiled.ClassFileStubBuilder; import com.intellij.psi.impl.compiled.ClsStubBuilderFactory; import com.intellij.psi.impl.compiled.DefaultClsStubBuilderFactory; +import com.intellij.psi.impl.file.PsiPackageImplementationHelper; import com.intellij.psi.impl.source.resolve.PsiResolveHelperImpl; +import com.intellij.psi.impl.source.tree.CoreJavaASTFactory; import com.intellij.psi.stubs.BinaryFileStubBuilders; import java.io.File; @@ -45,6 +53,10 @@ public class JavaCoreEnvironment extends CoreEnvironment { registerFileType(JavaClassFileType.INSTANCE, "class"); addExplicitExtension(FileTypeFileViewProviders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileViewProviderFactory()); addExplicitExtension(BinaryFileStubBuilders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileStubBuilder()); + + registerFileType(JavaFileType.INSTANCE, "java"); + addExplicitExtension(LanguageASTFactory.INSTANCE, JavaLanguage.INSTANCE, new CoreJavaASTFactory()); + addExplicitExtension(LanguageParserDefinitions.INSTANCE, JavaLanguage.INSTANCE, new JavaParserDefinition()); registerProjectExtensionPoint(PsiElementFinder.EP_NAME, PsiElementFinder.class); registerExtensionPoint(Extensions.getRootArea(), ClsStubBuilderFactory.EP_NAME, ClsStubBuilderFactory.class); @@ -60,6 +72,8 @@ public class JavaCoreEnvironment extends CoreEnvironment { myProject.registerService(JavaPsiImplementationHelper.class, new CoreJavaPsiImplementationHelper()); myProject.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(myPsiManager)); myProject.registerService(LanguageLevelProjectExtension.class, new CoreLanguageLevelProjectExtension()); + myProject.registerService(PsiPackageImplementationHelper.class, new CorePsiPackageImplementationHelper()); + myProject.registerService(PackageIndex.class, myFileManager); myApplication.registerService(EmptySubstitutor.class, new EmptySubstitutorImpl()); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/CoreJavaASTFactory.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/CoreJavaASTFactory.java new file mode 100644 index 000000000000..ffc35e117319 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/CoreJavaASTFactory.java @@ -0,0 +1,56 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.impl.source.tree; + +import com.intellij.lang.ASTFactory; +import com.intellij.lang.DefaultASTFactory; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.psi.impl.source.Constants; +import com.intellij.psi.impl.source.javadoc.PsiDocTokenImpl; +import com.intellij.psi.impl.source.tree.java.PsiIdentifierImpl; +import com.intellij.psi.impl.source.tree.java.PsiJavaTokenImpl; +import com.intellij.psi.impl.source.tree.java.PsiKeywordImpl; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.java.IJavaDocElementType; +import com.intellij.psi.tree.java.IJavaElementType; + +/** + * @author yole + */ +public class CoreJavaASTFactory extends ASTFactory implements Constants { + private final DefaultASTFactory myDefaultASTFactory = ServiceManager.getService(DefaultASTFactory.class); + + @Override + public LeafElement createLeaf(final IElementType type, final CharSequence text) { + if (type == C_STYLE_COMMENT || type == END_OF_LINE_COMMENT) { + return myDefaultASTFactory.createComment(type, text); + } + else if (type == IDENTIFIER) { + return new PsiIdentifierImpl(text); + } + else if (KEYWORD_BIT_SET.contains(type)) { + return new PsiKeywordImpl(type, text); + } + else if (type instanceof IJavaElementType) { + return new PsiJavaTokenImpl(type, text); + } + else if (type instanceof IJavaDocElementType) { + return new PsiDocTokenImpl(type, text); + } + + return null; + } +}