missing pieces of JavaCoreEnvironment

This commit is contained in:
Dmitry Jemerov
2011-12-19 16:17:35 +01:00
parent 10f3d1b980
commit 2af66fe1ad
5 changed files with 151 additions and 36 deletions
@@ -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;
}
}
@@ -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<File> myClasspath = new ArrayList<File>();
@@ -48,14 +51,23 @@ public class CoreJavaFileManager implements JavaFileManager {
@Override
public PsiPackage findPackage(@NotNull String packageName) {
final List<VirtualFile> files = findDirectoriesByPackageName(packageName);
if (files.size() > 0) {
return new PsiPackageImpl(myPsiManager, packageName);
}
return null;
}
private List<VirtualFile> findDirectoriesByPackageName(String packageName) {
List<VirtualFile> result = new ArrayList<VirtualFile>();
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<VirtualFile> getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
return new CollectionQuery<VirtualFile>(findDirectoriesByPackageName(packageName));
}
@Override
public PsiClass findClass(@NotNull String qName, @NotNull GlobalSearchScope scope) {
for (File file : myClasspath) {
@@ -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;
}
}
@@ -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());
}
@@ -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;
}
}