mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
towards working findClass(0
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.CommonBundle;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.PropertyKey;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JavaCoreBundle {
|
||||
private static Reference<ResourceBundle> ourBundle;
|
||||
|
||||
@NonNls private static final String BUNDLE = "messages.JavaCoreBundle";
|
||||
|
||||
private JavaCoreBundle() {
|
||||
}
|
||||
|
||||
public static String message(@PropertyKey(resourceBundle = BUNDLE)String key, Object... params) {
|
||||
return CommonBundle.message(getBundle(), key, params);
|
||||
}
|
||||
|
||||
private static ResourceBundle getBundle() {
|
||||
ResourceBundle bundle = null;
|
||||
if (ourBundle != null) bundle = ourBundle.get();
|
||||
if (bundle == null) {
|
||||
bundle = ResourceBundle.getBundle(BUNDLE);
|
||||
ourBundle = new SoftReference<ResourceBundle>(bundle);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,10 @@ public class CoreJavaFileManager implements JavaFileManager {
|
||||
if (!(psiFile instanceof PsiJavaFile)) {
|
||||
throw new UnsupportedOperationException("no java file for .class");
|
||||
}
|
||||
throw new UnsupportedOperationException("TODO");
|
||||
final PsiClass[] classes = ((PsiJavaFile)psiFile).getClasses();
|
||||
if (classes.length == 1) {
|
||||
return classes[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package com.intellij.core;
|
||||
|
||||
import com.intellij.ide.highlighter.JavaClassFileType;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiElementFinder;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.JavaPsiFacadeImpl;
|
||||
|
||||
import java.io.File;
|
||||
@@ -30,6 +31,10 @@ public class JavaCoreEnvironment extends CoreEnvironment {
|
||||
|
||||
public JavaCoreEnvironment(Disposable parentDisposable) {
|
||||
super(parentDisposable);
|
||||
|
||||
registerFileType(JavaClassFileType.INSTANCE, "class");
|
||||
addExplicitExtension(FileTypeFileViewProviders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileViewProviderFactory());
|
||||
|
||||
registerProjectExtensionPoint(PsiElementFinder.EP_NAME, PsiElementFinder.class);
|
||||
myFileManager = new CoreJavaFileManager(myPsiManager, myJarFileSystem);
|
||||
JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(myProject, myPsiManager, myFileManager, null);
|
||||
@@ -41,5 +46,9 @@ public class JavaCoreEnvironment extends CoreEnvironment {
|
||||
|
||||
public void addToClasspath(File path) {
|
||||
myFileManager.addToClasspath(path);
|
||||
final VirtualFile root = myJarFileSystem.findFileByPath(path + "!/");
|
||||
if (root != null) {
|
||||
myFileIndexFacade.addLibraryRoot(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.compiled;
|
||||
|
||||
import com.intellij.core.JavaCoreBundle;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
@@ -103,7 +104,7 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil
|
||||
throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE);
|
||||
}
|
||||
|
||||
protected static final String CAN_NOT_MODIFY_MESSAGE = PsiBundle.message("psi.error.attempt.to.edit.class.file");
|
||||
protected static final String CAN_NOT_MODIFY_MESSAGE = JavaCoreBundle.message("psi.error.attempt.to.edit.class.file");
|
||||
|
||||
public abstract void appendMirrorText(final int indentLevel, final StringBuilder buffer);
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
psi.error.attempt.to.edit.class.file=Cannot modify compiled element
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.CommonBundle;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.PropertyKey;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class CoreBundle {
|
||||
private static Reference<ResourceBundle> ourBundle;
|
||||
|
||||
@NonNls private static final String BUNDLE = "messages.CoreBundle";
|
||||
|
||||
private CoreBundle() {
|
||||
}
|
||||
|
||||
public static String message(@PropertyKey(resourceBundle = BUNDLE)String key, Object... params) {
|
||||
return CommonBundle.message(getBundle(), key, params);
|
||||
}
|
||||
|
||||
private static ResourceBundle getBundle() {
|
||||
ResourceBundle bundle = null;
|
||||
if (ourBundle != null) bundle = ourBundle.get();
|
||||
if (bundle == null) {
|
||||
bundle = ResourceBundle.getBundle(BUNDLE);
|
||||
ourBundle = new SoftReference<ResourceBundle>(bundle);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
}
|
||||
@@ -30,11 +30,14 @@ import com.intellij.openapi.extensions.ExtensionsArea;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileTypes.ContentBasedFileSubstitutor;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.FileTypeExtension;
|
||||
import com.intellij.openapi.fileTypes.FileTypeRegistry;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.FileIndexFacade;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Getter;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingRegistry;
|
||||
import com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem;
|
||||
import com.intellij.openapi.vfs.local.CoreLocalFileSystem;
|
||||
@@ -64,7 +67,7 @@ public class CoreEnvironment {
|
||||
protected MockProject myProject;
|
||||
private CoreLocalFileSystem myLocalFileSystem;
|
||||
protected final CoreJarFileSystem myJarFileSystem;
|
||||
private MockFileIndexFacade myFileIndexFacade;
|
||||
protected final MockFileIndexFacade myFileIndexFacade;
|
||||
protected final PsiManagerImpl myPsiManager;
|
||||
|
||||
public CoreEnvironment(Disposable parentDisposable) {
|
||||
@@ -115,6 +118,7 @@ public class CoreEnvironment {
|
||||
final MutablePicoContainer projectContainer = myProject.getPicoContainer();
|
||||
|
||||
myProject.registerService(PsiModificationTracker.class, new PsiModificationTrackerImpl(myProject));
|
||||
myProject.registerService(FileIndexFacade.class, myFileIndexFacade);
|
||||
|
||||
registerProjectExtensionPoint(PsiTreeChangePreprocessor.EP_NAME, PsiTreeChangePreprocessor.class);
|
||||
myPsiManager = new PsiManagerImpl(myProject, null, null, myFileIndexFacade, null);
|
||||
@@ -155,6 +159,16 @@ public class CoreEnvironment {
|
||||
});
|
||||
}
|
||||
|
||||
protected <T> void addExplicitExtension(final FileTypeExtension<T> instance, final FileType fileType, final T object) {
|
||||
instance.addExplicitExtension(fileType, object);
|
||||
Disposer.register(myProject, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
instance.removeExplicitExtension(fileType, object);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected <T> void registerExtensionPoint(final ExtensionsArea area, final ExtensionPointName<T> extensionPointName,
|
||||
final Class<? extends T> aClass) {
|
||||
final String name = extensionPointName.getName();
|
||||
@@ -172,4 +186,8 @@ public class CoreEnvironment {
|
||||
public CoreLocalFileSystem getLocalFileSystem() {
|
||||
return myLocalFileSystem;
|
||||
}
|
||||
|
||||
public void addLibraryRoot(VirtualFile file) {
|
||||
myFileIndexFacade.addLibraryRoot(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,15 @@ import com.intellij.openapi.roots.FileIndexFacade;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class MockFileIndexFacade extends FileIndexFacade {
|
||||
private final Module myModule;
|
||||
private final List<VirtualFile> myLibraryRoots = new ArrayList<VirtualFile>();
|
||||
|
||||
public MockFileIndexFacade(final Project project) {
|
||||
super(project);
|
||||
@@ -49,6 +53,11 @@ public class MockFileIndexFacade extends FileIndexFacade {
|
||||
|
||||
@Override
|
||||
public boolean isInLibraryClasses(VirtualFile file) {
|
||||
for (VirtualFile libraryRoot : myLibraryRoots) {
|
||||
if (VfsUtilCore.isAncestor(libraryRoot, file, false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -71,4 +80,8 @@ public class MockFileIndexFacade extends FileIndexFacade {
|
||||
public boolean isValidAncestor(VirtualFile baseDir, VirtualFile child) {
|
||||
return VfsUtilCore.isAncestor(baseDir, child, false);
|
||||
}
|
||||
|
||||
public void addLibraryRoot(VirtualFile file) {
|
||||
myLibraryRoots.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
psi.scanning.files.progress=Scanning files...
|
||||
psi.scanning.files.in.folder.progress=Scanning files in {0}...
|
||||
psi.error.attempt.to.edit.class.file=Cannot modify compiled element
|
||||
psi.decompiled.text.header=\
|
||||
// IntelliJ API Decompiler stub source generated from a class file\n\
|
||||
// Implementation of methods is not available
|
||||
|
||||
Reference in New Issue
Block a user