mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
couple more pieces of JavaCoreEnvironment
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.components.ServiceManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class CoreJavaDirectoryService extends JavaDirectoryService {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.core.CoreJavaDirectoryService");
|
||||
|
||||
@Override
|
||||
public PsiPackage getPackage(@NotNull PsiDirectory dir) {
|
||||
return ServiceManager.getService(dir.getProject(), CoreJavaFileManager.class).getPackage(dir);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClass[] getClasses(@NotNull PsiDirectory dir) {
|
||||
LOG.assertTrue(dir.isValid());
|
||||
|
||||
List<PsiClass> classes = null;
|
||||
for (PsiFile file : dir.getFiles()) {
|
||||
if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
|
||||
PsiClass[] psiClasses = ((PsiClassOwner)file).getClasses();
|
||||
if (psiClasses.length == 0) continue;
|
||||
if (classes == null) classes = new ArrayList<PsiClass>();
|
||||
ContainerUtil.addAll(classes, psiClasses);
|
||||
}
|
||||
}
|
||||
return classes == null ? PsiClass.EMPTY_ARRAY : classes.toArray(new PsiClass[classes.size()]);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClass createClass(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClass createClass(@NotNull PsiDirectory dir, @NotNull String name, @NotNull String templateName)
|
||||
throws IncorrectOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiClass createClass(@NotNull PsiDirectory dir,
|
||||
@NotNull String name,
|
||||
@NotNull String templateName,
|
||||
boolean askForUndefinedVariables) throws IncorrectOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkCreateClass(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClass createInterface(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClass createEnum(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClass createAnnotationType(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSourceRoot(@NotNull PsiDirectory dir) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LanguageLevel getLanguageLevel(@NotNull PsiDirectory dir) {
|
||||
return LanguageLevel.HIGHEST;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.core;
|
||||
|
||||
import com.intellij.openapi.roots.PackageIndex;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem;
|
||||
import com.intellij.openapi.vfs.local.CoreLocalFileSystem;
|
||||
@@ -70,6 +71,18 @@ public class CoreJavaFileManager extends PackageIndex implements JavaFileManager
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiPackage getPackage(PsiDirectory dir) {
|
||||
final File ioFile = new File(dir.getVirtualFile().getPath());
|
||||
for (File root : myClasspath) {
|
||||
if (FileUtil.isAncestor(root, ioFile, false)) {
|
||||
final String relativePath = FileUtil.getRelativePath(root.getPath(), ioFile.getPath(), '.');
|
||||
return new PsiPackageImpl(myPsiManager, relativePath);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private VirtualFile findUnderClasspathEntry(File classpathEntry, String relativeName) {
|
||||
if (classpathEntry.isFile()) {
|
||||
|
||||
@@ -62,8 +62,11 @@ public class JavaCoreEnvironment extends CoreEnvironment {
|
||||
registerExtensionPoint(Extensions.getRootArea(), ClsStubBuilderFactory.EP_NAME, ClsStubBuilderFactory.class);
|
||||
addExtension(ClsStubBuilderFactory.EP_NAME, new DefaultClsStubBuilderFactory());
|
||||
|
||||
myApplication.registerService(PsiPackageImplementationHelper.class, new CorePsiPackageImplementationHelper());
|
||||
|
||||
myFileManager = new CoreJavaFileManager(myPsiManager, getLocalFileSystem(), myJarFileSystem);
|
||||
JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(myProject, myPsiManager, myFileManager, null);
|
||||
myProject.registerService(CoreJavaFileManager.class, myFileManager);
|
||||
registerComponentInstance(myProject.getPicoContainer(),
|
||||
JavaPsiFacade.class,
|
||||
javaPsiFacade);
|
||||
@@ -72,10 +75,10 @@ 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());
|
||||
myApplication.registerService(JavaDirectoryService.class, new CoreJavaDirectoryService());
|
||||
}
|
||||
|
||||
public void addToClasspath(File path) {
|
||||
|
||||
Reference in New Issue
Block a user