diff --git a/java/execution/impl/src/com/intellij/execution/application/ApplicationConfiguration.java b/java/execution/impl/src/com/intellij/execution/application/ApplicationConfiguration.java index a7c0218b8a6d..4b228138a5d4 100644 --- a/java/execution/impl/src/com/intellij/execution/application/ApplicationConfiguration.java +++ b/java/execution/impl/src/com/intellij/execution/application/ApplicationConfiguration.java @@ -30,19 +30,14 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.options.SettingsEditorGroup; import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.OrderEnumerator; -import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.util.DefaultJDOMExternalizer; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiJavaModule; -import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.util.PsiMethodUtil; import com.intellij.refactoring.listeners.RefactoringElementListener; -import com.intellij.util.PathsList; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,7 +45,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; -import java.util.stream.Stream; public class ApplicationConfiguration extends ModuleBasedConfiguration implements CommonJavaRunConfigurationParameters, SingleClassConfiguration, RefactoringListenerProvider { @@ -292,34 +286,9 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration classRoots(f, index)) - .forEach(f -> { - modulePath.add(f); - classPath.remove(f); - }); + params.getModulePath().addAll(params.getClassPath().getPathList()); } } } - - private static Stream classRoots(VirtualFile file, ProjectFileIndex index) { - if (index.isInSourceContent(file)) { - Module module = index.getModuleForFile(file); - if (module != null) { - return Stream.of(OrderEnumerator.orderEntries(module).runtimeOnly().withoutSdk().withoutLibraries().withoutDepModules().getClassesRoots()); - } - } - else { - VirtualFile root = index.getClassRootForFile(file); - if (root != null) { - return Stream.of(root); - } - } - return Stream.empty(); - } } } \ No newline at end of file diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java b/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java index f1dcd32a378a..1c36843570e1 100644 --- a/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java +++ b/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java @@ -25,6 +25,7 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.*; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.encoding.EncodingProjectManager; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.util.PathsList; import com.intellij.util.text.VersionComparatorUtil; import org.intellij.lang.annotations.MagicConstant; @@ -32,6 +33,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.nio.charset.Charset; +import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Set; @@ -85,7 +87,8 @@ public class JavaParameters extends SimpleJavaParameters { if (!pathsList.getPathList().isEmpty()) { ParametersList vmParameters = getVMParametersList(); if (vmParameters.hasProperty(JAVA_LIBRARY_PATH_PROPERTY)) { - LOG.info(JAVA_LIBRARY_PATH_PROPERTY + " property is already specified, native library paths from dependencies (" + pathsList.getPathsString() + ") won't be added"); + LOG.info(JAVA_LIBRARY_PATH_PROPERTY + " property is already specified, " + + "native library paths from dependencies (" + pathsList.getPathsString() + ") won't be added"); } else { vmParameters.addProperty(JAVA_LIBRARY_PATH_PROPERTY, pathsList.getPathsString()); @@ -154,7 +157,9 @@ public class JavaParameters extends SimpleJavaParameters { return result; } - public void configureByProject(final Project project, @MagicConstant(valuesFromClass = JavaParameters.class) final int classPathType, final Sdk jdk) throws CantRunException { + public void configureByProject(Project project, + @MagicConstant(valuesFromClass = JavaParameters.class) int classPathType, + Sdk jdk) throws CantRunException { if ((classPathType & JDK_ONLY) != 0) { if (jdk == null) { throw CantRunException.noJdkConfigured(); @@ -170,7 +175,7 @@ public class JavaParameters extends SimpleJavaParameters { configureJavaLibraryPath(OrderEnumerator.orderEntries(project)); } - private static OrderRootsEnumerator configureEnumerator(OrderEnumerator enumerator, @MagicConstant(valuesFromClass = JavaParameters.class) int classPathType, Sdk jdk) { + private static OrderRootsEnumerator configureEnumerator(OrderEnumerator enumerator, int classPathType, Sdk jdk) { if ((classPathType & JDK_ONLY) == 0) { enumerator = enumerator.withoutSdk(); } @@ -180,8 +185,14 @@ public class JavaParameters extends SimpleJavaParameters { OrderRootsEnumerator rootsEnumerator = enumerator.classes(); if ((classPathType & JDK_ONLY) != 0) { rootsEnumerator = rootsEnumerator.usingCustomRootProvider( - e -> e instanceof JdkOrderEntry ? jdk.getRootProvider().getFiles(OrderRootType.CLASSES) : e.getFiles(OrderRootType.CLASSES)); + e -> e instanceof JdkOrderEntry ? jdkRoots(jdk) : e.getFiles(OrderRootType.CLASSES)); } return rootsEnumerator; } + + private static VirtualFile[] jdkRoots(Sdk jdk) { + return Arrays.stream(jdk.getRootProvider().getFiles(OrderRootType.CLASSES)) + .filter(f -> !JrtFileSystem.isModuleRoot(f)) + .toArray(VirtualFile[]::new); + } } \ No newline at end of file diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java index e4422331e055..8c40cb4c9c5a 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java @@ -23,7 +23,7 @@ import com.intellij.openapi.projectRoots.ui.SdkPathEditor; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.ui.OrderRootTypeUIFactory; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.impl.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.ui.components.JBList; import javax.swing.*; diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaModuleGraphUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaModuleGraphUtil.java index 65bec99cd7ff..c8ad3f474c68 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaModuleGraphUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaModuleGraphUtil.java @@ -63,14 +63,10 @@ public class JavaModuleGraphUtil { } public static boolean reads(@NotNull PsiJavaModule source, @NotNull PsiJavaModule destination) { - return getRequiresGraph(source).reads(source, destination); - } - - @NotNull - public static Collection moduleDependencies(@NotNull PsiJavaModule start) { - Set result = ContainerUtil.newHashSet(); - visit(getRequiresGraph(start), start, result); - return result; + Project project = source.getProject(); + RequiresGraph graph = CachedValuesManager.getManager(project).getCachedValue(project, () -> + Result.create(buildRequiresGraph(project), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)); + return graph.reads(source, destination); } // Looks for cycles between Java modules in the project sources. @@ -121,12 +117,6 @@ public class JavaModuleGraphUtil { return map; } - private static RequiresGraph getRequiresGraph(@NotNull PsiJavaModule source) { - Project project = source.getProject(); - return CachedValuesManager.getManager(project).getCachedValue(project, () -> - Result.create(buildRequiresGraph(project), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)); - } - // Starting from source modules, collects all module dependencies in the project. // The resulting graph is used for tracing readability. private static RequiresGraph buildRequiresGraph(Project project) { @@ -158,12 +148,6 @@ public class JavaModuleGraphUtil { } } - private static void visit(RequiresGraph graph, PsiJavaModule module, Set result) { - if (result.add(module)) { - graph.dependencies(module).forEach(dependency -> visit(graph, dependency, result)); - } - } - private static class RequiresGraph { private final Graph myGraph; private final Set myPublicEdges; @@ -187,10 +171,6 @@ public class JavaModuleGraphUtil { return false; } - public Iterable dependencies(PsiJavaModule node) { - return myGraph.getNodes().contains(node) ? () -> myGraph.getIn(node) : Collections.emptyList(); - } - public static String key(PsiJavaModule module, PsiJavaModule exporter) { return module.getModuleName() + '/' + exporter.getModuleName(); } diff --git a/java/java-impl/src/com/intellij/ide/navigationToolbar/JavaNavBarExtension.java b/java/java-impl/src/com/intellij/ide/navigationToolbar/JavaNavBarExtension.java index 2a4a555ad051..a5d3f04f7fb3 100644 --- a/java/java-impl/src/com/intellij/ide/navigationToolbar/JavaNavBarExtension.java +++ b/java/java-impl/src/com/intellij/ide/navigationToolbar/JavaNavBarExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -20,7 +20,7 @@ import com.intellij.lang.LangBundle; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.vfs.impl.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.presentation.java.ClassPresentationUtil; diff --git a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java index b04ea71d9d6f..495e30da6429 100644 --- a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java +++ b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java @@ -36,7 +36,7 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; -import com.intellij.openapi.vfs.impl.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; @@ -161,7 +161,6 @@ public class JavaSdkImpl extends JavaSdk { } @Override - @SuppressWarnings("HardCodedStringLiteral") public String getBinPath(@NotNull Sdk sdk) { return getConvertedHomePath(sdk) + "bin"; } @@ -372,7 +371,6 @@ public class JavaSdkImpl extends JavaSdk { } @Override - @SuppressWarnings("HardCodedStringLiteral") public void setupSdkPaths(@NotNull Sdk sdk) { String homePath = sdk.getHomePath(); assert homePath != null : sdk; @@ -488,11 +486,6 @@ public class JavaSdkImpl extends JavaSdk { return versionString; } - @Override - public int compareTo(@NotNull String versionString, @NotNull String versionNumber) { - return getVersionNumber(versionString).compareTo(versionNumber); - } - @Override public JavaSdkVersion getVersion(@NotNull Sdk sdk) { String version = sdk.getVersionString(); @@ -665,12 +658,10 @@ public class JavaSdkImpl extends JavaSdk { List result = ContainerUtil.newArrayList(); VirtualFileManager fileManager = VirtualFileManager.getInstance(); - String path = file.getPath(); - if (JrtFileSystem.isModularJdk(path)) { - String url = VirtualFileManager.constructUrl(JrtFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(path) + JrtFileSystem.SEPARATOR); - for (String module : JrtFileSystem.listModules(path)) { - ContainerUtil.addIfNotNull(result, fileManager.findFileByUrl(url + module)); - } + VirtualFile jrt = fileManager.findFileByUrl( + VirtualFileManager.constructUrl(JrtFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(file.getPath()) + JrtFileSystem.SEPARATOR)); + if (jrt != null) { + ContainerUtil.addAll(result, jrt.getChildren()); } for (File root : JavaSdkUtil.getJdkClassesRoots(file, isJre)) { @@ -678,7 +669,7 @@ public class JavaSdkImpl extends JavaSdk { ContainerUtil.addIfNotNull(result, fileManager.findFileByUrl(url)); } - Collections.sort(result, (o1, o2) -> o1.getPath().compareTo(o2.getPath())); + Collections.sort(result, Comparator.comparing(VirtualFile::getPath)); return result; } @@ -691,13 +682,11 @@ public class JavaSdkImpl extends JavaSdk { } @Nullable - @SuppressWarnings("HardCodedStringLiteral") private static VirtualFile findSources(File file) { return findSources(file, "src"); } @Nullable - @SuppressWarnings("HardCodedStringLiteral") private static VirtualFile findSources(File file, final String srcName) { File jarFile = new File(file, srcName + ".jar"); if (!jarFile.exists()) { @@ -719,7 +708,6 @@ public class JavaSdkImpl extends JavaSdk { } } - @SuppressWarnings("HardCodedStringLiteral") private static void addDocs(File file, SdkModificator rootContainer) { VirtualFile vFile = findDocs(file, "docs/api"); if (vFile != null) { diff --git a/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystem.java b/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystemImpl.java similarity index 74% rename from java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystem.java rename to java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystemImpl.java index d9f9c10f9a17..100e4ccb0649 100644 --- a/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystem.java +++ b/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystemImpl.java @@ -23,18 +23,22 @@ import com.intellij.notification.Notifications; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.projectRoots.ProjectJdkTable; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.OrderRootType; -import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.*; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.impl.ArchiveHandler; -import com.intellij.openapi.vfs.newvfs.*; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.newvfs.BulkFileListener; +import com.intellij.openapi.vfs.newvfs.NewVirtualFile; +import com.intellij.openapi.vfs.newvfs.RefreshQueue; +import com.intellij.openapi.vfs.newvfs.VfsImplUtil; import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.util.containers.ContainerUtil; @@ -42,36 +46,19 @@ import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.file.*; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; import java.util.stream.Stream; import static com.intellij.util.containers.ContainerUtil.newTroveMap; -public class JrtFileSystem extends ArchiveFileSystem { - public static final String PROTOCOL = StandardFileSystems.JRT_PROTOCOL; - public static final String PROTOCOL_PREFIX = StandardFileSystems.JRT_PROTOCOL_PREFIX; - public static final String SEPARATOR = JarFileSystem.JAR_SEPARATOR; - - private static final boolean SUPPORTED = - SystemInfo.isJavaVersionAtLeast("9") || SystemInfo.isJavaVersionAtLeast("1.8") && !SystemInfo.isJavaVersionAtLeast("1.9"); - - private static final URI ROOT_URI = URI.create("jrt:/"); - +public class JrtFileSystemImpl extends JrtFileSystem { private final Map myHandlers = newTroveMap(FileUtil.PATH_HASHING_STRATEGY); private final AtomicBoolean mySubscribed = new AtomicBoolean(false); - public JrtFileSystem() { + public JrtFileSystemImpl() { scheduleConfiguredSdkCheck(); } @@ -213,51 +200,4 @@ public class JrtFileSystem extends ArchiveFileSystem { protected boolean isCorrectFileType(@NotNull VirtualFile local) { return isModularJdk(FileUtil.toSystemDependentName(local.getPath())); } - - public static boolean isSupported() { - return SUPPORTED; - } - - public static boolean isModularJdk(@NotNull String homePath) { - return new File(homePath, "lib/modules").exists() && new File(homePath, "jrt-fs.jar").isFile(); - } - - public static boolean isRoot(@NotNull VirtualFile file) { - return file.getParent() == null && file.getFileSystem() instanceof JrtFileSystem; - } - - public static boolean isModuleRoot(@NotNull VirtualFile file) { - VirtualFile parent = file.getParent(); - return parent != null && isRoot(parent); - } - - @NotNull - public static List listModules(@NotNull String path) { - try { - Path root = getFileSystem(path).getPath("/modules"); - return Files.list(root).map(p -> p.getFileName().toString()).collect(Collectors.toList()); - } - catch (IOException | InvalidPathException e) { - Logger.getInstance(JrtFileSystem.class).warn(path, e); - return Collections.emptyList(); - } - } - - static FileSystem getFileSystem(String path) throws IOException { - try { - if (SystemInfo.isJavaVersionAtLeast("9")) { - return FileSystems.newFileSystem(ROOT_URI, Collections.singletonMap("java.home", path)); - } - else { - File file = new File(path, "jrt-fs.jar"); - if (!file.exists()) throw new IOException("Missing provider: " + file); - URL url = file.toURI().toURL(); - ClassLoader loader = new URLClassLoader(new URL[]{url}, null); - return FileSystems.newFileSystem(ROOT_URI, Collections.emptyMap(), loader); - } - } - catch (Error e) { - throw new IOException("Error mounting JRT filesystem at " + path, e); - } - } } \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtHandler.java b/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtHandler.java index 8e327d6e29cc..b42c549f9e73 100644 --- a/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtHandler.java +++ b/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtHandler.java @@ -15,20 +15,27 @@ */ package com.intellij.openapi.vfs.impl.jrt; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.impl.ArchiveHandler; import com.intellij.reference.SoftReference; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.URI; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; import java.util.Map; class JrtHandler extends ArchiveHandler { + private static final URI ROOT_URI = URI.create("jrt:/"); + private SoftReference myFileSystem; public JrtHandler(@NotNull String path) { @@ -38,8 +45,23 @@ class JrtHandler extends ArchiveHandler { private synchronized FileSystem getFileSystem() throws IOException { FileSystem fs = SoftReference.dereference(myFileSystem); if (fs == null) { - fs = JrtFileSystem.getFileSystem(getFile().getPath()); - myFileSystem = new SoftReference<>(fs); + String path = getFile().getPath(); + try { + if (SystemInfo.isJavaVersionAtLeast("9")) { + fs = FileSystems.newFileSystem(ROOT_URI, Collections.singletonMap("java.home", path)); + } + else { + File file = new File(path, "jrt-fs.jar"); + if (!file.exists()) throw new IOException("Missing provider: " + file); + URL url = file.toURI().toURL(); + ClassLoader loader = new URLClassLoader(new URL[]{url}, null); + fs = FileSystems.newFileSystem(ROOT_URI, Collections.emptyMap(), loader); + } + myFileSystem = new SoftReference<>(fs); + } + catch (RuntimeException | Error e) { + throw new IOException("Error mounting JRT filesystem at " + path, e); + } } return fs; } diff --git a/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java b/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java index 784da4e17cdd..f6b3baa8b3a7 100644 --- a/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java +++ b/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java @@ -27,7 +27,7 @@ import com.intellij.openapi.roots.SourceFolder; import com.intellij.openapi.roots.ui.configuration.SourceRootPresentation; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.impl.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.openapi.vfs.newvfs.ArchiveFileSystem; import com.intellij.psi.JavaDirectoryService; import com.intellij.psi.PsiDirectory; diff --git a/java/java-psi-api/src/com/intellij/codeInsight/AnnotationTargetUtil.java b/java/java-psi-api/src/com/intellij/codeInsight/AnnotationTargetUtil.java index 7393be47a8e7..324cb0e657a8 100644 --- a/java/java-psi-api/src/com/intellij/codeInsight/AnnotationTargetUtil.java +++ b/java/java-psi-api/src/com/intellij/codeInsight/AnnotationTargetUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -61,14 +61,14 @@ public class AnnotationTargetUtil { } if (owner instanceof PsiModifierList) { - if (((PsiModifierList)owner).getNextSibling() instanceof PsiErrorElement) { - return TargetType.EMPTY_ARRAY; - } PsiElement element = ((PsiModifierList)owner).getParent(); if (element instanceof PsiPackageStatement) { return PACKAGE_TARGETS; } if (element instanceof PsiClass) { + if (((PsiClass)element).getModifierList() != owner){ + return TargetType.EMPTY_ARRAY; + } if (((PsiClass)element).isAnnotationType()) { return ANNOTATION_TARGETS; } diff --git a/java/java-tests/testSrc/com/intellij/openapi/vfs/JrtFileSystemTest.java b/java/java-tests/testSrc/com/intellij/openapi/vfs/JrtFileSystemTest.java index 73a738088ff5..fca53f14df83 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/vfs/JrtFileSystemTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/vfs/JrtFileSystemTest.java @@ -17,7 +17,7 @@ package com.intellij.openapi.vfs; import com.intellij.JavaTestUtil; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.vfs.impl.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.testFramework.fixtures.BareTestFixtureTestCase; import com.intellij.testFramework.rules.TempDirectory; import org.junit.Before; @@ -64,9 +64,10 @@ public class JrtFileSystemTest extends BareTestFixtureTestCase { } @Test - public void moduleListing() { - String path = myTempDir.getRoot().getPath(); - assertThat(JrtFileSystem.listModules(path)).containsExactlyInAnyOrder("java.base", "test1"); + public void nonRoot() { + String url = VirtualFileManager.constructUrl(JrtFileSystem.PROTOCOL, JavaTestUtil.getJavaTestDataPath() + JrtFileSystem.SEPARATOR); + VirtualFile root = VirtualFileManager.getInstance().findFileByUrl(url); + assertThat(root).isNull(); } @Test diff --git a/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdk.java b/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdk.java index 5bc30f2c229d..5600d50cffd3 100644 --- a/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdk.java +++ b/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdk.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -17,33 +17,27 @@ package com.intellij.openapi.projectRoots; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.projectRoots.impl.SdkVersionUtil; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; public abstract class JavaSdk extends SdkType implements JavaSdkType { - public JavaSdk(@NotNull @NonNls String name) { - super(name); - } - public static JavaSdk getInstance() { return ApplicationManager.getApplication().getComponent(JavaSdk.class); } + public JavaSdk(@NotNull String name) { + super(name); + } + @NotNull public final Sdk createJdk(@NotNull String jdkName, @NotNull String jreHome) { return createJdk(jdkName, jreHome, true); } - /** - * @deprecated use {@link #isOfVersionOrHigher(Sdk, JavaSdkVersion)} instead - */ - public abstract int compareTo(@NotNull String versionString, @NotNull String versionNumber); - @NotNull - public abstract Sdk createJdk(@NonNls String jdkName, @NotNull String home, boolean isJre); + public abstract Sdk createJdk(String jdkName, @NotNull String home, boolean isJre); @Nullable public abstract JavaSdkVersion getVersion(@NotNull Sdk sdk); @@ -65,4 +59,4 @@ public abstract class JavaSdk extends SdkType implements JavaSdkType { public static String getJdkVersion(@NotNull String sdkHome) { return SdkVersionUtil.detectJdkVersion(sdkHome); } -} +} \ No newline at end of file diff --git a/java/openapi/src/com/intellij/openapi/vfs/jrt/JrtFileSystem.java b/java/openapi/src/com/intellij/openapi/vfs/jrt/JrtFileSystem.java new file mode 100644 index 000000000000..0b9a75ff10cc --- /dev/null +++ b/java/openapi/src/com/intellij/openapi/vfs/jrt/JrtFileSystem.java @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2016 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.openapi.vfs.jrt; + +import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.vfs.StandardFileSystems; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.newvfs.ArchiveFileSystem; +import com.intellij.util.io.URLUtil; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public abstract class JrtFileSystem extends ArchiveFileSystem { + public static final String PROTOCOL = StandardFileSystems.JRT_PROTOCOL; + public static final String PROTOCOL_PREFIX = StandardFileSystems.JRT_PROTOCOL_PREFIX; + public static final String SEPARATOR = URLUtil.JAR_SEPARATOR; + + private static final boolean SUPPORTED = + SystemInfo.isJavaVersionAtLeast("9") || SystemInfo.isJavaVersionAtLeast("1.8") && !SystemInfo.isJavaVersionAtLeast("1.9"); + + public static boolean isSupported() { + return SUPPORTED; + } + + public static boolean isModularJdk(@NotNull String homePath) { + return new File(homePath, "lib/modules").exists() && new File(homePath, "jrt-fs.jar").isFile(); + } + + public static boolean isRoot(@NotNull VirtualFile file) { + return file.getParent() == null && file.getFileSystem() instanceof JrtFileSystem; + } + + public static boolean isModuleRoot(@NotNull VirtualFile file) { + VirtualFile parent = file.getParent(); + return parent != null && isRoot(parent); + } +} \ No newline at end of file diff --git a/platform/core-api/src/com/intellij/util/PathsList.java b/platform/core-api/src/com/intellij/util/PathsList.java index af0385de832e..2e5ef730428c 100644 --- a/platform/core-api/src/com/intellij/util/PathsList.java +++ b/platform/core-api/src/com/intellij/util/PathsList.java @@ -81,13 +81,6 @@ public class PathsList { add(LOCAL_PATH.fun(file)); } - public void remove(VirtualFile file) { - String path = LOCAL_PATH.fun(file); - if (path != null) { - remove(path); - } - } - public void addFirst(String path) { int index = 0; for (String element : chooseFirstTimeItems(path)) { diff --git a/platform/projectModel-api/src/com/intellij/openapi/roots/OrderRootType.java b/platform/projectModel-api/src/com/intellij/openapi/roots/OrderRootType.java index af67b753eb2c..6fe05ade2034 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/roots/OrderRootType.java +++ b/platform/projectModel-api/src/com/intellij/openapi/roots/OrderRootType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -17,15 +17,17 @@ package com.intellij.openapi.roots; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; /** * Root types that can be queried from OrderEntry. - * @see OrderEntry + * * @author dsl + * @see OrderEntry */ public class OrderRootType { private final String myName; @@ -35,29 +37,30 @@ public class OrderRootType { protected static PersistentOrderRootType[] ourPersistentOrderRootTypes = new PersistentOrderRootType[0]; - protected OrderRootType(@NonNls String name) { + protected OrderRootType(String name) { myName = name; } /** - * Classpath without output directories for modules. - * Includes: - *
  • classes roots for libraries and jdk - *
  • recursively for module dependencies: only exported items + * Classpath without output directories for modules. Includes: + *
      + *
    • classes roots for libraries and jdk
    • + *
    • recursively for module dependencies: only exported items
    • + *
    */ public static final OrderRootType CLASSES = new PersistentOrderRootType("CLASSES", "classPath", null, "classPathEntry"); /** - * Sources. - * Includes: - *
  • production and test source roots for modules - *
  • source roots for libraries and jdk - *
  • recursively for module dependencies: only exported items + * Sources. Includes: + *
      + *
    • production and test source roots for modules
    • + *
    • source roots for libraries and jdk
    • + *
    • recursively for module dependencies: only exported items
    • + *
    */ public static final OrderRootType SOURCES = new PersistentOrderRootType("SOURCES", "sourcePath", null, "sourcePathEntry"); /** - * Documentation. * Generic documentation order root type */ public static final OrderRootType DOCUMENTATION = new DocumentationRootType(); @@ -67,19 +70,14 @@ public class OrderRootType { * cases if supported by LibraryType. */ public static class DocumentationRootType extends OrderRootType { - public DocumentationRootType() { super("DOCUMENTATION"); } - + @Override public boolean skipWriteIfEmpty() { return true; } - - public String getSdkRootName() { - return "documentation"; - } } public String name() { @@ -117,13 +115,13 @@ public class OrderRootType { protected static T getOrderRootType(final Class orderRootTypeClass) { OrderRootType[] rootTypes = Extensions.getExtensions(EP_NAME); - for(OrderRootType rootType: rootTypes) { + for (OrderRootType rootType : rootTypes) { if (orderRootTypeClass.isInstance(rootType)) { - //noinspection unchecked - return (T)rootType; + @SuppressWarnings("unchecked") T t = (T)rootType; + return t; } } - assert false : "Root type "+orderRootTypeClass+" not found. All roots: "+ Arrays.asList(rootTypes); + assert false : "Root type " + orderRootTypeClass + " not found. All roots: " + Arrays.asList(rootTypes); return null; } @@ -139,4 +137,4 @@ public class OrderRootType { public String toString() { return "Root " + name(); } -} +} \ No newline at end of file diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/SubstitutionHandler.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/SubstitutionHandler.java index 0c4023daef1b..73dad2f2d9d9 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/SubstitutionHandler.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/SubstitutionHandler.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2016 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.structuralsearch.impl.matcher.handlers; import com.intellij.dupLocator.iterators.FilteringNodeIterator; @@ -119,22 +134,26 @@ public class SubstitutionHandler extends MatchingHandler { return false; } - MatchResultImpl result = context.getResult().findSon(name); - + MatchResultImpl result = context.hasResult() ? context.getResult().findSon(name) : null; + if (result == null && context.getPreviousResult() != null) { result = context.getPreviousResult().findSon(name); } - if (result!=null) { + if (result != null) { if (minOccurs == 1 && maxOccurs == 1) { // check if they are the same return validateOneMatch(match, start, end, result,context); - } else if (maxOccurs > 1 && totalMatchedOccurs!=-1) { - final int size = result.getAllSons().size(); - if (matchedOccurs >= size) { - return false; + } else if (maxOccurs > 1 && totalMatchedOccurs != -1) { + if (result.isMultipleMatch()) { + final int size = result.getAllSons().size(); + if (matchedOccurs >= size) { + return false; + } + if (size != 0) { + result = (MatchResultImpl)result.getAllSons().get(matchedOccurs); + } } - result = size == 0 ?result:(MatchResultImpl)result.getAllSons().get(matchedOccurs); // check if they are the same return validateOneMatch(match, start, end, result, context); } @@ -241,7 +260,7 @@ public class SubstitutionHandler extends MatchingHandler { } boolean validate(MatchContext context, Class elementContext) { - MatchResult substitution = context.getResult().findSon(name); + MatchResult substitution = context.hasResult() ? context.getResult().findSon(name) : null; if (minOccurs >= 1 && ( substitution == null || diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java index 752abe82e2b5..32e757e98e1f 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java @@ -30,158 +30,116 @@ import java.util.List; */ @SuppressWarnings({"HardCodedStringLiteral"}) public class StructuralSearchTest extends StructuralSearchTestCase { - private static final String s1 = - "debug(\"In action performed:\"+event);"+ - "project = (Project)event.getDataContext().getData(DataConstants.PROJECT);" + - "CodeEditorManager.getInstance(project).commitAllToPsiFile();" + - "file = (PsiFile) event.getDataContext().getData(\"psi.File\"); " + - "((dialog==null)?" + - " (dialog = new SearchDialog()):" + - " dialog" + - ").show();"; + private static final String s1 = "debug(\"In action performed:\"+event);"+ + "project = (Project)event.getDataContext().getData(DataConstants.PROJECT);" + + "CodeEditorManager.getInstance(project).commitAllToPsiFile();" + + "file = (PsiFile) event.getDataContext().getData(\"psi.File\"); " + + "((dialog==null)?" + + " (dialog = new SearchDialog()):" + + " dialog" + + ").show();"; private static final String s2 = "((dialog==null)? (dialog = new SearchDialog()): dialog).show();"; - private static final String s3 = "dialog = new SearchDialog()"; - private static final String s4 = - " do { " + - " pattern = pattern.getNextSibling(); " + - " } " + - " while (pattern!=null && filterLexicalNodes(pattern));"; + private static final String s4 = " do { " + + " pattern = pattern.getNextSibling(); " + + " } " + + " while (pattern!=null && filterLexicalNodes(pattern));"; - private static final String s5 = - "{ System.out.println();" + - " while(false) { " + - " do { " + - " pattern = pattern.getNextSibling(); " + - " } " + - " while (pattern!=null && filterLexicalNodes(pattern)); " + - " } " + - " do { " + - " pattern = pattern.getNextSibling(); " + - " } while (pattern!=null && filterLexicalNodes(pattern));" + - " { { " + - " do { " + - " pattern = pattern.getNextSibling(); " + - " } while (pattern!=null && filterLexicalNodes(pattern));" + - " } }" + - "}"; + private static final String s5 = "{ System.out.println();" + + " while(false) { " + + " do { " + + " pattern = pattern.getNextSibling(); " + + " } " + + " while (pattern!=null && filterLexicalNodes(pattern)); " + + " } " + + " do { " + + " pattern = pattern.getNextSibling(); " + + " } while (pattern!=null && filterLexicalNodes(pattern));" + + " { { " + + " do { " + + " pattern = pattern.getNextSibling(); " + + " } while (pattern!=null && filterLexicalNodes(pattern));" + + " } }" + + "}"; - private static final String s6 = - " do { " + - " pattern.getNextSibling(); " + - " } " + - " while (pattern!=null && filterLexicalNodes(pattern));"; + private static final String s6 = " do { " + + " pattern.getNextSibling(); " + + " } " + + " while (pattern!=null && filterLexicalNodes(pattern));"; - private static final String s7 = - " if (true) throw new UnsupportedPatternException(statement.toString());" + - " if (true) { " + - " throw new UnsupportedPatternException(statement.toString());" + - " } "; + private static final String s7 = " if (true) throw new UnsupportedPatternException(statement.toString());" + + " if (true) { " + + " throw new UnsupportedPatternException(statement.toString());" + + " } "; - private static final String s8 = - " if (true) { " + - " throw new UnsupportedPatternException(statement.toString());" + - " } "; + private static final String s8 = " if (true) { " + + " throw new UnsupportedPatternException(statement.toString());" + + " } "; private static final String s9 = " if (true) throw new UnsupportedPatternException(statement.toString());"; private static final String s10 = "listener.add(new Runnable() { public void run() {} });"; - private static final String s11 = " new XXX()"; - private static final String s12 = - "new Runnable() {" + - " public void run() {" + - " matchContext.getSink().matchingFinished();" + - " } " + - " }"; + private static final String s12 = "new Runnable() {" + + " public void run() {" + + " matchContext.getSink().matchingFinished();" + + " } " + + " }"; - private static final String s13 = "new Runnable() {}"; private static final String s14_1 = "if (true) { aaa(var); }"; private static final String s14_2 = "if (true) { aaa(var); bbb(var2); }\n if(1==1) { system.out.println('o'); }"; - private static final String s15 = "'T;"; - private static final String s16 = "if('_T) { '_T2; }"; - private static final String s17 = - "token.getText().equals(token2.getText());" + - "token.getText().equals(token2.getText2());" + - "token.a.equals(token2.b);" + - "token.a.equals(token2.a);"; - private static final String s18_1 = "'_T1.'_T2.equals('_T3.'_T2);"; - private static final String s18_2 = "'_T1.'_T2().equals('_T3.'_T2());"; - private static final String s18_3 = "'_T1.'_T2"; + private static final String s17 = "token.getText().equals(token2.getText());" + + "token.getText().equals(token2.getText2());" + + "token.a.equals(token2.b);" + + "token.a.equals(token2.a);"; private static final String s19 = "Aaa a = (Aaa)b; Aaa c = (Bbb)d;"; - private static final String s20 = "'_T1 'T2 = ('_T1)'_T3;"; - private static final String s20_2 = "'_T1 '_T2 = ('_T1)'_T3;"; - private static final String s21_1 = "'_T1:Aa* 'T2 = ('_T1)'_T3;"; - private static final String s21_2 = "'_T1:A* 'T2 = ( '_T1:A+ )'_T3;"; - private static final String s21_3 = "'_T1:Aa* 'T2 = ( '_T1 )'_T3;"; private static final String s22 = "Aaa a = (Aaa)b; Bbb c = (Bbb)d;"; private static final String s23 = "a[i] = 1; b[a[i]] = f(); if (a[i]==1) return b[c[i]];"; - private static final String s24_1 = "'T['_T2:.*i.* ] = '_T3;"; - private static final String s24_2 = "'T['_T2:.*i.* ]"; private static final String s25 = "class MatcherImpl { void doMatch(int a) {} }\n" + "class Matcher { abstract void doMatch(int a);}\n " + "class Matcher2Impl { void doMatch(int a, int b) {} } "; - private static final String s26 = "class 'T:.*Impl { '_T2 '_T3('_T4 '_T5) {\n\n} } "; private static final String s27 = "class A {} interface B {}"; - private static final String s28 = "interface 'T {}"; private static final String s29 = "class A { void B(int C) {} } class D { void E(double e) {} }"; - private static final String s30 = "class '_ { void '_('_:int '_); } "; private static final String s31 = "class A extends B { } class D extends B { } class C extends C {}"; - private static final String s32 = "class '_ extends B { } "; private static final String s33 = "class A implements B,C { } class D implements B,D { } class C2 implements C,B {}"; - private static final String s34 = "class '_ implements B,C { } "; private static final String s35 = "class A { int b; double c; void d() {} int e() {} } " + "class A2 { int b; void d() {} }"; - private static final String s36 = "class '_ { double '_; int '_; int '_() {} void '_() {} } "; private static final String s37 = "class A { void d() throws B,C,D {} } class A2 { void d() throws B,C {} }"; - private static final String s38 = "class 'T { '_ '_() throws D,C {} } "; private static final String s39 = "class A extends B { } class A2 { }"; - private static final String s40 = "class 'T { } "; private static final String s41 = "class A extends B { int a = 1; } class B { int[] c= new int[2]; } " + "class D { double e; } class E { int d; } "; - private static final String s42_1 = "class '_ { '_T '_T2 = '_T3; } "; - private static final String s42_2 = "class '_ { '_T '_T2; } "; private static final String s43 = "interface A extends B { int B = 1; } " + "interface D { public final static double e = 1; } " + "interface E { final static ind d = 2; } " + "interface F { } "; - private static final String s44 = "interface '_ { '_T 'T2 = '_T3; } "; private static final String s45 = "class A extends B { private static final int B = 1; } " + "class C extends D { int B = 1; }" + "class E { }"; - private static final String s46 = "class '_ { final static private '_T 'T2 = '_T3; } "; - private static final String s46_2 = "class '_ { '_T 'T2 = '_T3; } "; - private static final String s47 = "class C { java.lang.String t; } class B { BufferedString t2;} class A { String p;} "; - private static final String s48 = "class '_ { String '_; }"; private static final String s49 = "class C { void a() throws java.lang.RuntimeException {} } class B { BufferedString t2;}"; - private static final String s50 = "class '_ { '_ '_() throws RuntimeException; }"; private static final String s51 = "class C extends B { } class B extends A { } class E {}"; - private static final String s52 = "class '_ extends '_ { }"; private static final String s53 = "class C { " + " String a = System.getProperty(\"abcd\"); " + " static { String s = System.getProperty(a); }" + " static void b() { String s = System.getProperty(a); }" + " }"; - private static final String s54 = "System.getProperty('T)"; private static final String s55 = " a = b.class; "; - private static final String s56 = "'T.class"; private static final String s57 = "/** @author Maxim */ class C {" + " private int value; " + @@ -207,23 +165,10 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "/** @serializable */ private int value2; " + "}" + "class G { /** @param a*/ void a() {} }"; - private static final String s58 = "/** @'T '_T2 */ class '_ { }"; - private static final String s58_2 = "class '_ { /** @serializable '_* */ '_ '_; }"; - private static final String s58_3 = "class '_ { /** @'T 1.4 */ '_ '_() {} }"; - private static final String s58_4 = "/** @'T '_T2 */"; - private static final String s58_5 = "/** @'T '_T2? */"; private static final String s59 = "interface A { void B(); }"; - private static final String s60 = "interface '_ { void '_(); }"; private static final String s61 = "{ a=b; c=d; return; } { e=f; } {}"; - private static final String s62_1 = "{ 'T*; }"; - private static final String s62_2 = "{ 'T+; }"; - private static final String s62_3 = "{ 'T?; }"; - - private static final String s62_4 = "{ '_*; }"; - private static final String s62_5 = "{ '_+; }"; - private static final String s62_6 = "{ '_?; }"; private static final String s63 = " class A { A() {} } class B { public void run() {} }"; private static final String s63_2 = " class A { A() {} " + @@ -231,39 +176,26 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "class D { public void run() {} } " + "} " + "class C {}"; - private static final String s64 = " class 'T { public void '_T2:run () {} }"; - private static final String s64_2 = "class '_ { class 'T { public void '_T2:run () {} } }"; private static final String s65 = " if (A instanceof B) {} else if (B instanceof C) {}"; - private static final String s66 = " '_T instanceof '_T2:B"; private static final String s67 = " buf.append((VirtualFile)a);"; - private static final String s68 = " (VirtualFile)'T"; private static final String s69 = " System.getProperties(); System.out.println(); java.lang.System.out.println(); some.other.System.out.println();"; - private static final String s70 = " System.out "; - private static final String s70_2 = " java.lang.System.out "; private static final String s71 = " class A { " + "class D { D() { c(); } }" + - "void a() { c(); new MouseListenener() { void b() { c(); } } }" + + "void a() { c(); new MouseListener() { void b() { c(); } } }" + " }"; - private static final String s72 = " c(); "; private static final String s73 = " class A { int A; static int B=5; public abstract void a(int c); void q() { ind d=7; } }"; - private static final String s74 = " '_Type 'Var = '_Init?; "; private static final String s75 = "/** @class aClass\n @author the author */ class A {}\n" + "/** */ class B {}\n" + "/** @class aClass */ class C {}"; - private static final String s76 = " /** @'_tag+ '_value+ */"; - private static final String s76_2 = " /** @'_tag* '_value* */"; - private static final String s76_3 = " /** @'_tag? '_value? */ class 't {}"; private static final String s77 = " new ActionListener() {} "; - private static final String s78 = " class 'T:.*aaa {} "; private static final String s79 = " class A { static { int c; } void a() { int b; b=1; }} "; - private static final String s80 = " { '_T 'T3 = '_T2?; '_*; } "; private static final String s81 = "class Pair {" + " void a(B b, D e) throws C {" + @@ -275,13 +207,6 @@ public class StructuralSearchTest extends StructuralSearchTestCase { private static final String s81_2 = "class Double {} class T {} class Single {}"; - private static final String s82 = "class '_<'T+> {}"; - private static final String s82_2 = "'_Expr instanceof '_Type<'_Parameter+>"; - private static final String s82_3 = "( '_Type<'_Parameter+> ) '_Expr"; - private static final String s82_4 = "'_Type<'_Parameter+> 'a = '_Init?;"; - private static final String s82_5 = "class '_ { <'_+> '_Type 'Method('_* '_*); }"; - private static final String s82_6 = "class '_<'_+ extends 'res+> {}"; - private static final String s82_7 = "'Type"; private static final String s83 = "/**\n" + " * @hibernate.class\n" + @@ -326,15 +251,8 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " }\n" + "}"; - private static final String s84 = " /**\n" + - " * @hibernate.property\n" + - " * 'Property+\n" + - " */\n"; - private static final String s84_2 = " /**\n" + - " * @hibernate.property\n" + - " * update=\"fa.se\"\n" + - " */\n"; + private static final String s85 = "{ int a; a=1; a=1; return a; }"; private static final String s86 = "'T; 'T;"; @@ -344,12 +262,6 @@ public class StructuralSearchTest extends StructuralSearchTestCase { private static final String s88_2 = " 'Call('_*); "; private static final String s88_3 = " '_Instance?.'Call('_*); "; private static final String s89 = "{ a = 1; b = 2; c=3; }"; - private static final String s90 = "{ '_T*; '_T2*; }"; - private static final String s90_2 = " { '_T*; '_T2*; '_T3+; } "; - private static final String s90_3 = " { '_T+; '_T2+; '_T3+; '_T4+; } "; - private static final String s90_4 = " { '_T{1,3}; '_T2{2}; } "; - private static final String s90_5 = " { '_T{1}?; '_T2*?; '_T3+?; } "; - private static final String s90_6 = " { '_T{1}?; '_T2{1,2}?; '_T3+?; '_T4+?; } "; private static final String s91 = "class a {\n" + " void b() {\n" + @@ -360,26 +272,11 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " a a1;\n" + " }\n" + "}"; - private static final String s92 = "'T:a"; - private static final String s92_2 = "'T:b"; - private static final String s92_3 = "'T:c"; private static final String s93 = " class A {" + "private int field;" + "public void b() {}" + "}"; - private static final String s94 = " class '_ {" + - "private void b() {}" + - "}"; - private static final String s94_2 = " class '_ {" + - "public void b() {}" + - "}"; - private static final String s94_3 = " class '_ {" + - "protected int field;" + - "}"; - private static final String s94_4 = " class '_ {" + - "private int field;" + - "}"; private static final String s95 = " class Clazz {" + "private int field;" + @@ -387,118 +284,53 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "private int fiel-d2;" + "}"; - private static final String s96 = " class '_ {" + - "private int 'T+:field.* ;" + - "}"; - public void testSearchExpressions() { - assertFalse("subexpr match",findMatchesCount(s2,s3)==0); - assertEquals("search for new ",findMatchesCount(s10,s11),0); - assertEquals("search for anonymous classes",findMatchesCount(s12,s13),1); - // expr in definition initializer - assertEquals( - "expr in def initializer", - 3, - findMatchesCount(s53,s54) - ); + assertFalse("subexpr match", findMatchesCount(s2, "dialog = new SearchDialog()") == 0); + assertEquals("search for new ", 0, findMatchesCount(s10, " new XXX()")); + assertEquals("search for anonymous classes", 1, findMatchesCount(s12, "new Runnable() {}")); + assertEquals("expr in def initializer", 3, findMatchesCount(s53, "System.getProperty('T)")); - // a.class expression search - assertEquals( - "a.class pattern", - findMatchesCount(s55,s56), - 1 - ); + assertEquals("a.class expression", 1, findMatchesCount(s55, "'T.class")); String complexCode = "interface I { void b(); } interface I2 extends I {} class I3 extends I {} " + "class A implements I2 { void b() {} } class B implements I3 { void b() {}} " + "I2 a; I3 b; a.b(); b.b(); b.b(); A c; B d; c.b(); d.b(); d.b(); "; - String exprTypePattern1 = "'t:[exprtype( I2 )].b();"; - String exprTypePattern2 = "'t:[!exprtype( I2 )].b();"; - - String exprTypePattern3 = "'t:[exprtype( *I2 )].b();"; - String exprTypePattern4 = "'t:[!exprtype( *I2 )].b();"; - - assertEquals( - "expr type condition", - findMatchesCount(complexCode,exprTypePattern1), - 1 - ); - - assertEquals( - "expr type condition 2", - 5, - findMatchesCount(complexCode,exprTypePattern2) - ); - - assertEquals( - "expr type condition 3", - findMatchesCount(complexCode,exprTypePattern3), - 2 - ); - - assertEquals( - "expr type condition 4", - findMatchesCount(complexCode,exprTypePattern4), - 4 - ); + assertEquals("expr type condition", 1, findMatchesCount(complexCode, "'t:[exprtype( I2 )].b();")); + assertEquals("expr type condition 2", 5, findMatchesCount(complexCode, "'t:[!exprtype( I2 )].b();")); + assertEquals("expr type condition 3", 2, findMatchesCount(complexCode, "'t:[exprtype( *I2 )].b();")); + assertEquals("expr type condition 4", 4, findMatchesCount(complexCode, "'t:[!exprtype( *I2 )].b();")); String complexCode2 = "enum X { XXX, YYY }\n class C { static void ordinal() {} void test() { C c; c.ordinal(); c.ordinal(); X.XXX.ordinal(); } }"; - assertEquals( - "expr type condition with enums", - findMatchesCount(complexCode2, "'t:[exprtype( *java\\.lang\\.Enum )].ordinal()"), - 1 - ); + assertEquals("expr type condition with enums", 1, + findMatchesCount(complexCode2, "'t:[exprtype( *java\\.lang\\.Enum )].ordinal()")); - assertEquals( - "no smart detection of search target", - findMatchesCount("processInheritors(1,2,3,4); processInheritors(1,2,3); processInheritors(1,2,3,4,5,6);","'instance?.processInheritors('_param1{1,6});"), - 3 - ); + final String in = "processInheritors(1,2,3,4); " + + "processInheritors(1,2,3); " + + "processInheritors(1,2,3,4,5,6);"; + assertEquals("no smart detection of search target", 3, + findMatchesCount(in, "'instance?.processInheritors('_param1{1,6});")); String arrays = "int[] a = new int[20];\n" + "byte[] b = new byte[30]"; - String arrayPattern = "new int['_a]"; - assertEquals( - "Improper array search", - 1, - findMatchesCount(arrays,arrayPattern) - ); + assertEquals("Improper array search", 1, findMatchesCount(arrays, "new int['_a]")); String someCode = "a *= 2; a+=2;"; - String otherCode = "a *= 2;"; - - assertEquals( - "Improper *= 2 search", - 1, - findMatchesCount(someCode,otherCode) - ); + assertEquals("Improper *= 2 search", 1, findMatchesCount(someCode, "a *= 2;")); String s1 = "Thread t = new Thread(\"my thread\",\"my another thread\") {\n" + " public void run() {\n" + " // do stuff\n" + " }\n" + "}"; - String s2 = "new Thread('args*) { '_Other* }"; - - assertEquals( - "Find inner class parameters", - 2, - findMatchesCount(s1,s2) - ); + assertEquals("Find inner class parameters", 2, findMatchesCount(s1, "new Thread('args*) { '_Other* }")); String s3 = "Thread t = new Thread(\"my thread\") {\n" + " public void run() {\n" + " // do stuff\n" + " }\n" + "};"; - String s4 = "new Thread('_args)"; - - assertEquals( - "Find inner class by new", - 1, - findMatchesCount(s3,s4) - ); + assertEquals("Find inner class by new", 1, findMatchesCount(s3, "new Thread('_args)")); String s5 = "class A {\n" + "public static T[] copy(T[] array, Class aClass) {\n" + @@ -507,13 +339,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " return (T[])array.clone();\n" + " }\n" + "}"; - String s6 = "('_T[])'_expr"; - - assertEquals( - "Find cast to array", - 1, - findMatchesCount(s5,s6) - ); + assertEquals("Find cast to array", 1, findMatchesCount(s5, "('_T[])'_expr")); String s7 = "import java.math.BigDecimal;\n" + "\n" + @@ -547,22 +373,11 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " prorator.prorate(something[0]);\n" + " }\n" + "}"; - String s8 = "'_Instance.'_MethodCall:[regex( prorate )]('_Param:[exprtype( BigDecimal\\[\\] )]) "; - - assertEquals( - "Find method call with array for parameter expr type", - 2, - findMatchesCount(s7,s8,true) - ); + assertEquals("Find method call with array for parameter expr type", 2, + findMatchesCount(s7, "'_Instance.'_MethodCall:[regex( prorate )]('_Param:[exprtype( BigDecimal\\[\\] )]) ", true)); String s13 = "try { } catch(Exception e) { e.printStackTrace(); }"; - String s14 = "'_Instance.'_MethodCall('_Parameter*)"; - - assertEquals( - "Find statement in catch", - 1, - findMatchesCount(s13,s14) - ); + assertEquals("Find statement in catch", 1, findMatchesCount(s13, "'_Instance.'_MethodCall('_Parameter*)")); String s9 = "int a[] = new int[] { 1,2,3,4};\n" + "int b[] = { 2,3,4,5 };\n" + @@ -620,87 +435,32 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " static String s = \"aaa\";\n" + " static String s2;\n" + "}"; - String s2 = "static String '_FieldName = '_Init?:[!regex( \".*\" )];"; - String s2_2 = "static String '_FieldName = '_Init:[!regex( \".*\" )];"; + assertEquals("Literal", 2, findMatchesCount(s, "static String '_FieldName = '_Init?:[!regex( \".*\" )];")); + assertEquals("Literal, 2", 1, findMatchesCount(s, "static String '_FieldName = '_Init:[!regex( \".*\" )];")); + assertEquals("String literal", 1, findMatchesCount(s, "\"'String\"")); - assertEquals( - "Literal", - 2, - findMatchesCount(s,s2) - ); - - assertEquals( - "Literal, 2", - 1, - findMatchesCount(s,s2_2) - ); - - String pattern3 = "\"'String\""; - assertEquals("String literal", 1, findMatchesCount(s, pattern3)); - - String pattern4 = "\"test\""; String source = "@SuppressWarnings(\"test\") class A {" + " @SuppressWarnings({\"other\", \"test\"}) String field;" + "}"; - assertEquals("String literal in annotation", 2, findMatchesCount(source, pattern4)); + assertEquals("String literal in annotation", 2, findMatchesCount(source, "\"test\"")); } public void testCovariantArraySearch() { String s1 = "String[] argv;"; String s2 = "String argv;"; - String s3 = "'T[] argv;"; - String s3_2 = "'T:*Object [] argv;"; - - assertEquals( - "Find array types", - 0, - findMatchesCount(s1,s2) - ); - - assertEquals( - "Find array types, 2", - 0, - findMatchesCount(s2,s1) - ); - - assertEquals( - "Find array types, 3", - 0, - findMatchesCount(s2,s3) - ); - - assertEquals( - "Find array types, 3", - 1, - findMatchesCount(s1,s3_2) - ); + assertEquals("Find array types", 0, findMatchesCount(s1, s2)); + assertEquals("Find array types, 2", 0, findMatchesCount(s2, s1)); + assertEquals("Find array types, 3", 0, findMatchesCount(s2, "'T[] argv;")); + assertEquals("Find array types, 3", 1, findMatchesCount(s1, "'T:*Object [] argv;")); String s11 = "class A {\n" + " void main(String[] argv);" + " void main(String argv[]);" + " void main(String argv);" + "}"; - String s12 = "'_t:[regex( *Object\\[\\] ) ] '_t2;"; - String s12_2 = "'_t:[regex( *Object ) ] '_t2 [];"; - String s12_3 = "'_t:[regex( *Object ) ] '_t2;"; - - assertEquals( - "Find array covariant types", - 2, - findMatchesCount(s11,s12) - ); - - assertEquals( - "Find array covariant types, 2", - 2, - findMatchesCount(s11,s12_2) - ); - - assertEquals( - "Find array covariant types, 3", - 1, - findMatchesCount(s11,s12_3) - ); + assertEquals("Find array covariant types", 2, findMatchesCount(s11, "'_t:[regex( *Object\\[\\] ) ] '_t2;")); + assertEquals("Find array covariant types, 2", 2, findMatchesCount(s11, "'_t:[regex( *Object ) ] '_t2 [];")); + assertEquals("Find array covariant types, 3", 1, findMatchesCount(s11, "'_t:[regex( *Object ) ] '_t2;")); } public void testFindArrayDeclarations() { @@ -739,19 +499,19 @@ public class StructuralSearchTest extends StructuralSearchTestCase { assertEquals("find primitive array 4", 1, findMatchesCount(source3, "'_T:[regex( int\\[\\] )] '_a;")); } - // @todo support back references (\1 in another reg exp or as fild member) + // @todo support back references (\1 in another reg exp or as field member) //private static final String s1002 = " setSSS( instance.getSSS() ); " + // " setSSS( instance.SSS ); "; //private static final String s1003 = " 't:set(.+) ( '_.get't_1() ); "; //private static final String s1003_2 = " 't:set(.+) ( '_.'t_1 ); "; public void testSearchStatements() { - assertEquals("statement search",findMatchesCount(s1,s2),1); - assertEquals("several constructions match",findMatchesCount(s5,s4),3); + assertEquals("statement search", 1, findMatchesCount(s1, s2)); + assertEquals("several constructions match", 3, findMatchesCount(s5, s4)); assertFalse("several constructions 2",(findMatchesCount(s5,s6))!=0); - assertEquals("several constructions 3",findMatchesCount(s7,s8),2); - assertEquals("several constructions 4",findMatchesCount(s7,s9),2); + assertEquals("several constructions 3", 2, findMatchesCount(s7, s8)); + assertEquals("several constructions 4", 2, findMatchesCount(s7, s9)); final String s1000 = "{ lastTest = \"search for parameterized pattern\";\n" + " matches = testMatcher.findMatches(s14_1,s15, options);\n" + @@ -763,87 +523,32 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " matches = testMatcher.findMatches('_In,'_Pattern, options);\n" + " if (matches.size()!='_Number ) return false;"; - assertEquals("several operators 5",findMatchesCount(s1000,s1001),2); - - assertEquals( - "two the same statements search", - findMatchesCount(s85,s86), - 1 - ); - - assertEquals( - "search for simple call", - findMatchesCount(s87,s88), - 1 - ); - - assertEquals( - "search for simple call 2", - findMatchesCount(s87,s88_2), - 1 - ); - - assertEquals( - "search for simple call 3", - findMatchesCount(s87,s88_3), - 2 - ); + assertEquals("several operators 5", 2, findMatchesCount(s1000, s1001)); + assertEquals("two the same statements search", 1, findMatchesCount(s85,s86)); + assertEquals("search for simple call", 1, findMatchesCount(s87,s88)); + assertEquals("search for simple call 2", 1, findMatchesCount(s87,s88_2)); + assertEquals("search for simple call 3", 2, findMatchesCount(s87,s88_3)); String s10015 = "DocumentListener[] listeners = getCachedListeners();"; - String s10016 = "'_Type 'Var = '_Call();"; - - assertEquals( - "search for definition with init", - 1, - findMatchesCount(s10015,s10016) - ); + assertEquals("search for definition with init", 1, findMatchesCount(s10015, "'_Type 'Var = '_Call();")); String s10017 = "a = b; b = c; a=a; c=c;"; - String s10018 = "'_a = '_a;"; - - assertEquals( - "search silly assignments", - 2, - findMatchesCount(s10017,s10018) - ); + assertEquals("search silly assignments", 2, findMatchesCount(s10017, "'_a = '_a;")); String s10019 = "a.b(); a.b(null); a.b(null, 1);"; - String s10020 = "a.b(null);"; - - assertEquals( - "search parameter", - 1, - findMatchesCount(s10019,s10020) - ); + assertEquals("search parameter", 1, findMatchesCount(s10019, "a.b(null);")); String s1008 = "int a, b, c, d; int a,b,c; int c,d; int e;"; - String s1009 = "int '_a{3,4};"; - - assertEquals( - "search many declarations", - 2, - findMatchesCount(s1008,s1009) - ); + assertEquals("search many declarations", 2, findMatchesCount(s1008, "int '_a{3,4};")); String s1 = "super(1,1); call(1,1); call(2,2);"; - String s2 = "super('_t*);"; - - assertEquals( - "search super", - 1, - findMatchesCount(s1,s2) - ); + assertEquals("search super", 1, findMatchesCount(s1, "super('_t*);")); String s10021 = "short a = 1;\n" + "short b = 2;\n" + "short c = a.b();"; - String s10022 = "short '_a = '_b.b();"; - assertEquals( - "search def init bug", - 1, - findMatchesCount(s10021,s10022) - ); + assertEquals("search def init bug", 1, findMatchesCount(s10021, "short '_a = '_b.b();")); String s10023 = "abstract class A { public abstract short getType(); }\n" + "A a;\n" + @@ -855,65 +560,34 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " case 1:\n" + " { return 0; }\n" + "}"; - String s10024 = "switch('_a:[exprtype( short )]) { '_statement*; }"; - assertEquals( - "finding switch", - 2, - findMatchesCount(s10023,s10024) - ); + assertEquals("finding switch", 2, + findMatchesCount(s10023, "switch('_a:[exprtype( short )]) { '_statement*; }")); String s10025 = "A[] a;\n" + "A b[];\n" + "A c;"; - String s10026 = "A[] 'a;"; - String s10026_2 = "A 'a[];"; - - assertEquals( - "array types in dcl", - 2, - findMatchesCount(s10025,s10026) - ); - - assertEquals( - "array types in dcl 2", - 2, - findMatchesCount(s10025,s10026_2) - ); + assertEquals("array types in dcl", 2, findMatchesCount(s10025, "A[] 'a;")); + assertEquals("array types in dcl 2", 2, findMatchesCount(s10025, "A 'a[];")); String s10027 = "try { a(); } catch(Exception ex) {}\n" + "try { a(); } finally {}\n" + "try { a(); } catch(Exception ex) {} finally {} \n"; - String s10028 = "try { a(); } finally {}\n"; - assertEquals( - "finally matching", - 2, - findMatchesCount(s10027,s10028) - ); + assertEquals("finally matching", 2, findMatchesCount(s10027, "try { a(); } finally {}\n")); String s10029 = "for(String a:b) { System.out.println(a); }"; - String s10030 = "for(String a:b) { '_a; }"; - assertEquals( - "for each matching", - 1, - findMatchesCount(s10029,s10030) - ); + assertEquals("for each matching", 1, findMatchesCount(s10029, "for(String a:b) { '_a; }")); String s10031 = "try { a(); } catch(Exception ex) {} catch(Error error) { 1=1; }\n" + "try { a(); } catch(Exception ex) {}"; - String s10032 = "try { a(); } catch('_Type+ 'Arg+) { '_Statements*; }\n"; - assertEquals( - "finally matching", - 2, - findMatchesCount(s10031,s10032) - ); + assertEquals("finally matching", 2, + findMatchesCount(s10031, "try { a(); } catch('_Type+ 'Arg+) { '_Statements*; }\n")); String s10033 = "return x;\n" + "return !x;\n" + "return (x);\n" + "return (x);\n" + "return !(x);"; - String s10034 = "return ('a);"; - assertEquals("Find statement with parenthesized expr",2,findMatchesCount(s10033,s10034)); + assertEquals("Find statement with parenthesized expr",2,findMatchesCount(s10033, "return ('a);")); String in = "if (true) {" + " System.out.println();" + @@ -921,116 +595,42 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " System.out.println();" + "}" + "if (true) System.out.println();"; - String pattern1 = "if ('_exp) { '_statement*; }"; - assertEquals("Find if statement with else", 2, findMatchesCount(in, pattern1)); - - String pattern2 = "if ('_exp) { '_statement*; } else { '_statement2{0,0}; }"; - assertEquals("Find if statement without else", 1, findMatchesCount(in, pattern2)); + assertEquals("Find if statement with else", 2, findMatchesCount(in, "if ('_exp) { '_statement*; }")); + assertEquals("Find if statement without else", 1, + findMatchesCount(in, "if ('_exp) { '_statement*; } else { '_statement2{0,0}; }")); } public void testSearchClass() { - // no modifier list in interface vars - assertEquals( - "no modifier for interface vars", - findMatchesCount(s43,s44), - 3 - ); - - // different order of access modifiers - assertEquals( - "different order of access modifiers", - findMatchesCount(s45,s46), - 1 - ); - - // no access modifiers - assertEquals( - "no access modifier", - findMatchesCount(s45,s46_2), - 2 - ); - - // type could differ with package - assertEquals( - "type differs with package", - findMatchesCount(s47,s48), - 2 - ); - - // reference element could differ in package - assertEquals( - "reference could differ in package", - findMatchesCount(s49,s50), - 1 - ); + assertEquals("no modifier for interface vars", 3, findMatchesCount(s43, "interface '_ { '_T 'T2 = '_T3; } ")); + assertEquals("different order of access modifiers", 1, + findMatchesCount(s45, "class '_ { final static private '_T 'T2 = '_T3; } ")); + assertEquals("no access modifier", 2, findMatchesCount(s45, "class '_ { '_T 'T2 = '_T3; } ")); + assertEquals("type differs with package", 2, findMatchesCount(s47, "class '_ { String '_; }")); + assertEquals("reference could differ in package", 1, + findMatchesCount(s49, "class '_ { '_ '_() throws RuntimeException; }")); String s51 = "class C extends java.awt.List {} class A extends java.util.List {} class B extends java.awt.List {} "; - String s52 = "class 'B extends '_C:java\\.awt\\.List {}"; - - assertEquals( - "reference could differ in package 2", - findMatchesCount(s51,s52), - 2 - ); - - assertEquals( - "method access modifier", - findMatchesCount(s93,s94), - 0 - ); - - assertEquals( - "method access modifier 2", - findMatchesCount(s93,s94_2), - 1 - ); - - assertEquals( - "field access modifier", - findMatchesCount(s93,s94_3), - 0 - ); - - assertEquals( - "field access modifier 2", - findMatchesCount(s93,s94_4), - 1 - ); + assertEquals("reference could differ in package 2", 2, + findMatchesCount(s51, "class 'B extends '_C:java\\.awt\\.List {}")); + assertEquals("method access modifier", 0, findMatchesCount(s93, " class '_ {private void b() {}}")); + assertEquals("method access modifier 2", 1, findMatchesCount(s93, " class '_ {public void b() {}}")); + assertEquals("field access modifier", 0, findMatchesCount(s93, " class '_ {protected int field;}")); + assertEquals("field access modifier 2", 1, findMatchesCount(s93, " class '_ {private int field;}")); final String s127 = "class a { void b() { new c() {}; } }"; - final String s128 = "class 't {}"; - assertEquals( - "class finds anonymous class", - findMatchesCount(s127,s128), - 2 - ); + assertEquals("class finds anonymous class", 2, findMatchesCount(s127, "class 't {}")); final String s129 = "class a { public void run() {} }\n" + "class a2 { public void run() { run(); } }\n" + "class a3 { public void run() { run(); } }\n" + "class a4 { public void run(); }"; - final String s130 = "class 'a { public void run() {} }"; - final String s130_2 = "class 'a { public void run() { '_statement; } }"; - final String s130_3 = "class 'a { public void run(); }"; - - assertEquals( - "empty method finds empty method only", - findMatchesCount(s129,s130), - 1 - ); - - assertEquals( - "nonempty method finds nonempty method", - findMatchesCount(s129,s130_2), - 2 - ); - - assertEquals( - "nonempty method finds nonempty method", - findMatchesCount(s129,s130_3), - 4 - ); + assertEquals("empty method finds empty method only", 1, + findMatchesCount(s129, "class 'a { public void run() {} }")); + assertEquals("nonempty method finds nonempty method", 2, + findMatchesCount(s129, "class 'a { public void run() { '_statement; } }")); + assertEquals("nonempty method finds nonempty method", 4, + findMatchesCount(s129, "class 'a { public void run(); }")); final String s133 = "class S {\n" + "void cc() {\n" + @@ -1083,11 +683,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " void f();\n" + " '_type '_method{0,0} ('_paramtype* '_paramname* );\n" + "}"; - assertEquals( - "reject method with 0 max occurence", - findMatchesCount(s135,s136), - 1 - ); + assertEquals("reject method with 0 max occurence", 1, findMatchesCount(s135,s136)); final String s137 = "abstract class My {\n" + " int a;\n" + @@ -1102,54 +698,30 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "abstract class My {\n" + " int a = 1;\n" + "}\n"; - final String s138 = "class 'm {\n" + - " Project '_f{0,0} = '_t?;\n" + - "}"; - assertEquals( - "reject field with 0 max occurence", - findMatchesCount(s137,s138), - 2 - ); + assertEquals("reject field with 0 max occurence", 2, + findMatchesCount(s137, "class 'm { Project '_f{0,0} = '_t?; }")); final String s139 = "class My { boolean equals(Object o); int hashCode(); }"; - final String s139_2 = "class My { boolean equals(Object o); }"; final String s140 = "class 'A { boolean equals(Object '_o ); int '_hashCode{0,0}:hashCode (); }"; + assertEquals("reject method with constraint", 0, findMatchesCount(s139,s140)); - assertEquals( - "reject method with constraint", - findMatchesCount(s139,s140), - 0 - ); - - assertEquals( - "reject field with 0 max occurence", - findMatchesCount(s139_2,s140), - 1 - ); + final String s139_2 = "class My { boolean equals(Object o); }"; + assertEquals("reject field with 0 max occurence", 1, findMatchesCount(s139_2,s140)); final String s141 = "class A { static { a = 10 } }\n" + "class B { { a = 10; } }\n" + "class C { { a = 10; } }"; - final String s142 = "class '_ { static { a = 10; } } "; - assertEquals( - "static block search", - findMatchesCount(s141,s142), - 1 - ); + assertEquals("static block search", 1, findMatchesCount(s141, "class '_ { static { a = 10; } } ")); } - public void testParameterlessContructorSearch() { + public void testParameterlessConstructorSearch() { final String s143 = "class A { A() {} };\n" + "class B { B(int a) {} };\n" + "class C { C() {} C(int a) {} };\n" + "class D {}\n" + "class E {}"; - final String s144 = "class '_a { '_d{0,0}:[ script( \"__context__.constructor\" ) ]('_b+ '_c+); }"; - assertEquals( - "parameterless contructor search", - 3, - findMatchesCount(s143,s144) - ); + assertEquals("parameterless constructor search", 3, + findMatchesCount(s143, "class '_a { '_d{0,0}:[ script( \"__context__.constructor\" ) ]('_b+ '_c+); }")); } public void testScriptSearch() { @@ -1212,18 +784,14 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "}")); assertEquals("Current variable should be available under own name", 1, - findMatchesCount(source2, - "'_a + '_b:[script(\"__log__.info(b)\n__log__.info(__context__)\ntrue\")]")); + findMatchesCount(source2, "'_a + '_b:[script(\"__log__.info(b)\n__log__.info(__context__)\ntrue\")]")); } public void testCheckScriptValidation() { - final String s1 = ""; - final String s2 = "'_b:[script( \"^^^\" )]"; - try { - final int count = findMatchesCount(s1, s2); - assertFalse("Validation does not work", true); - } catch (MalformedPatternException ex) {} + findMatchesCount("", "'_b:[script( \"^^^\" )]"); + fail("Validation does not work"); + } catch (MalformedPatternException ignored) {} } //public void testRelationBetweenVars() { @@ -1255,12 +823,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " }\n" + "}"; String s2 = "'_map:[exprtype( *java\\.util\\.Map )].put('_key:[ exprtype( *Object ) ], '_value:[ exprtype( *AppPreferences ) ]);"; - - assertEquals( - "expr type with object", - 4, - findMatchesCount(s1,s2,true) - ); + assertEquals("expr type with object", 4, findMatchesCount(s1,s2,true)); } public void testInterfaceImplementationsSearch() { @@ -1290,50 +853,19 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " class D extends C {\n" + " \n" + " }"; - String what = "class 'A implements '_B:*Serializable , '_C:*Cloneable {}"; - assertEquals( - "search interface within hierarchy", - 5, - findMatchesCount(in, what) - ); + assertEquals("search interface within hierarchy", 5, + findMatchesCount(in, "class 'A implements '_B:*Serializable , '_C:*Cloneable {}")); } public void testSearchBacktracking() { - assertEquals( - "backtracking greedy regexp", - findMatchesCount(s89,s90), - 1 - ); - - assertEquals( - "backtracking greedy regexp 2", - findMatchesCount(s89,s90_2), - 1 - ); - - assertEquals( - "backtracking greedy regexp 3", - findMatchesCount(s89,s90_3), - 0 - ); - - assertEquals( - "counted regexp (with back tracking)", - findMatchesCount(s89,s90_4), - 1 - ); - - assertEquals( - "nongreedy regexp (counted, with back tracking)", - findMatchesCount(s89,s90_5), - 1 - ); - - assertEquals( - "nongreedy regexp (counted, with back tracking) 2", - findMatchesCount(s89,s90_6), - 0 - ); + assertEquals("backtracking greedy regexp", 1, findMatchesCount(s89, "{ '_T*; '_T2*; }")); + assertEquals("backtracking greedy regexp 2", 1, findMatchesCount(s89, " { '_T*; '_T2*; '_T3+; } ")); + assertEquals("backtracking greedy regexp 3", 0, findMatchesCount(s89, " { '_T+; '_T2+; '_T3+; '_T4+; } ")); + assertEquals("counted regexp (with back tracking)", 1, findMatchesCount(s89, " { '_T{1,3}; '_T2{2}; } ")); + assertEquals("nongreedy regexp (counted, with back tracking)", 1, + findMatchesCount(s89, " { '_T{1}?; '_T2*?; '_T3+?; } ")); + assertEquals("nongreedy regexp (counted, with back tracking) 2", 0, + findMatchesCount(s89, " { '_T{1}?; '_T2{1,2}?; '_T3+?; '_T4+?; } ")); String s1000 = "class A {\n" + " void _() {}\n" + @@ -1342,47 +874,24 @@ public class StructuralSearchTest extends StructuralSearchTestCase { String s1001 = "class '_Class { \n" + " '_ReturnType+ 'MethodName+ ('_ParameterType* '_Parameter* );\n" + "}"; - assertEquals( - "handling of no match", - findMatchesCount(s1000,s1001), - 2 - ); + assertEquals("handling of no match", 2, findMatchesCount(s1000,s1001)); } public void testSearchSymbol() { final String s131 = "a.b(); c.d = 1; "; - final String s132 = "'T:b|d"; - - assertEquals( - "symbol match", - 2, - findMatchesCount(s131,s132) - ); - - final String s129 = "A a = new A();"; - final String s130 = "'Sym:A"; + assertEquals("symbol match", 2, findMatchesCount(s131, "'T:b|d")); options.setCaseSensitiveMatch(true); - assertEquals( - "case sensitive match", - findMatchesCount(s129,s130), - 2 - ); + final String s129 = "A a = new A();"; + assertEquals("case sensitive match", 2, findMatchesCount(s129, "'Sym:A")); final String s133 = "class C { int a; int A() { a = 1; }} void c(int a) { a = 2; }"; - final String s133_2 = "class C { int a() {} int A() { a(1); }}"; final String s134 = "a"; + assertEquals("find sym finds declaration", 4, findMatchesCount(s133, s134, true, StdFileTypes.JAVA)); - List results = findMatches(s133, s134, true, StdFileTypes.JAVA); - assertEquals( - "find sym finds declaration", - 4, results.size() - ); + final String s133_2 = "class C { int a() {} int A() { a(1); }}"; + assertEquals("find sym finds declaration", 2, findMatchesCount(s133_2, s134, true)); - assertEquals( - "find sym finds declaration", - 2, findMatchesCount(s133_2, s134, true) - ); final String in = "class C {" + " {" + " int i = 0;" + @@ -1393,11 +902,8 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " }" + " void i() {}" + "}"; - final String pattern1 = "'_:[read]"; - assertEquals("Find reads of symbol (including operator assignment)", 2, findMatchesCount(in, pattern1)); - - final String pattern2 = "'_:[write && regex( i )]"; - assertEquals("Find writes of symbol", 3, findMatchesCount(in, pattern2)); + assertEquals("Find reads of symbol (including operator assignment)", 2, findMatchesCount(in, "'_:[read]")); + assertEquals("Find writes of symbol", 3, findMatchesCount(in, "'_:[write && regex( i )]")); final String source = "class A {" + " static A a() {};" + @@ -1405,64 +911,21 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " A a = A.a();" + " }" + "}"; - final String pattern3 = "A"; - assertEquals("No duplicate results", 4, findMatchesCount(source, pattern3)); + assertEquals("No duplicate results", 4, findMatchesCount(source, "A")); } public void testSearchGenerics() { - assertEquals( - "parameterized class match", - findMatchesCount(s81,s82), - 2 - ); + assertEquals("parameterized class match", 2, findMatchesCount(s81, "class '_<'T+> {}")); + assertEquals("parameterized instanceof match", 1, findMatchesCount(s81, "'_Expr instanceof '_Type<'_Parameter+>")); + assertEquals("parameterized cast match", 1, findMatchesCount(s81, "( '_Type<'_Parameter+> ) '_Expr")); + assertEquals("parameterized symbol without variables matching", 2, findMatchesCount(s81, "S")); + assertEquals("parameterized definition match", 3, findMatchesCount(s81, "'_Type<'_Parameter+> 'a = '_Init?;")); + assertEquals("parameterized method match", 1, findMatchesCount(s81, "class '_ { <'_+> '_Type 'Method('_* '_*); }")); + assertEquals("parameterized constraint match", 2, findMatchesCount(s81_2, "class '_<'_+ extends 'res+> {}")); - assertEquals( - "parameterized instanceof match", - findMatchesCount(s81,s82_2), - 1 - ); - - assertEquals( - "parameterized cast match", - findMatchesCount(s81,s82_3), - 1 - ); - - assertEquals( - "parameterized symbol without variables matching", - findMatchesCount(s81, "S"), - 2 - ); - - assertEquals( - "parameterized definition match", - findMatchesCount(s81,s82_4), - 3 - ); - - assertEquals( - "parameterized method match", - findMatchesCount(s81,s82_5), - 1 - ); - - assertEquals( - "parameterized constraint match", - findMatchesCount(s81_2,s82_6), - 2 - ); - - assertEquals( - "symbol matches parameterization", - findMatchesCount(s81,s82_7), - 29 - ); - - assertEquals( - "symbol matches parameterization 2", - findMatchesCount(s81_2,s82_7), - 7 - ); + String s82_7 = "'Type"; + assertEquals("symbol matches parameterization", 29, findMatchesCount(s81,s82_7)); + assertEquals("symbol matches parameterization 2", 7, findMatchesCount(s81_2,s82_7)); String s81_3 = " class A {\n" + " public static Collection unmodifiableCollection(int c) {\n" + @@ -1472,11 +935,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " public T[] toArray(T[] a) {return c.toArray(a);}\n" + " }\n" + "}"; - assertEquals( - "typed symbol symbol", - findMatchesCount(s81_3,s82_5), - 2 - ); + assertEquals("typed symbol symbol", 2, findMatchesCount(s81_3, "class '_ { <'_+> '_Type 'Method('_* '_*); }")); String s81_4="class A { \n" + " static void c(D f) throws R {\n" + @@ -1491,76 +950,28 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " if (g instanceof H) { a.c(); b.d(new A() {}); throw new Exception(((I)k)); }"+ " }\n" + "}"; - String s82_8 = "'T<'_Subst+>"; - assertEquals( - "typed symbol", - 8, - findMatchesCount(s81_4,s82_8) - ); + assertEquals("typed symbol", 8, findMatchesCount(s81_4, "'T<'_Subst+>")); String s81_5 = "class A { HashMap variable = new HashMap(\"aaa\");}"; String s82_9 = "'_Type<'_GType, '_GType2> '_instance = new '_Type<'_GType, '_GType2>('_Param);"; - assertEquals( - "generic vars in new", - findMatchesCount(s81_5,s82_9), - 1 - ); - assertEquals( - "no exception on searching for diamond operator", - findMatchesCount(s81_5, "new 'Type<>('_Param)"), - 0 - ); - assertEquals( - "order of parameters matters", - 0, - findMatchesCount(s81_5, "HashMap") - ); - assertEquals( - "order of parameters matters 2", - 2, - findMatchesCount(s81_5, "HashMap") - ); + assertEquals("generic vars in new", 1, findMatchesCount(s81_5,s82_9)); + assertEquals("no exception on searching for diamond operator", 0, findMatchesCount(s81_5, "new 'Type<>('_Param)")); + assertEquals("order of parameters matters", 0, findMatchesCount(s81_5, "HashMap")); + assertEquals("order of parameters matters 2", 2, findMatchesCount(s81_5, "HashMap")); String source1 = "class Comparator { private Comparator c; private Comparator d; private Comparator e; }"; - String target1 = "java.util.Comparator 'a;"; - assertEquals( - "qualified type should not match 1", - 0, - findMatchesCount(source1, target1) - ); + assertEquals("qualified type should not match 1", 0, findMatchesCount(source1, "java.util.Comparator 'a;")); + assertEquals("qualified type should not match 2", 0, findMatchesCount(source1, "java.util.Comparator 'a;")); - String target2 = "java.util.Comparator 'a;"; - assertEquals( - "qualified type should not match 2", - 0, - findMatchesCount(source1, target2) - ); + assertEquals("unparameterized type query should match", 3, findMatchesCount(source1, "Comparator 'a;")); + assertEquals("parameterized type query should only match parameterized", 1, + findMatchesCount(source1, "Comparator<'_a> 'b;")); - assertEquals( - "unparameterized type query should match", - 3, - findMatchesCount(source1, "Comparator 'a;") - ); - - assertEquals( - "parameterized type query should only match parameterized", - 1, - findMatchesCount(source1, "Comparator<'_a> 'b;") - ); - - assertEquals( - "should find unparameterized only", - 2, - findMatchesCount(source1, "Comparator<'_a{0,0}> 'b;") - ); + assertEquals("should find unparameterized only", 2, findMatchesCount(source1, "Comparator<'_a{0,0}> 'b;")); String source2 = "class A<@Q T> {}\n" + "class B {}"; - assertEquals( - "find annotated type parameter", - 1, - findMatchesCount(source2, "class '_A<@Q '_T> {}") - ); + assertEquals("find annotated type parameter", 1, findMatchesCount(source2, "class '_A<@Q '_T> {}")); // @todo typed vars constrains (super), // @todo generic method invocation @@ -1590,322 +1001,122 @@ public class StructuralSearchTest extends StructuralSearchTestCase { } public void testSearchSubstitutions() { - // searching for parameterized pattern - assertEquals("search for parameterized pattern",findMatchesCount(s14_1,s15),2); + final String s15 = "'T;"; - assertEquals("search for parameterized pattern 2",findMatchesCount(s14_2,s15),5); + assertEquals("search for parameterized pattern", 2, findMatchesCount(s14_1, s15)); + assertEquals("search for parameterized pattern 2", 5, findMatchesCount(s14_2, s15)); options.setRecursiveSearch(false); - assertEquals("search for parameterized pattern-non-recursive",findMatchesCount(s14_1,s15),1); - - assertEquals("search for parameterized pattern 2-non-recursive",findMatchesCount(s14_2,s15),2); + assertEquals("search for parameterized pattern-non-recursive", 1, findMatchesCount(s14_1, s15)); + assertEquals("search for parameterized pattern 2-non-recursive", 2, findMatchesCount(s14_2, s15)); + final String s24_2 = "'T['_T2:.*i.* ]"; // typed vars with arrays - assertEquals("typed pattern with array 2-non-recursive",findMatchesCount(s23,s24_2),4); + assertEquals("typed pattern with array 2-non-recursive", 4, findMatchesCount(s23, s24_2)); options.setRecursiveSearch(true); - // searching for parameterized pattern - assertEquals("search for parameterized pattern 3",findMatchesCount(s14_2,s16),1); + assertEquals("search for parameterized pattern 3", 1, findMatchesCount(s14_2, "if('_T) { '_T2; }")); - // searching for parameterized pattern in complex expr (with field selection) - assertEquals("search for parameterized pattern in field selection",findMatchesCount(s17,s18_1),1); + assertEquals("search for parameterized pattern in field selection", 1, + findMatchesCount(s17, "'_T1.'_T2.equals('_T3.'_T2);")); - // searching for parameterized pattern in complex expr (with method call) - assertEquals("search for parameterized pattern with method call",findMatchesCount(s17,s18_2),1); + assertEquals("search for parameterized pattern with method call", 1, + findMatchesCount(s17, "'_T1.'_T2().equals('_T3.'_T2());")); - // searching for parameterized pattern in complex expr (with method call) - assertEquals("search for parameterized pattern with method call ep.2",findMatchesCount(s17,s18_3),4); + assertEquals("search for parameterized pattern with method call ep.2", 4, + findMatchesCount(s17, "'_T1.'_T2")); - // searching for parameterized pattern in definition with initializer - assertEquals("search for same var constraint",findMatchesCount(s19,s20),1); + assertEquals("search for same var constraint", 1, findMatchesCount(s19, "'_T1 'T2 = ('_T1)'_T3;")); - // searching for semi anonymous parameterized pattern in definition with initializer - assertEquals("search for same var constraint for semi anonymous typed vars",findMatchesCount(s19,s20_2),1); + assertEquals("search for same var constraint for semi anonymous typed vars", 1, + findMatchesCount(s19, "'_T1 '_T2 = ('_T1)'_T3;")); - // support for type var constraint - assertEquals("search for typed var constraint",findMatchesCount(s22,s21_1),1); + assertEquals("search for typed var constraint", 1, findMatchesCount(s22, "'_T1:Aa* 'T2 = ('_T1)'_T3;")); - // noncompatible same typed var constraints try { - findMatchesCount(s22,s21_2); - assertFalse("search for noncompatible typed var constraint",false); - } catch(MalformedPatternException e) { - } + findMatchesCount(s22, "'_T1:A* 'T2 = ( '_T1:A+ )'_T3;"); + fail("search for noncompatible typed var constraint"); + } catch(MalformedPatternException ignored) {} - // compatible same typed var constraints - assertEquals("search for same typed var constraint",findMatchesCount(s22,s21_3),1); - - // typed var with instanceof - assertEquals("typed instanceof",findMatchesCount(s65,s66),1); + assertEquals("search for same typed var constraint", 1, findMatchesCount(s22, "'_T1:Aa* 'T2 = ( '_T1 )'_T3;")); + assertEquals("typed instanceof", 1, findMatchesCount(s65, " '_T instanceof '_T2:B")); try { - // warn on incomplete instanceof findMatchesCount(s65, "'_T instanceof"); - fail(); + fail("warn on incomplete instanceof"); } catch (MalformedPatternException e) { assertEquals("Type expected", e.getMessage()); } - // typed vars with arrays - assertEquals("typed pattern with array",findMatchesCount(s23,s24_1),2); + assertEquals("typed pattern with array", 2, findMatchesCount(s23, "'T['_T2:.*i.* ] = '_T3;")); + assertEquals("typed pattern with array 2", 6, findMatchesCount(s23, s24_2)); + assertEquals("typed pattern in class name, method name, return type, parameter type and name", 1, + findMatchesCount(s25, "class 'T:.*Impl { '_T2 '_T3('_T4 '_T5) {\n\n} } ")); + assertEquals("finding interface", 1, findMatchesCount(s27, "interface 'T {}")); + assertEquals("anonymous typed vars", 1, findMatchesCount(s29, "class '_ { void '_('_:int '_); } ")); + assertEquals("finding class descendants", 2, findMatchesCount(s31, "class '_ extends B { } ")); + assertEquals("interface implementation", 2, findMatchesCount(s33, "class '_ implements B,C { } ")); + assertEquals("different order of fields and methods", 1, + findMatchesCount(s35, "class '_ { double '_; int '_; int '_() {} void '_() {} } ")); + assertEquals("different order in throws", 1, findMatchesCount(s37, "class 'T { '_ '_() throws D,C {} } ")); + assertEquals("match of class without extends to class with it", 2, findMatchesCount(s39, "class 'T { } ")); + assertEquals("match of class without extends to class with it, ep. 2", 2, + findMatchesCount(s41, "class '_ { '_T '_T2 = '_T3; } ")); + assertEquals("match of class without extends to class with it, ep 3", 4, + findMatchesCount(s41, "class '_ { '_T '_T2; } ")); + assertEquals("match class with fields without initializers", 2, + findMatchesCount(s41, "class '_ { '_T '_T2 = '_T3{0,0}; } ")); + assertEquals("typed reference element", 2, findMatchesCount(s51, "class '_ extends '_ { }")); + assertEquals("empty name for typed var", 1, findMatchesCount(s59, "interface '_ { void '_(); }")); - // typed vars with arrays - assertEquals("typed pattern with array 2",findMatchesCount(s23,s24_2),6); + final String s64 = " class 'T { public void '_T2:run () {} }"; + assertEquals("comparing method with constructor", 1, findMatchesCount(s63,s64)); + assertEquals("finding nested class", 2, findMatchesCount(s63_2,s64)); + assertEquals("find nested class by special pattern", 1, + findMatchesCount(s63_2, "class '_ { class 'T { public void '_T2:run () {} } }")); - // typed vars in class name, method name, its return type, parameter type and name - assertEquals("typed pattern in class name, method name, return type, parameter type and name",findMatchesCount(s25,s26),1); - - assertEquals( - "finding interface", - findMatchesCount(s27,s28), - 1 - ); - - // finding anonymous type vars - assertEquals( - "anonymous typed vars", - findMatchesCount(s29,s30), - 1 - ); - - // finding descedants - assertEquals( - "finding class descendants", - findMatchesCount(s31,s32), - 2 - ); - - // finding interface implementation - assertEquals( - "interface implementation", - findMatchesCount(s33,s34), - 2 - ); - - // different order of fields and methods - assertEquals( - "different order of fields and methods", - findMatchesCount(s35,s36), - 1 - ); - - // different order of exceptions in throws - assertEquals( - "differend order in throws", - findMatchesCount(s37,s38), - 1 - ); - - // class pattern without extends matches pattern with extends - assertEquals( - "match of class without extends to class with it", - findMatchesCount(s39,s40), - 2 - ); - - // class pattern without extends matches pattern with extends - assertEquals( - "match of class without extends to class with it, ep. 2", - findMatchesCount(s41,s42_1), - 2 - ); - - // class pattern without extends matches pattern with extends - assertEquals( - "match of class without extends to class with it, ep 3", - 4, - findMatchesCount(s41,s42_2) - ); - - assertEquals("match class with fields without initializers", 2, findMatchesCount(s41, "class '_ { '_T '_T2 = '_T3{0,0}; } ")); - - // typed reference element - assertEquals( - "typed reference element", - findMatchesCount(s51,s52), - 2 - ); - - // empty name of type var - assertEquals( - "empty name for typed var", - findMatchesCount(s59,s60), - 1 - ); - - // comparing method with constructor - assertEquals( - "comparing method with constructor", - findMatchesCount(s63,s64), - 1 - ); - - // comparing method with constructor - assertEquals( - "finding nested class", - findMatchesCount(s63_2,s64), - 2 - ); - - // comparing method with constructor - assertEquals( - "finded nested class by special pattern", - findMatchesCount(s63_2,s64_2), - 1 - ); - - assertEquals( - "* regexp for typed var", - findMatchesCount(s61,s62_1), - 5 - ); - - assertEquals( - "+ regexp for typed var", - findMatchesCount(s61,s62_2), - 4 - ); - - assertEquals( - "? regexp for typed var", - findMatchesCount(s61,s62_3), - 2 - ); - - assertEquals( - "cast in method parameters", - findMatchesCount(s67,s68), - 1 - ); - - assertEquals( - "searching for static field in static call", - 2, - findMatchesCount(s69,s70) - ); - - assertEquals( - "searching for static field in static call, 2", - 2, - findMatchesCount(s69,s70_2) - ); - - assertEquals( - "* regexp for anonymous typed var", - findMatchesCount(s61,s62_4), - 3 - ); - - assertEquals( - "+ regexp for anonymous typed var", - findMatchesCount(s61,s62_5), - 2 - ); - - assertEquals( - "? regexp for anonymous typed var", - findMatchesCount(s61,s62_6), - 2 - ); - - assertEquals( - "statement inside anonymous class", - findMatchesCount(s71,s72), - 3 - ); - - assertEquals( - "clever regexp match", - findMatchesCount(s91,s92), - 2 - ); - - assertEquals( - "clever regexp match 2", - findMatchesCount(s91,s92_2), - 2 - ); - - assertEquals( - "clever regexp match 3", - findMatchesCount(s91,s92_3), - 2 - ); + assertEquals("* regexp for typed var", 5, findMatchesCount(s61, "{ 'T*; }")); + assertEquals("+ regexp for typed var", 4, findMatchesCount(s61, "{ 'T+; }")); + assertEquals("? regexp for typed var", 2, findMatchesCount(s61, "{ 'T?; }")); + assertEquals("cast in method arguments", 1, findMatchesCount(s67, " (VirtualFile)'T")); + assertEquals("searching for static field in static call", 2, findMatchesCount(s69, " System.out ")); + assertEquals("searching for static field in static call, 2", 2, findMatchesCount(s69, " java.lang.System.out ")); + assertEquals("* regexp for anonymous typed var", 3, findMatchesCount(s61, "{ '_*; }")); + assertEquals("+ regexp for anonymous typed var", 2, findMatchesCount(s61, "{ '_+; }")); + assertEquals("? regexp for anonymous typed var", 2, findMatchesCount(s61, "{ '_?; }")); + assertEquals("statement inside anonymous class", 3, findMatchesCount(s71, " c(); ")); + assertEquals("clever regexp match", 2, findMatchesCount(s91, "'T:a")); + assertEquals("clever regexp match 2", 2, findMatchesCount(s91, "'T:b")); + assertEquals("clever regexp match 3", 2, findMatchesCount(s91, "'T:c")); } public void testSearchJavaDoc() { - // javadoc comment in class - assertEquals( - "java doc comment in class", - 1, - findMatchesCount(s57,s58) - ); + final String s58 = "/** @'T '_T2 */ class '_ { }"; + assertEquals("java doc comment in class", 1, findMatchesCount(s57,s58)); + assertEquals("java doc comment in class in file", 1, findMatchesCount(s57_2,s58,true)); - assertEquals( - "java doc comment in class in file", - 1, - findMatchesCount(s57_2,s58,true) - ); + assertEquals("javadoc comment for field", 2, findMatchesCount(s57, "class '_ { /** @serializable '_* */ '_ '_; }")); + assertEquals("javadoc comment for method", 2, findMatchesCount(s57, "class '_ { /** @'T 1.4 */ '_ '_() {} }")); + assertEquals("just javadoc comment search", 4, findMatchesCount(s57, "/** @'T '_T2 */")); - // javadoc comment for field - assertEquals( - "javadoc comment for field", - 2, - findMatchesCount(s57, s58_2) - ); + final String s84 = " /**\n" + + " * @hibernate.property\n" + + " * 'Property+\n" + + " */\n"; + assertEquals("XDoclet metadata", 2, findMatchesCount(s83,s84)); - // javadoc comment for method - assertEquals( - "javadoc comment for method", - 2, - findMatchesCount(s57, s58_3) - ); - - // just javadoc comment search - assertEquals( - "just javadoc comment search", - 4, - findMatchesCount(s57,s58_4) - ); - - assertEquals( - "XDoclet metadata", - 2, - findMatchesCount(s83,s84) - ); - - assertEquals( - "XDoclet metadata 2", - 1, - findMatchesCount(s83,s84_2) - ); - - assertEquals( - "optional tag value match", - 6, - findMatchesCount(s57, s58_5) - ); - - assertEquals( - "multiple tags match +", - 2, - findMatchesCount(s75,s76) - ); - - assertEquals( - "multiple tags match *", - 3, - findMatchesCount(s75, s76_2) - ); - - assertEquals( - "multiple tags match ?", - 3, - findMatchesCount(s75, s76_3) - ); + final String s84_2 = " /**\n" + + " * @hibernate.property\n" + + " * update=\"fa.se\"\n" + + " */\n"; + assertEquals("XDoclet metadata 2", 1, findMatchesCount(s83,s84_2)); + assertEquals("optional tag value match", 6, findMatchesCount(s57, "/** @'T '_T2? */")); + assertEquals("multiple tags match +", 2, findMatchesCount(s75, " /** @'_tag+ '_value+ */")); + assertEquals("multiple tags match *", 3, findMatchesCount(s75, " /** @'_tag* '_value* */")); + assertEquals("multiple tags match ?", 3, findMatchesCount(s75, " /** @'_tag? '_value? */ class 't {}")); assertEquals("no infinite loop on javadoc matching", 1, findMatchesCount(s57, "/** 'Text */ class '_ { }")); } @@ -1933,12 +1144,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " Object '_SpecialSerializationReadHandler?:readResolve () throws ObjectStreamException;" + " Object '_SpecialSerializationWriteHandler?:writeReplace () throws ObjectStreamException;" + "}"; - - assertEquals( - "serialization match", - findMatchesCount(s133,s134), - 2 - ); + assertEquals("serialization match", 2, findMatchesCount(s133,s134)); String s135 = "class SimpleStudentEventActionImpl extends Action { " + " public ActionForward execute(ActionMapping mapping,\n" + @@ -1955,12 +1161,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " HttpServletRequest '_,\n" + " HttpServletResponse '_);" + "}"; - - assertEquals( - "Struts actions", - findMatchesCount(s135,s136), - 2 - ); + assertEquals("Struts actions", 2, findMatchesCount(s135, s136)); final String s123 = "class NodeFilter {} public class MethodFilter extends NodeFilter {\n" + " private MethodFilter() {}\n" + @@ -1981,173 +1182,61 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " return '_Instance;\n" + " }\n" + "}"; - - assertEquals( - "singleton search", - findMatchesCount(s123,s124), - 1 - ); + assertEquals("singleton search", 1, findMatchesCount(s123,s124)); String s1111 = "if (true) { a=1; b=1; } else { a=1; }\n" + "if(true) { a=1; } else { a=1; b=1; }\n" + "if(true) { a=1; b=2; } else { a = 1; b=2; }"; - String s1112 = "if (true) { '_a{1,2}; } else { '_a; }"; - - assertEquals( - "same multiple name pattern", - findMatchesCount(s1111,s1112), - 1 - ); + assertEquals("same multiple name pattern", 1, findMatchesCount(s1111, "if (true) { '_a{1,2}; } else { '_a; }")); } public void testHierarchy() { final String s105 = "class B {} class A extends B { }"; - final String s106 = "class '_ extends '_:[ref('T)] {}"; - assertEquals( - "extends match", - findMatchesCount(s105,s106), - 1 - ); + assertEquals("extends match", 1, findMatchesCount(s105, "class '_ extends '_:[ref('T)] {}")); final String s107 = "interface IA {} interface IB extends IA { } interface IC extends IB {} interface ID extends IC {}" + "class A implements IA {} class B extends A { } class C extends B implements IC {} class D extends C {}"; - final String s108 = "class '_ extends 'Type:+A {}"; - final String s108_2 = "class '_ implements 'Type:+IA {}"; - - assertEquals( - "extends navigation match", - findMatchesCount(s107,s108), - 2 - ); - - assertEquals( - "implements navigation match", - 3, - findMatchesCount(s107,s108_2) - ); + assertEquals("extends navigation match", 2, findMatchesCount(s107, "class '_ extends 'Type:+A {}")); + assertEquals("implements navigation match", 3, findMatchesCount(s107, "class '_ implements 'Type:+IA {}")); final String s109 = "interface I {} interface I2 extends I {} class A implements I2 {} class B extends A { } class C extends B {} class D { void e() { C c; B b; A a;} }"; - final String s110 = "'_:*A '_;"; - final String s110_2 = "'_:*I '_;"; - final String s110_3 = "'_:*[regex( I ) && ref('T)] '_;"; - final String s110_4 = "'_:*[regex( I ) && ref2('T)] '_;"; - assertEquals( - "extends navigation match in definition", - findMatchesCount(s109,s110), - 3 - ); - - assertEquals( - "implements navigation match in definition 2", - findMatchesCount(s109,s110_2), - 3 - ); - - assertEquals( - "implements navigation match in definition 2 with nested conditions", - findMatchesCount(s109,s110_3), - 1 - ); - + assertEquals("extends navigation match in definition", 3, findMatchesCount(s109, "'_:*A '_;")); + assertEquals("implements navigation match in definition 2", 3, findMatchesCount(s109, "'_:*I '_;")); + assertEquals("implements navigation match in definition 2 with nested conditions", 1, + findMatchesCount(s109, "'_:*[regex( I ) && ref('T)] '_;")); try { - findMatchesCount(s109,s110_4); - assertFalse("implements navigation match in definition 2 with nested conditions - incorrect cond",false); - } catch(UnsupportedPatternException ex) {} + findMatchesCount(s109, "'_:*[regex( I ) && ref2('T)] '_;"); + fail("implements navigation match in definition 2 with nested conditions - incorrect cond"); + } catch(UnsupportedPatternException ignored) {} final String s111 = "interface E {} class A implements E {} class B extends A { int f = 0; } class C extends B {} class D { void e() { C c; B b; A a;} }"; final String s112 = "'_"; - assertEquals( - "symbol match", - findMatchesCount(s111,s112), - 17 - ); + assertEquals("symbol match", 17, findMatchesCount(s111,s112)); final String s113 = "class B {int c; void d() {} } int a; B b; a = 1; b.d(); ++a; int c=a; System.out.println(a); " + "b.c = 1; System.out.println(b.c); b.c++;"; - final String s114 = "'_:[read]"; - final String s114_2 = "'_:[write]"; - assertEquals( - "read symbol match", - findMatchesCount(s113,s114), - 11 - ); - - assertEquals( - "write symbol match", - findMatchesCount(s113,s114_2), - 5 - ); + assertEquals("read symbol match", 11, findMatchesCount(s113, "'_:[read]")); + assertEquals("write symbol match", 5, findMatchesCount(s113, "'_:[write]")); final String s115 = "class B {} public class C {}"; - final String s116 = "public class '_ {}"; - assertEquals( - "public modifier for class", - findMatchesCount(s115,s116), - 1 - ); + assertEquals("public modifier for class", 1, findMatchesCount(s115, "public class '_ {}")); final String s117 = "class A { int b; void c() { int e; b=1; this.b=1; e=5; " + "System.out.println(e); " + "System.out.println(b); System.out.println(this.b);} }"; - final String s118 = "this.'Field"; - final String s118_2 = "this.'Field:[read]"; - final String s118_3 = "this.'Field:[write]"; - - assertEquals( - "fields of class", - 4, - findMatchesCount(s117,s118) - ); - - assertEquals( - "fields of class read", - 2, - findMatchesCount(s117,s118_2) - ); - - assertEquals( - "fields of class written", - 2, - findMatchesCount(s117,s118_3) - ); + assertEquals("fields of class", 4, findMatchesCount(s117, "this.'Field")); + assertEquals("fields of class read", 2, findMatchesCount(s117, "this.'Field:[read]")); + assertEquals("fields of class written", 2, findMatchesCount(s117, "this.'Field:[write]")); final String s119 = "try { a.b(); } catch(IOException e) { c(); } catch(Exception ex) { d(); }"; - final String s120 = "try { '_; } catch('_ '_) { '_; }"; - final String s120_2 = "try { '_; } catch(Throwable '_) { '_; }"; - assertEquals( - "catches loose matching", - findMatchesCount(s119,s120), - 1 - ); - - assertEquals( - "catches loose matching 2", - findMatchesCount(s119,s120_2), - 0 - ); + assertEquals("catches loose matching", 1, findMatchesCount(s119, "try { '_; } catch('_ '_) { '_; }")); + assertEquals("catches loose matching 2", 0, findMatchesCount(s119, "try { '_; } catch(Throwable '_) { '_; }")); final String s121 = "class A { private int a; class Inner {} } " + "class B extends A { private int a; class Inner2 {} }"; - final String s122 = "class '_ { int '_:* ; }"; - final String s122_2 = "class '_ { int '_:+hashCode (); }"; - final String s122_3 = "class '_ { class '_:* {} }"; - assertEquals( - "hierarchical matching", - findMatchesCount(s121,s122), - 2 - ); - - assertEquals( - "hierarchical matching 2", - findMatchesCount(s121,s122_2), - 4 - ); - - assertEquals( - "hierarchical matching 3", - findMatchesCount(s121,s122_3), - 2 - ); + assertEquals("hierarchical matching", 2, findMatchesCount(s121, "class '_ { int '_:* ; }")); + assertEquals("hierarchical matching 2", 4, findMatchesCount(s121, "class '_ { int '_:+hashCode (); }")); + assertEquals("hierarchical matching 3", 2, findMatchesCount(s121, "class '_ { class '_:* {} }")); } public void testSearchInCommentsAndLiterals() { @@ -2157,89 +1246,31 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "// Some garbage\n"+ "/** And now third comment*/\n" + "/** Some garbage*/ }"; - String s2 = "// 'Comment:[regex( .*(?:comment).* )]"; - String s3 = "/** 'Comment:[regex( .*(?:comment).* )] */"; - String s2_2 = "/* 'Comment:[regex( .*(?:comment).* )] */"; - - assertEquals( - "Comment matching", - findMatchesCount(s1,s2), - 3 - ); - - assertEquals( - "Comment matching, 2", - 3, - findMatchesCount(s1,s2_2) - ); - - assertEquals( - "Java doc matching", - findMatchesCount(s1,s3), - 1 - ); + assertEquals("Comment matching", 3, findMatchesCount(s1, "// 'Comment:[regex( .*(?:comment).* )]")); + assertEquals("Comment matching, 2", 3, findMatchesCount(s1, "/* 'Comment:[regex( .*(?:comment).* )] */")); + assertEquals("Java doc matching", 1, findMatchesCount(s1, "/** 'Comment:[regex( .*(?:comment).* )] */")); String s4 = "\"'test\", \"another test\", \"garbage\""; - String s5 = "\"'test:[regex( .*test.* )]\""; - String s6 = "\"''test\""; - - assertEquals( - "Literal content", - findMatchesCount(s4,s5), - 2 - ); - - assertEquals( - "Literal content with escaping", - findMatchesCount(s4,s6), - 1 - ); + assertEquals("Literal content", 2, findMatchesCount(s4, "\"'test:[regex( .*test.* )]\"")); + assertEquals("Literal content with escaping", 1, findMatchesCount(s4, "\"''test\"")); String s7 = "\"aaa\""; - String s8 = "\"'test:[regex( aaa )]\""; - - assertEquals( - "Simple literal content", - findMatchesCount(s7,s8), - 1 - ); + assertEquals("Simple literal content", 1, findMatchesCount(s7, "\"'test:[regex( aaa )]\"")); String s9 = "\" aaa \" \" bbb \" \" ccc ccc aaa\""; - String s10 = "\"'test:[regexw( aaa|ccc )]\""; - String s11 = "\"'test:[regexw( bbb )]\""; - - assertEquals( - "Whole word literal content with alternations", - findMatchesCount(s9,s10), - 2 - ); - - assertEquals( - "Whole word literal content", - findMatchesCount(s9,s11), - 1 - ); + assertEquals("Whole word literal content with alternations", 2, + findMatchesCount(s9, "\"'test:[regexw( aaa|ccc )]\"")); + assertEquals("Whole word literal content", 1, findMatchesCount(s9, "\"'test:[regexw( bbb )]\"")); String s12 = "assert agentInfo != null : \"agentInfo is null\";\n" + "assert addresses != null : \"addresses is null\";"; - String s13 = "assert '_exp != null : \"'_exp is null\";"; - - assertEquals( - "reference to substitution in comment", - findMatchesCount(s12,s13), - 2 - ); + assertEquals("reference to substitution in comment", 2, + findMatchesCount(s12, "assert '_exp != null : \"'_exp is null\";")); String s14 = "\"(some text with special chars)\"," + "\" some\"," + "\"(some)\""; - String s15 = "\"('a:[regexw( some )])\""; - - assertEquals( - "meta char in literal", - 2, - findMatchesCount(s14,s15) - ); + assertEquals("meta char in literal", 2, findMatchesCount(s14, "\"('a:[regexw( some )])\"")); String s16 = "/**\n" + "* Created by IntelliJ IDEA.\n" + @@ -2259,11 +1290,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "*/\n" + "class 'c {\n" + "}"; - assertEquals( - "complete comment match", - 1, - findMatchesCount(s16,s17,true) - ); + assertEquals("complete comment match", 1, findMatchesCount(s16,s17,true)); String s18 = "public class A {\n" + " private void f(int i) {\n" + @@ -2275,117 +1302,28 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " '_s; // sss\n" + " }\n" + "}"; - assertEquals( - "statement match with comment", - 1, - findMatchesCount(s18,s19) - ); + assertEquals("statement match with comment", 1, findMatchesCount(s18,s19)); } public void testOther() { - assertEquals( - "optional init match in definition", - findMatchesCount(s73,s74), - 4 - ); - - assertEquals( - "null match", - findMatchesCount(s77,s78), - 0 - ); - - assertEquals( - "body of method by block search", - findMatchesCount(s79,s80), - 2 - ); - - - assertEquals( - "first matches, next not", - findMatchesCount(s95,s96), - 2 - ); + assertEquals("optional init match in definition", 4, findMatchesCount(s73, " '_Type 'Var = '_Init?; ")); + assertEquals("null match", 0, findMatchesCount(s77, " class 'T:.*aaa {} ")); + assertEquals("body of method by block search", 2, findMatchesCount(s79, " { '_T 'T3 = '_T2?; '_*; } ")); + assertEquals("first matches, next not", 2, findMatchesCount(s95, " class '_ {private int 'T+:field.* ;}")); final String s97 = "class A { int c; void b() { C d; } } class C { C() { A a; a.b(); a.c=1; } }"; - final String s98 = "'_.'_:[ref('T)] ()"; - final String s98_2 = "'_.'_:[ref('T)]"; - final String s98_3 = "'_:[ref('T)].'_ ();"; - final String s98_4 = "'_:[ref('T)] '_;"; - - assertEquals( - "method predicate match", - findMatchesCount(s97,s98), - 1 - ); - - assertEquals( - "field predicate match", - findMatchesCount(s97,s98_2), - 1 - ); - - assertEquals( - "dcl predicate match", - findMatchesCount(s97,s98_3), - 1 - ); + assertEquals("method predicate match", 1, findMatchesCount(s97, "'_.'_:[ref('T)] ()")); + assertEquals("field predicate match", 1, findMatchesCount(s97, "'_.'_:[ref('T)]")); + assertEquals("dcl predicate match", 1, findMatchesCount(s97, "'_:[ref('T)].'_ ();")); final String s99 = " char s = '\\u1111'; char s1 = '\\n'; "; - final String s100 = " char 'var = '\\u1111'; "; - final String s100_2 = " char 'var = '\\n'; "; - assertEquals( - "char constants in pattern", - findMatchesCount(s99,s100), - 1 - ); + assertEquals("char constants in pattern", 1, findMatchesCount(s99, " char 'var = '\\u1111'; ")); + assertEquals("char constants in pattern 2", 1, findMatchesCount(s99, " char 'var = '\\n'; ")); - assertEquals( - "char constants in pattern 2", - findMatchesCount(s99,s100_2), - 1 - ); - - assertEquals( - "class predicate match (from definition)", - findMatchesCount(s97,s98_4), - 3 - ); - - final String s125 = "a=1;"; - final String s126 = "'t:[regex(a)]"; - - try { - findMatchesCount(s125,s126); - assertFalse("spaces around reg exp check",false); - } catch(MalformedPatternException ex) {} + assertEquals("class predicate match (from definition)", 3, findMatchesCount(s97, "'_:[ref('T)] '_;")); final String s101 = "class A { void b() { String d; String e; String[] f; f.length=1; f.length=1; } }"; - final String s102 = "'_:[ref('T)] '_;"; - - assertEquals( - "distinct match", - findMatchesCount(s101,s102), - 1 - ); - - final String s103 = " a=1; "; - final String s104 = "'T:{ ;"; - try { - findMatchesCount(s103,s104); - assertFalse("incorrect reg exp",false); - } catch(MalformedPatternException ex) { - } - - final String s106 = "'_ReturnType 'MethodName('_ParameterType '_Parameter);"; - final String s105 = " aaa; "; - - try { - findMatchesCount(s105,s106); - assertFalse("incorrect reg exp 2",false); - } catch(UnsupportedPatternException ex) { - } + assertEquals("distinct match", 1, findMatchesCount(s101, "'_:[ref('T)] '_;")); String s107 = "class A {\n" + " /* */\n" + @@ -2401,48 +1339,32 @@ public class StructuralSearchTest extends StructuralSearchTestCase { String s108 = " /*" + " *" + " */"; - assertEquals("finding comments without typed var", 1, findMatchesCount(s107,s108)); String s109 = "class A { void b(); int b(int c); char d(char e); }\n" + "A a; a.b(1); a.b(2); a.b(); a.d('e'); a.d('f'); a.d('g');"; - String s110 = "'_a.'_b:[exprtype( int ) ]('_c*);"; - assertEquals("caring about method return type", 2, findMatchesCount(s109,s110)); + assertEquals("caring about method return type", 2, findMatchesCount(s109, "'_a.'_b:[exprtype( int ) ]('_c*);")); String s111 = "class A { void getManager() { getManager(); } };\n" + "class B { void getManager() { getManager(); getManager(); } };"; - String s112 = "'Instance?:[exprtype( B )].getManager()"; - assertEquals("caring about missing qualifier type", 2, findMatchesCount(s111,s112)); - - String s112a = "'Instance?:[regex( B )].getManager()"; - assertEquals("static query should not match instance method", 0, findMatchesCount(s111, s112a)); - - String s112b = "B.getManager()"; - assertEquals("static query should not match instance method 2", 0, findMatchesCount(s111, s112b)); + assertEquals("caring about missing qualifier type", 2, findMatchesCount(s111, "'Instance?:[exprtype( B )].getManager()")); + assertEquals("static query should not match instance method", 0, findMatchesCount(s111, "'Instance?:[regex( B )].getManager()")); + assertEquals("static query should not match instance method 2", 0, findMatchesCount(s111, "B.getManager()")); String s113 = "class A { static void a() { a(); }}\n" + "class B { static void a() { a(); a(); }}\n"; - String s114 = "'_Q?:[regex( B )].a()"; - assertEquals("should care about implicit class qualifier", 2, findMatchesCount(s113, s114)); - - String s114a = "B.a()"; - assertEquals("should match simple implicit class qualifier query", 2, findMatchesCount(s113, s114a)); - - String s114b = "'_Q?:[exprtype( B )].a()"; - assertEquals("instance query should not match static method", 0, findMatchesCount(s113, s114b)); + assertEquals("should care about implicit class qualifier", 2, findMatchesCount(s113, "'_Q?:[regex( B )].a()")); + assertEquals("should match simple implicit class qualifier query", 2, findMatchesCount(s113, "B.a()")); + assertEquals("instance query should not match static method", 0, findMatchesCount(s113, "'_Q?:[exprtype( B )].a()")); String s115 = "class A { int a; int f() { return a; }}\n" + "class B { int a; int g() { return a + a; }}\n"; - String s116 = "'_Instance?:[exprtype( B )].a"; - assertEquals("should care about implicit instance qualifier", 2, findMatchesCount(s115, s116)); - - String s116a = "A.a"; - assertEquals("should not match instance method", 0, findMatchesCount(s115, s116a)); + assertEquals("should care about implicit instance qualifier", 2, findMatchesCount(s115, "'_Instance?:[exprtype( B )].a")); + assertEquals("should not match instance method", 0, findMatchesCount(s115, "A.a")); String s117 = "class A { static int a; static int f() { return a; }}\n" + "class B { static int a; static int g() { return a + a; }}\n"; - String s118 = "'_Q?:[regex( B )].a"; - assertEquals("should care about implicit class qualifier for field", 2, findMatchesCount(s117, s118)); + assertEquals("should care about implicit class qualifier for field", 2, findMatchesCount(s117, "'_Q?:[regex( B )].a")); // b) hierarchy navigation support // c) or search support @@ -2467,48 +1389,49 @@ public class StructuralSearchTest extends StructuralSearchTestCase { public void testFQNInPatternAndVariableConstraints() { String s1 = "import java.awt.List;\n" + "class A { List l; }"; + String s2 = "class '_ { 'Type:java\\.util\\.List '_Field; }"; + assertEquals("No matches for qualified class", 0, findMatchesCount(s1, s2, true)); + String s1_2 = "import java.util.List;\n" + "class A { List l; }"; - String s2 = "class '_ { 'Type:java\\.util\\.List '_Field; }"; - - assertEquals("No matches for qualified class",findMatchesCount(s1,s2,true),0); - assertEquals("Matches for qualified class",findMatchesCount(s1_2,s2,true),1); + assertEquals("Matches for qualified class", 1, findMatchesCount(s1_2, s2, true)); String s3 = "import java.util.ArrayList;\n" + "class A { ArrayList l; }"; - String s4 = "class '_ { 'Type:*java\\.util\\.Collection '_Field; }"; - assertEquals("Matches for qualified class in hierarchy",findMatchesCount(s3,s4,true),1); + assertEquals("Matches for qualified class in hierarchy", 1, + findMatchesCount(s3, "class '_ { 'Type:*java\\.util\\.Collection '_Field; }", true)); String s5 = "import java.util.List;\n" + "class A { { List l = new List(); l.add(\"1\"); } }"; + assertEquals("Matches for qualified expr type in hierarchy", 2, + findMatchesCount(s5, "'a:[exprtype( *java\\.util\\.Collection )]", true)); + + String s6 = "'a:[exprtype( java\\.util\\.List )]"; + assertEquals("Matches for qualified expr type", 2, findMatchesCount(s5, s6, true)); + String s5_2 = "import java.awt.List;\n" + "class A { { List l = new List(); l.add(\"1\"); } }"; - String s6 = "'a:[exprtype( java\\.util\\.List )]"; - String s6_2 = "'a:[exprtype( *java\\.util\\.Collection )]"; + assertEquals("No matches for qualified expr type", 0, findMatchesCount(s5_2, s6, true)); + String s6_3 = "java.util.List '_a = '_b?;"; - - assertEquals("Matches for qualified expr type",findMatchesCount(s5,s6,true), 2); - assertEquals("No matches for qualified expr type",findMatchesCount(s5_2,s6,true),0); - assertEquals("Matches for qualified expr type in hierarchy",findMatchesCount(s5,s6_2,true), 2); - - assertEquals("Matches for qualified var type in pattern",findMatchesCount(s5,s6_3,true),1); - assertEquals("No matches for qualified var type in pattern",findMatchesCount(s5_2,s6_3,true),0); + assertEquals("Matches for qualified var type in pattern", 1, findMatchesCount(s5, s6_3, true)); + assertEquals("No matches for qualified var type in pattern", 0, findMatchesCount(s5_2, s6_3, true)); String s7 = "import java.util.List;\n" + "class A extends List { }"; - String s7_2 = "import java.awt.List;\n" + - "class A extends List {}"; String s8 = "class 'a extends java.util.List {}"; + assertEquals("Matches for qualified type in pattern", 1, findMatchesCount(s7, s8, true)); - assertEquals("Matches for qualified type in pattern",findMatchesCount(s7,s8,true),1); - assertEquals("No matches for qualified type in pattern",findMatchesCount(s7_2,s8,true),0); + String s7_2 = "import java.awt.List;\n" + + "class A extends List {}"; + assertEquals("No matches for qualified type in pattern", 0, findMatchesCount(s7_2, s8, true)); String s9 = "String.intern(\"1\");\n" + "java.util.Collections.sort(null);" + "java.util.Collections.sort(null);"; - String s10 = "java.lang.String.'_method ( '_params* )"; - assertEquals("FQN in class name",1,findMatchesCount(s9,s10,false)); + assertEquals("FQN in class name",1, + findMatchesCount(s9, "java.lang.String.'_method ( '_params* )", false)); } public void testAnnotations() throws Exception { @@ -2564,29 +1487,28 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " @'_Annotation+ ( 'AnnotationMember*:name = '_AnnotationValue* )\n" + " String '_field* ;\n" + "}"; + assertEquals("Find annotation members of annotated field class",4,findMatchesCount(s3,s4,false)); + String s4_2 = "class '_a {\n" + " @'_Annotation+ ()\n" + " String 'field* ;\n" + "}"; - - assertEquals("Find annotation members of annotated field class",4,findMatchesCount(s3,s4,false)); assertEquals("Find annotation fields",3,findMatchesCount(s3,s4_2,false)); String s5 = "class A {" + " @NotNull private static Collection resolveElements(final PsiReference reference, final Project project) {}\n" + " @NotNull private static Collection resolveElements2(final PsiReference reference, final Project project) {}\n" + "}"; - String s6 = "class '_c {@NotNull '_rt 'method* ('_pt* '_p*){ '_inst*; } }"; - String s6_2 = "class '_c {@'_:NotNull '_rt 'method* ('_pt* '_p*){ '_inst*; } }"; - assertEquals("Find annotated methods",2,findMatchesCount(s5,s6)); - assertEquals("Find annotated methods, 2",2,findMatchesCount(s5,s6_2)); + assertEquals("Find annotated methods",2, + findMatchesCount(s5, "class '_c {@NotNull '_rt 'method* ('_pt* '_p*){ '_inst*; } }")); + assertEquals("Find annotated methods, 2",2, + findMatchesCount(s5, "class '_c {@'_:NotNull '_rt 'method* ('_pt* '_p*){ '_inst*; } }")); String s7 = "class A { void message(@NonNls String msg); }\n" + "class B { void message2(String msg); }\n" + "class C { void message2(String msg); }"; - String s8 = "class '_A { void 'b( @'_Ann{0,0}:NonNls String '_); }"; - assertEquals("Find not annotated methods",2,findMatchesCount(s7,s8)); + assertEquals("Find not annotated methods",2,findMatchesCount(s7, "class '_A { void 'b( @'_Ann{0,0}:NonNls String '_); }")); String s9 = "class A {\n" + " Object[] method1() {}\n" + @@ -2596,12 +1518,12 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " @MyAnnotation Object[] method2(int a) {}\n" + " @NonNls Object[] method3() {}\n" + "}"; - String s10 = "class '_A { @'_Ann{0,0}:NonNls '_Type:Object\\[\\] 'b+( '_pt* '_p* ); }"; - String s10_2 = "class '_A { @'_Ann{0,0}:NonNls '_Type [] 'b+( '_pt* '_p* ); }"; - String s10_3 = "class '_A { @'_Ann{0,0}:NonNls '_Type:Object [] 'b+( '_pt* '_p* ); }"; - assertEquals("Find not annotated methods, 2",2,findMatchesCount(s9,s10)); - assertEquals("Find not annotated methods, 2",2,findMatchesCount(s9,s10_2)); - assertEquals("Find not annotated methods, 2",2,findMatchesCount(s9,s10_3)); + assertEquals("Find not annotated methods, 2",2, + findMatchesCount(s9, "class '_A { @'_Ann{0,0}:NonNls '_Type:Object\\[\\] 'b+( '_pt* '_p* ); }")); + assertEquals("Find not annotated methods, 2",2, + findMatchesCount(s9, "class '_A { @'_Ann{0,0}:NonNls '_Type [] 'b+( '_pt* '_p* ); }")); + assertEquals("Find not annotated methods, 2",2, + findMatchesCount(s9, "class '_A { @'_Ann{0,0}:NonNls '_Type:Object [] 'b+( '_pt* '_p* ); }")); String s11 = "class A {\n" + "@Foo(value=baz) int a;\n" + @@ -2612,21 +1534,13 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "@Foo(value2=baz3) int a3;\n" + "@Foo(value2=baz4) int a3;\n" + "}"; - String s12 = "@Foo(value=baz) int 'a;)"; - String s12_2 = "@Foo(value='baz:baz2 ) int '_a;)"; - String s12_3 = "@Foo('value:value2 = baz3 ) int '_a;)"; - String s12_4 = "@Foo('value:value2 = '_baz3:baz3 ) int '_a;)"; - String s12_5 = "@Foo('value:value2 = '_baz3:baz ) int '_a;)"; - String s12_6 = "@Foo('value:value2 = '_baz3 ) int '_a;)"; - String s12_7 = "@Foo('value:value2 = ) int '_a;"; - - assertEquals("Find anno parameter value",1,findMatchesCount(s11,s12)); - assertEquals("Find anno parameter value",2,findMatchesCount(s11,s12_2)); - assertEquals("Find anno parameter value",3,findMatchesCount(s11,s12_3)); - assertEquals("Find anno parameter value",3,findMatchesCount(s11,s12_4)); - assertEquals("Find anno parameter value",0,findMatchesCount(s11,s12_5)); - assertEquals("Find anno parameter value",4,findMatchesCount(s11,s12_6)); - assertEquals("Find anno parameter value",4,findMatchesCount(s11,s12_7)); + assertEquals("Find anno parameter value",1,findMatchesCount(s11, "@Foo(value=baz) int 'a;)")); + assertEquals("Find anno parameter value",2,findMatchesCount(s11, "@Foo(value='baz:baz2 ) int '_a;)")); + assertEquals("Find anno parameter value",3,findMatchesCount(s11, "@Foo('value:value2 = baz3 ) int '_a;)")); + assertEquals("Find anno parameter value",3,findMatchesCount(s11, "@Foo('value:value2 = '_baz3:baz3 ) int '_a;)")); + assertEquals("Find anno parameter value",0,findMatchesCount(s11, "@Foo('value:value2 = '_baz3:baz ) int '_a;)")); + assertEquals("Find anno parameter value",4,findMatchesCount(s11, "@Foo('value:value2 = '_baz3 ) int '_a;)")); + assertEquals("Find anno parameter value",4,findMatchesCount(s11, "@Foo('value:value2 = ) int '_a;")); String source1 = "class A {" + " void m() {" + @@ -2686,17 +1600,13 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "a.c(3);\n" + "Integer i = 4;\n" + "int j = Integer.valueOf(4);\n"; - String s2 = "a.'b('_Params:[formal( Integer ) && exprtype( int ) ])"; - String s2_2 = "a.c('_Params:[formal( int ) && exprtype( Integer ) ])"; - assertEquals("Find boxing in method call",1,findMatchesCount(s1,s2,false)); - assertEquals("Find unboxing in method call",2,findMatchesCount(s1,s2_2,false)); - - String pattern1 = "'_a:[formal( Integer ) && exprtype( int ) ]"; - assertEquals("Find any boxing", 2, findMatchesCount(s1, pattern1)); - - String pattern2 = "'_a:[formal( int ) && exprtype( Integer ) ]"; - assertEquals("Find any unboxing", 3, findMatchesCount(s1, pattern2)); + assertEquals("Find boxing in method call",1, + findMatchesCount(s1, "a.'b('_Params:[formal( Integer ) && exprtype( int ) ])", false)); + assertEquals("Find unboxing in method call",2, + findMatchesCount(s1, "a.c('_Params:[formal( int ) && exprtype( Integer ) ])", false)); + assertEquals("Find any boxing", 2, findMatchesCount(s1, "'_a:[formal( Integer ) && exprtype( int ) ]")); + assertEquals("Find any unboxing", 3, findMatchesCount(s1, "'_a:[formal( int ) && exprtype( Integer ) ]")); } public void testCommentsInDclSearch() { @@ -2705,6 +1615,8 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " char b;\n" + " int c; // comment2\n" + "}"; + assertEquals("Find field by dcl with comment",2,findMatchesCount(s1, "'_Type '_Variable = '_Value?; //'Comment")); + String s1_2 = "class A {\n" + " // comment\n" + " int a;\n" + @@ -2712,17 +1624,12 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " // comment2\n" + " int c;\n" + "}"; - - String s2 = "'_Type '_Variable = '_Value?; //'Comment"; String s2_2 = "//'Comment\n" + "'_Type '_Variable = '_Value?;"; - - assertEquals("Find field by dcl with comment",2,findMatchesCount(s1,s2)); assertEquals("Find field by dcl with comment 2",2,findMatchesCount(s1_2,s2_2)); } public void testSearchingEmptyModifiers() { - String s1 = "class A {\n" + " int a;\n" + " private char b;\n" + @@ -2730,38 +1637,32 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " public int c;\n" + " public int c2;\n" + "}"; - String s2 = "@Modifier(\"packageLocal\") '_Type '_Variable = '_Value?;"; - String s2_2 = "@Modifier({\"packageLocal\",\"private\"}) '_Type '_Variable = '_Value?;"; - String s2_3 = "@Modifier({\"PackageLocal\",\"private\"}) '_Type '_Variable = '_Value?;"; - - assertEquals("Finding package-private dcls",1,findMatchesCount(s1,s2)); - assertEquals("Finding package-private dcls",3,findMatchesCount(s1,s2_2)); - + assertEquals("Finding package-private dcls",1, + findMatchesCount(s1, "@Modifier(\"packageLocal\") '_Type '_Variable = '_Value?;")); + assertEquals("Finding package-private dcls",3, + findMatchesCount(s1, "@Modifier({\"packageLocal\",\"private\"}) '_Type '_Variable = '_Value?;")); try { - findMatchesCount(s1,s2_3); - assertTrue("Finding package-private dcls",false); - } catch(MalformedPatternException ex) { - - } + findMatchesCount(s1, "@Modifier({\"PackageLocal\",\"private\"}) '_Type '_Variable = '_Value?;"); + fail("Finding package-private dcls"); + } catch(MalformedPatternException ignored) {} String s3 = "class A {\n" + " int a;\n" + " static char b;\n" + " static char b2;\n" + "}"; - String s4 = "@Modifier(\"Instance\") '_Type '_Variable = '_Value?;"; - String s4_2 = "@Modifier({\"static\",\"Instance\"}) '_Type '_Variable = '_Value?;"; - assertEquals("Finding instance fields",1,findMatchesCount(s3,s4)); - assertEquals("Finding all fields",3,findMatchesCount(s3,s4_2)); + assertEquals("Finding instance fields",1, + findMatchesCount(s3, "@Modifier(\"Instance\") '_Type '_Variable = '_Value?;")); + assertEquals("Finding all fields",3, + findMatchesCount(s3, "@Modifier({\"static\",\"Instance\"}) '_Type '_Variable = '_Value?;")); String s5 = "class A {}\n" + "abstract class B {}\n" + "final class C {}\n" + "class D {}"; - String s6 = "@Modifier(\"Instance\") class 'Type {}"; - String s6_2 = "@Modifier({\"abstract\",\"final\",\"Instance\"}) class 'Type {}"; - assertEquals("Finding instance classes",3,findMatchesCount(s5,s6)); - assertEquals("Finding all classes",4,findMatchesCount(s5,s6_2)); + assertEquals("Finding instance classes",3,findMatchesCount(s5, "@Modifier(\"Instance\") class 'Type {}")); + assertEquals("Finding all classes",4, + findMatchesCount(s5, "@Modifier({\"abstract\",\"final\",\"Instance\"}) class 'Type {}")); } public void testSearchTransientFieldsWithModifier() { @@ -2771,10 +1672,8 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " transient String field2;\n" + " String field3;\n" + "}"; - - String template = "transient @Modifier(\"packageLocal\") '_Type '_Variable = '_Value?;"; - - assertEquals("Finding package-private transient fields", 1, findMatchesCount(source, template)); + assertEquals("Finding package-private transient fields", 1, + findMatchesCount(source, "transient @Modifier(\"packageLocal\") '_Type '_Variable = '_Value?;")); } public void test() { @@ -2799,8 +1698,8 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "B2.foo(1);\n" + "B3.foo(2,3);\n" + "C.foo();"; - String s2 = "'_Instance:[regex( *A )].'_Method:[regex( foo )] ( '_Params* )"; - assertEquals("Find static methods within expr type hierarchy", 3, findMatchesCount(s1,s2)); + assertEquals("Find static methods within expr type hierarchy", 3, + findMatchesCount(s1, "'_Instance:[regex( *A )].'_Method:[regex( foo )] ( '_Params* )")); } public void testFindClassesWithinHierarchy() { @@ -2810,10 +1709,10 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "class B2 implements I { }\n" + "class B3 extends A { }\n" + "class C extends B2 { static void foo(); }\n"; - String s2 = "class '_ extends '_Extends:[!regex( *A )] implements '_Implements:[regex( I )] {}"; - String s2_2 = "class '_ extends '_Extends:[!regex( *A )]{}"; - assertEquals("Find class within type hierarchy with not", 1, findMatchesCount(s1,s2)); - assertEquals("Find class within type hierarchy with not, 2", 1, findMatchesCount(s1,s2_2)); + assertEquals("Find class within type hierarchy with not", 1, + findMatchesCount(s1, "class '_ extends '_Extends:[!regex( *A )] implements '_Implements:[regex( I )] {}")); + assertEquals("Find class within type hierarchy with not, 2", 1, + findMatchesCount(s1, "class '_ extends '_Extends:[!regex( *A )]{}")); } public void testFindTryWithoutProperFinally() { @@ -2857,14 +1756,13 @@ public class StructuralSearchTest extends StructuralSearchTestCase { // assertEquals( 3, findMatchesCount(s1,s2)); //} + @SuppressWarnings("unused") public void _testStaticInstanceInitializers() { String s1 = "public class DiallingNumber {\n static { int a = 1; } static { int b = 1; } { int c = 2; }}"; - String s2 = "class '_Class {\n" + " static { 't*; } }"; - String s2_2 = "class '_Class {\n" + " { 't*; } }"; - String s2_3 = "class '_Class {\n" + " @Modifier(\"Instance\") { 't*; } }"; - assertEquals("Static / instance initializers", 2, findMatchesCount(s1,s2)); - assertEquals("Static / instance initializers", 1, findMatchesCount(s1,s2_3)); - assertEquals("Static / instance initializers", 3, findMatchesCount(s1,s2_2)); + assertEquals("Static / instance initializers", 2, findMatchesCount(s1, "class '_Class { static { 't*; } }")); + assertEquals("Static / instance initializers", 1, + findMatchesCount(s1, "class '_Class { @Modifier(\"Instance\") { 't*; } }")); + assertEquals("Static / instance initializers", 3, findMatchesCount(s1, "class '_Class { { 't*; } }")); } @NotNull @@ -2889,11 +1787,11 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " try { int b = 1; } catch(Type t) { a = 2; } catch(Type2 t2) { a = 3; }\n" + " }\n" + "}"; - String s2 = "try { '_st*; } catch('_Type 't+) { '_st2*; }"; final List vars = new ArrayList<>(); - final PsiFile file = PsiFileFactory.getInstance(getProject()).createFileFromText("_.java", s1); + @SuppressWarnings("deprecation") final PsiFile file = PsiFileFactory.getInstance(getProject()).createFileFromText("_.java", s1); + //noinspection AnonymousInnerClassMayBeStatic file.acceptChildren(new JavaRecursiveElementWalkingVisitor() { @Override public void visitVariable(final PsiVariable variable) { super.visitVariable(variable); @@ -2902,14 +1800,14 @@ public class StructuralSearchTest extends StructuralSearchTestCase { }); assertEquals(7, vars.size()); - List results = new ArrayList<>(); Matcher testMatcher = new Matcher(getProject()); MatchOptions options = new MatchOptions(); - options.setSearchPattern(s2); + options.setSearchPattern("try { '_st*; } catch('_Type 't+) { '_st2*; }"); MatcherImplUtil.transform(options); options.setFileType(StdFileTypes.JAVA); + List results = new ArrayList<>(); for(PsiVariable var:vars) { final List matchResult = testMatcher.matchByDownUp(var, options); results.addAll(matchResult); @@ -2925,10 +1823,9 @@ public class StructuralSearchTest extends StructuralSearchTestCase { assertEquals("t2", result.getMatchImage()); results.clear(); - String s2_2 = "try { '_st*; } catch('Type:Type2 '_t) { '_st2*; }"; options.clearVariableConstraints(); - options.setSearchPattern(s2_2); + options.setSearchPattern("try { '_st*; } catch('Type:Type2 '_t) { '_st2*; }"); MatcherImplUtil.transform(options); for(PsiVariable var:vars) { @@ -2945,6 +1842,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { assertEquals("Type2", result.getMatchImage()); } + @SuppressWarnings("unused") public void _testContainsPredicate() { String s1 = "{{\n" + " int a;\n" + @@ -2958,16 +1856,8 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " int c = 2;\n" + " c = 2;\n" + "}}"; - String s2 = "{\n" + - " '_a*:[contains( \"'type '_a = '_b;\" )];\n" + - "}"; - - String s2_2 = "{\n" + - " '_a*:[!contains( \"'_type '_a = '_b;\" )];\n" + - "}"; - - assertEquals(2, findMatchesCount(s1, s2)); - assertEquals(1, findMatchesCount(s1, s2_2)); + assertEquals(2, findMatchesCount(s1, "{ '_a*:[contains( \"'type '_a = '_b;\" )]; }")); + assertEquals(1, findMatchesCount(s1, "{ '_a*:[!contains( \"'_type '_a = '_b;\" )]; }")); } public void testWithinPredicate() { @@ -2981,9 +1871,9 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " int c = 2;\n" + "}"; String s2 = "[within( \"if ('_a) { '_st*; }\" )]'_type 'a = '_b;"; - String s2_2 = "[!within( \"if ('_a) { '_st*; }\" )]'_type 'a = '_b;"; - assertEquals(2,findMatchesCount(s1, s2)); + + String s2_2 = "[!within( \"if ('_a) { '_st*; }\" )]'_type 'a = '_b;"; assertEquals(1,findMatchesCount(s1, s2_2)); String s3 = "if (true) {\n" + @@ -3027,15 +1917,14 @@ public class StructuralSearchTest extends StructuralSearchTestCase { public void testMultiStatementPatternWithTypedVariable() throws Exception { String s = "Integer i;\ni.valueOf();"; + assertEquals(1, findMatchesCount(s, "Integer '_i;\n'_i.valueOf();")); + String s_2 = "Integer i;\nint a = 1;\ni.valueOf();"; - String s2 = "Integer '_i;\n'_i.valueOf();"; - String s2_2 = "Integer '_i;\n'_st; '_i.valueOf();"; + assertEquals(1, findMatchesCount(s_2, "Integer '_i;\n'_st; '_i.valueOf();")); + String s2_3 = "Integer '_i;\n'_st*; '_i.valueOf();"; - - assertEquals(1, findMatchesCount(s,s2)); - assertEquals(1, findMatchesCount(s_2,s2_2)); - assertEquals(1, findMatchesCount(s_2,s2_3)); - assertEquals(1, findMatchesCount(s,s2_3)); + assertEquals(1, findMatchesCount(s_2, s2_3)); + assertEquals(1, findMatchesCount(s, s2_3)); } public void testFindAnnotationDeclarations() throws Exception { @@ -3236,27 +2125,25 @@ public class StructuralSearchTest extends StructuralSearchTestCase { public void testNoUnexpectedException() { String source = "{}"; - String pattern1 = "/*$A$a*/"; MalformedPatternException ex = null; try { - findMatchesCount(source, pattern1); + findMatchesCount(source, "/*$A$a*/"); } catch (MalformedPatternException e) { ex = e; } assertNotNull(ex); - String pattern2 = "class $A$Visitor {}"; try { - findMatchesCount(source, pattern2); + findMatchesCount(source, "class $A$Visitor {}"); } catch (MalformedPatternException e) { ex = e; } assertNotNull(ex); - String pattern3 = "class $Class$ { \n" + - " class $n$$FieldType$ $FieldName$ = $Init$;\n" + - "}"; try { + String pattern3 = "class $Class$ { \n" + + " class $n$$FieldType$ $FieldName$ = $Init$;\n" + + "}"; findMatchesCount(source, pattern3); } catch (MalformedPatternException e) { ex = e; @@ -3502,5 +2389,13 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "}"; assertEquals("find super call", 1, findMatchesCount(source, "super.'_m()")); assertEquals("find super and non super call", 2, findMatchesCount(source, "'_q:[regex( super|this )].'_m()")); + + String source2 = "class A {" + + " public boolean equals(Object o) {" + + " return super.equals(o);" + + " }" + + "}"; + assertEquals("find method with super call and matching parameter", 1, + findMatchesCount(source2, "'_rt '_m('_t '_p*) { return super.'_m('_p); }")); } } diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/impl/matcher/compiler/StringToConstraintsTransformerTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/impl/matcher/compiler/StringToConstraintsTransformerTest.java index bfdadf49a45e..472db4c9cbcf 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/impl/matcher/compiler/StringToConstraintsTransformerTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/impl/matcher/compiler/StringToConstraintsTransformerTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2016 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.structuralsearch.impl.matcher.compiler; import com.intellij.structuralsearch.MalformedPatternException; @@ -239,6 +254,18 @@ public class StringToConstraintsTransformerTest { test("'a:[regex( .* ) ]"); } + @Test(expected = MalformedPatternException.class) + public void testInvalidRegex() { + test("'T:{ ;"); + } + + @Test + public void testNoSpacesSurroundingRegexNeeded() { + test("'t:[regex(a)]"); + final MatchVariableConstraint constraint = myOptions.getVariableConstraint("t"); + assertEquals("a", constraint.getRegExp()); + } + private void test(String pattern) { myOptions.setSearchPattern(pattern); StringToConstraintsTransformer.transformOldPattern(myOptions); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MisorderedAssertEqualsArgumentsInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MisorderedAssertEqualsArgumentsInspectionBase.java index 51f1adcb282b..1d107013907b 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MisorderedAssertEqualsArgumentsInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MisorderedAssertEqualsArgumentsInspectionBase.java @@ -25,7 +25,10 @@ import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; -import com.siyeh.ig.psiutils.*; +import com.siyeh.ig.psiutils.DeclarationSearchUtils; +import com.siyeh.ig.psiutils.ExpressionUtils; +import com.siyeh.ig.psiutils.LibraryUtil; +import com.siyeh.ig.psiutils.ParenthesesUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -61,7 +64,7 @@ public abstract class MisorderedAssertEqualsArgumentsInspectionBase extends Base return new FlipArgumentsFix(); } - private static class FlipArgumentsFix extends InspectionGadgetsFix { + private class FlipArgumentsFix extends InspectionGadgetsFix { @Override @NotNull @@ -85,7 +88,7 @@ public abstract class MisorderedAssertEqualsArgumentsInspectionBase extends Base if (method == null) { return; } - final ExpectedActual expectedActual = ExpectedActual.create(method, callExpression.getArgumentList().getExpressions(), true); + final ExpectedActual expectedActual = ExpectedActual.create(method, callExpression.getArgumentList().getExpressions(), checkTestNG()); if (expectedActual == null) { return; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/naming/LambdaUnfriendlyMethodOverloadInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/naming/LambdaUnfriendlyMethodOverloadInspectionBase.java index 837b802cd900..3b4cdb87a0b4 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/naming/LambdaUnfriendlyMethodOverloadInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/naming/LambdaUnfriendlyMethodOverloadInspectionBase.java @@ -15,7 +15,6 @@ */ package com.siyeh.ig.naming; -import com.intellij.openapi.util.Key; import com.intellij.psi.*; import com.intellij.psi.util.PsiSuperMethodUtil; import com.intellij.psi.util.TypeConversionUtil; @@ -54,14 +53,9 @@ public class LambdaUnfriendlyMethodOverloadInspectionBase extends BaseInspection private static class LambdaUnfriendlyMethodOverloadVisitor extends BaseInspectionVisitor { - private static final Key SKIP_MARKER = new Key<>("skip marker for lambda unfriendly method overload inspection"); - @Override public void visitMethod(PsiMethod method) { super.visitMethod(method); - if (method.getUserData(SKIP_MARKER) == Boolean.TRUE) { - return; - } final PsiParameterList parameterList = method.getParameterList(); final int parametersCount = parameterList.getParametersCount(); if (parametersCount == 0) { @@ -84,7 +78,6 @@ public class LambdaUnfriendlyMethodOverloadInspectionBase extends BaseInspection return; } final String name = method.getName(); - boolean problemFound = false; for (PsiMethod sameNameMethod : containingClass.findMethodsByName(name, true)) { if (method.equals(sameNameMethod) || PsiSuperMethodUtil.isSuperMethod(method, sameNameMethod)) { continue; @@ -103,16 +96,10 @@ public class LambdaUnfriendlyMethodOverloadInspectionBase extends BaseInspection } if (areSameShapeFunctionalTypes(functionalType, otherFunctionalType)) { - problemFound = true; - if (containingClass.equals(sameNameMethod.getContainingClass())) { - registerMethodError(sameNameMethod, sameNameMethod); - sameNameMethod.putUserData(SKIP_MARKER, Boolean.TRUE); - } + registerMethodError(method, method); + return; } } - if (problemFound) { - registerMethodError(method, method); - } } private static boolean areSameShapeFunctionalTypes(PsiType one, PsiType two) { diff --git a/plugins/terminal/resources/META-INF/terminal.xml b/plugins/terminal/resources/META-INF/terminal.xml index 0906025d4809..165952ce6e92 100644 --- a/plugins/terminal/resources/META-INF/terminal.xml +++ b/plugins/terminal/resources/META-INF/terminal.xml @@ -10,6 +10,7 @@ + diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalOptionsConfigurable.java b/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalOptionsConfigurable.java index f699ce8166cf..db7846fa7c60 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalOptionsConfigurable.java +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalOptionsConfigurable.java @@ -61,7 +61,6 @@ public class TerminalOptionsConfigurable implements SearchableConfigurable, Conf @Override public JComponent createComponent() { myPanel = new TerminalSettingsPanel(); - if (myProjectOptionsProvider == null) return new JPanel(); return myPanel.createPanel(myOptionsProvider, myProjectOptionsProvider); } diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalProjectOptionsProvider.java b/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalProjectOptionsProvider.java index 6b9443620269..349b99ee2b7c 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalProjectOptionsProvider.java +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/TerminalProjectOptionsProvider.java @@ -33,7 +33,7 @@ import java.io.File; * @author traff */ @State( - name = "TerminalOptionsProvider", + name = "TerminalProjectOptionsProvider", storages = @Storage("terminal.xml") ) public class TerminalProjectOptionsProvider implements PersistentStateComponent { @@ -42,7 +42,7 @@ public class TerminalProjectOptionsProvider implements PersistentStateComponent< private State myState = new State(); private final Project myProject; - public TerminalProjectOptionsProvider(Project project) {myProject = project;} + public TerminalProjectOptionsProvider(@NotNull Project project) {myProject = project;} public static TerminalProjectOptionsProvider getInstance(@NotNull Project project) { diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 005b554bb44e..0c9f0fed5b34 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -46,7 +46,8 @@ - com.intellij.openapi.vfs.impl.jrt.JrtFileSystem + com.intellij.openapi.vfs.jrt.JrtFileSystem + com.intellij.openapi.vfs.impl.jrt.JrtFileSystemImpl com.intellij.util.xml.impl.JavaDomApplicationComponent