From 96f0349f641aad9cf0f989f4bace243c4e78d4d6 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 17 Apr 2013 15:55:44 +0400 Subject: [PATCH] [r=Alexander Lobas] IDEA-105480 Regression: 12.1 GUI Designer no longer works with multiple classes in a single file --- .../compiler/FormsBindingManager.java | 84 +++++++++++++------ 1 file changed, 59 insertions(+), 25 deletions(-) diff --git a/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsBindingManager.java b/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsBindingManager.java index 63a1fb4aff85..ab79c6703d2c 100644 --- a/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsBindingManager.java +++ b/plugins/ui-designer/jps-plugin/src/org/jetbrains/jps/uiDesigner/compiler/FormsBindingManager.java @@ -20,6 +20,7 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import gnu.trove.THashMap; +import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.ModuleChunk; @@ -39,6 +40,7 @@ import org.jetbrains.jps.uiDesigner.model.JpsUiDesignerConfiguration; import org.jetbrains.jps.uiDesigner.model.JpsUiDesignerExtensionService; import java.io.File; +import java.io.FilenameFilter; import java.io.IOException; import java.util.*; @@ -132,12 +134,14 @@ public class FormsBindingManager extends FormsBuilder { for (final Map.Entry entry : formsToCompile.entrySet()) { final File form = entry.getKey(); final ModuleBuildTarget target = entry.getValue(); - final File boundSource = findBoundSource(context, target, form); - if (boundSource != null && !excludes.isExcluded(boundSource)) { - addBinding(boundSource, form, srcToForms); - FSOperations.markDirty(context, boundSource); - filesToCompile.put(boundSource, target); - exitCode = ExitCode.OK; + final Collection sources = findBoundSourceCandidates(context, target, form); + for (File boundSource : sources) { + if (!excludes.isExcluded(boundSource)) { + addBinding(boundSource, form, srcToForms); + FSOperations.markDirty(context, boundSource); + filesToCompile.put(boundSource, target); + exitCode = ExitCode.OK; + } } } @@ -185,23 +189,28 @@ public class FormsBindingManager extends FormsBuilder { return exitCode; } - @Nullable - private static File findBoundSource(CompileContext context, final ModuleBuildTarget target, File form) throws IOException { + @NotNull + private static Collection findBoundSourceCandidates(CompileContext context, final ModuleBuildTarget target, File form) throws IOException { final List targetRoots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context); if (targetRoots.isEmpty()) { - return null; + return Collections.emptyList(); } final String className = FormsParsing.readBoundClassName(form); if (className == null) { - return null; + return Collections.emptyList(); } for (JavaSourceRootDescriptor rd : targetRoots) { final File boundSource = findSourceForClass(rd, className); if (boundSource != null) { - return boundSource; + return Collections.singleton(boundSource); } } - return null; + + final Set candidates = new THashSet(FileUtil.FILE_HASHING_STRATEGY); + for (JavaSourceRootDescriptor rd : targetRoots) { + candidates.addAll(findPossibleSourcesForClass(rd, className)); + } + return candidates; } @Nullable @@ -209,19 +218,7 @@ public class FormsBindingManager extends FormsBuilder { if (boundClassName == null) { return null; } - - String clsName = boundClassName; - String prefix = rd.getPackagePrefix(); - if (!StringUtil.isEmpty(prefix)) { - if (!StringUtil.endsWith(prefix, ".")) { - prefix += "."; - } - if (SystemInfo.isFileSystemCaseSensitive? StringUtil.startsWith(clsName, prefix) : StringUtil.startsWithIgnoreCase(clsName, prefix)) { - clsName = clsName.substring(prefix.length()); - } - } - - String relPath = clsName.replace('.', '/') + JAVA_EXTENSION; + String relPath = suggestRelativePath(rd, boundClassName); while (true) { final File candidate = new File(rd.getRootFile(), relPath); if (candidate.exists()) { @@ -235,4 +232,41 @@ public class FormsBindingManager extends FormsBuilder { } } + @Nullable + private static Collection findPossibleSourcesForClass(JavaSourceRootDescriptor rd, final @Nullable String boundClassName) throws IOException { + if (boundClassName == null) { + return Collections.emptyList(); + } + String relPath = suggestRelativePath(rd, boundClassName); + final File containingDirectory = new File(rd.getRootFile(), relPath).getParentFile(); + if (containingDirectory == null) { + return Collections.emptyList(); + } + final File[] files = containingDirectory.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.endsWith(JAVA_EXTENSION); + } + }); + if (files == null || files.length == 0) { + return Collections.emptyList(); + } + return Arrays.asList(files); + } + + @NotNull + private static String suggestRelativePath(@NotNull JavaSourceRootDescriptor rd, @NotNull String className) { + String clsName = className; + String prefix = rd.getPackagePrefix(); + if (!StringUtil.isEmpty(prefix)) { + if (!StringUtil.endsWith(prefix, ".")) { + prefix += "."; + } + if (SystemInfo.isFileSystemCaseSensitive? StringUtil.startsWith(clsName, prefix) : StringUtil.startsWithIgnoreCase(clsName, prefix)) { + clsName = clsName.substring(prefix.length()); + } + } + + return clsName.replace('.', '/') + JAVA_EXTENSION; + } }