mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge commit 'origin/master'
This commit is contained in:
@@ -137,6 +137,7 @@
|
||||
<projectService serviceInterface="org.jetbrains.android.compiler.AndroidDexCompilerConfiguration"
|
||||
serviceImplementation="org.jetbrains.android.compiler.AndroidDexCompilerConfiguration"/>
|
||||
<compilerSettingsFactory implementation="org.jetbrains.android.compiler.AndroidDexCompilerSettingsFactory"/>
|
||||
<problemFileHighlightFilter implementation="org.jetbrains.android.AndroidProblemFileHighlightingFilter"/>
|
||||
</extensions>
|
||||
|
||||
<extensionPoints>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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 org.jetbrains.android;
|
||||
|
||||
import com.android.sdklib.SdkConstants;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.resourceManagers.ResourceManager;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public class AndroidProblemFileHighlightingFilter implements Condition<VirtualFile> {
|
||||
private final Project myProject;
|
||||
|
||||
public AndroidProblemFileHighlightingFilter(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean value(VirtualFile file) {
|
||||
if (file.getFileType() != StdFileTypes.XML) {
|
||||
return false;
|
||||
}
|
||||
if (SdkConstants.FN_ANDROID_MANIFEST_XML.equals(file.getName())) {
|
||||
Module module = ModuleUtil.findModuleForFile(file, myProject);
|
||||
return module != null && AndroidFacet.getInstance(module) != null;
|
||||
}
|
||||
|
||||
VirtualFile parent = file.getParent();
|
||||
if (parent == null) return false;
|
||||
parent = parent.getParent();
|
||||
if (parent == null) return false;
|
||||
return ResourceManager.isResourceDirectory(parent, myProject);
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,8 @@ public class AndroidAptCompiler implements SourceGeneratingCompiler {
|
||||
return;
|
||||
}
|
||||
String className = FileUtil.getNameWithoutExtension(aptItem.myGeneratedFile);
|
||||
AndroidCompileUtil.removeDuplicatingClasses(aptItem.myModule, aptItem.myPackage, className, aptItem.myGeneratedFile);
|
||||
AndroidCompileUtil.removeDuplicatingClasses(aptItem.myModule, aptItem.myPackage, className, aptItem.myGeneratedFile,
|
||||
aptItem.mySourceRootPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ import com.intellij.openapi.compiler.GeneratingCompiler;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
@@ -187,16 +185,24 @@ public class AndroidCompileUtil {
|
||||
// must be invoked in a read action!
|
||||
|
||||
public static void removeDuplicatingClasses(final Module module, @NotNull final String packageName, @NotNull String className,
|
||||
@Nullable final File classFile) {
|
||||
@Nullable final File classFile, String sourceRootPath) {
|
||||
if (sourceRootPath == null) {
|
||||
return;
|
||||
}
|
||||
VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByPath(sourceRootPath);
|
||||
if (sourceRoot == null) {
|
||||
return;
|
||||
}
|
||||
final Project project = module.getProject();
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
|
||||
final String interfaceQualifiedName = packageName + '.' + className;
|
||||
PsiClass[] classes = facade.findClasses(interfaceQualifiedName, GlobalSearchScope.moduleScope(module));
|
||||
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
for (PsiClass c : classes) {
|
||||
PsiFile psiFile = c.getContainingFile();
|
||||
if (className.equals(FileUtil.getNameWithoutExtension(psiFile.getName()))) {
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
if (virtualFile != null) {
|
||||
if (virtualFile != null && projectFileIndex.getSourceRootForFile(virtualFile) == sourceRoot) {
|
||||
final String path = virtualFile.getPath();
|
||||
File f = new File(path);
|
||||
if (!f.equals(classFile) && f.exists()) {
|
||||
|
||||
@@ -114,6 +114,7 @@ public class AndroidIdlCompiler implements SourceGeneratingCompiler {
|
||||
final IAndroidTarget myAndroidTarget;
|
||||
final File myGeneratedFile;
|
||||
final String myPackageName;
|
||||
final String mySourceRootPath;
|
||||
|
||||
public IdlGenerationItem(@NotNull Module module,
|
||||
@NotNull VirtualFile file,
|
||||
@@ -126,6 +127,7 @@ public class AndroidIdlCompiler implements SourceGeneratingCompiler {
|
||||
myTestSource = testSource;
|
||||
myAndroidTarget = androidTarget;
|
||||
myPackageName = packageName;
|
||||
mySourceRootPath = sourceRootPath;
|
||||
myGeneratedFile =
|
||||
new File(sourceRootPath, packageName.replace('.', File.separatorChar) + File.separator + file.getNameWithoutExtension() + ".java");
|
||||
}
|
||||
@@ -222,7 +224,9 @@ public class AndroidIdlCompiler implements SourceGeneratingCompiler {
|
||||
public void run() {
|
||||
if (idlItem.myModule.getProject().isDisposed()) return;
|
||||
String className = FileUtil.getNameWithoutExtension(idlItem.myGeneratedFile);
|
||||
AndroidCompileUtil.removeDuplicatingClasses(idlItem.myModule, idlItem.myPackageName, className, idlItem.myGeneratedFile);
|
||||
AndroidCompileUtil.removeDuplicatingClasses(idlItem.myModule, idlItem.myPackageName, className,
|
||||
idlItem.myGeneratedFile.exists() ? idlItem.myGeneratedFile : null,
|
||||
idlItem.mySourceRootPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+4
-1
@@ -106,7 +106,8 @@ public class AndroidMavenResourcesCompiler implements SourceGeneratingCompiler {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
String className = FileUtil.getNameWithoutExtension(genItem.myGeneratedFile);
|
||||
AndroidCompileUtil.removeDuplicatingClasses(genItem.myModule, genItem.myPackage, className, genItem.myGeneratedFile);
|
||||
AndroidCompileUtil.removeDuplicatingClasses(genItem.myModule, genItem.myPackage, className, genItem.myGeneratedFile,
|
||||
genItem.mySourceRootPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -132,12 +133,14 @@ public class AndroidMavenResourcesCompiler implements SourceGeneratingCompiler {
|
||||
final Module myModule;
|
||||
final String myPackage;
|
||||
final File myGeneratedFile;
|
||||
final String mySourceRootPath;
|
||||
|
||||
private MyGenerationItem(@NotNull Module module, @NotNull String aPackage, @NotNull String sourceRootPath) {
|
||||
myModule = module;
|
||||
myPackage = aPackage;
|
||||
myGeneratedFile =
|
||||
new File(sourceRootPath, aPackage.replace('.', File.separatorChar) + File.separator + AndroidUtils.R_JAVA_FILENAME);
|
||||
mySourceRootPath = sourceRootPath;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -142,7 +142,8 @@ class AndroidResourceFilesListener extends VirtualFileAdapter {
|
||||
Manifest manifest = myFacet.getManifest();
|
||||
String aPackage = manifest != null ? manifest.getPackage().getValue() : null;
|
||||
if (myCachedPackage != null && !myCachedPackage.equals(aPackage)) {
|
||||
AndroidCompileUtil.removeDuplicatingClasses(myModule, myCachedPackage, AndroidUtils.R_CLASS_NAME, null);
|
||||
String aptGenDirPath = myFacet.getAptGenSourceRootPath();
|
||||
AndroidCompileUtil.removeDuplicatingClasses(myModule, myCachedPackage, AndroidUtils.R_CLASS_NAME, null, aptGenDirPath);
|
||||
}
|
||||
myCachedPackage = aPackage;
|
||||
myFacet.getLocalResourceManager().invalidateAttributeDefinitions();
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -332,13 +333,21 @@ public abstract class ResourceManager {
|
||||
return dir != null && isResourceDirectory(dir);
|
||||
}
|
||||
|
||||
public static boolean isResourceDirectory(VirtualFile dir, Project project) {
|
||||
Module module = ModuleUtil.findModuleForFile(dir, project);
|
||||
if (module != null) {
|
||||
AndroidFacet facet = AndroidFacet.getInstance(module);
|
||||
return facet != null && facet.getLocalResourceManager().isResourceDir(dir);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isResourceDirectory(PsiDirectory dir) {
|
||||
// check facet settings
|
||||
VirtualFile vf = dir.getVirtualFile();
|
||||
Module module = ModuleUtil.findModuleForPsiElement(dir);
|
||||
if (module != null) {
|
||||
AndroidFacet facet = AndroidFacet.getInstance(module);
|
||||
return facet != null && facet.getLocalResourceManager().isResourceDir(vf);
|
||||
|
||||
if (isResourceDirectory(vf, dir.getProject())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// method can be invoked for system resource dir, so we should check it
|
||||
|
||||
Reference in New Issue
Block a user