diff --git a/build/scripts/dist.gant b/build/scripts/dist.gant index 3a7d54ca6c43..3d6b4f5e7502 100644 --- a/build/scripts/dist.gant +++ b/build/scripts/dist.gant @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -29,6 +29,8 @@ class Paths { final artifacts final artifacts_core final artifacts_jps + final ideaSystem + final ideaConfig def Paths(String out) { sandbox = out @@ -39,6 +41,8 @@ class Paths { artifacts = "$sandbox/artifacts" artifacts_core = "$artifacts/core" artifacts_jps = "$artifacts/jps" + ideaSystem = "$sandbox/system" + ideaConfig = "$sandbox/config" } } @@ -75,6 +79,8 @@ target('default': 'The default target') { zipSources(home, paths.artifacts) + indexSearchableOptions() + layoutAll([buildNumber: "IC-$snapshot", system_selector: "IdeaIC${p("component.version.major")}", tools_jar: true], @@ -83,15 +89,28 @@ target('default': 'The default target') { target('build-dist-jars' : 'Target to build jars from locally compiled classes') { loadProject() + // load ApplicationInfo.xml properties ant.xmlproperty(file: appInfoFile(), collapseAttributes: "true") + indexSearchableOptions() + layoutAll([buildNumber: "IC-$snapshot", system_selector: "IdeaIC${p("component.version.major")}", tools_jar: true], home, null, paths) } +private void indexSearchableOptions() { + buildSearchableOptions("${projectBuilder.moduleOutput(findModule("resources-en"))}/search", [], { + ant.pathelement(location: "$jdkHome/lib/tools.jar") + ant.pathelement(location: "$home/lib/junit.jar") + projectBuilder.moduleRuntimeClasspath(findModule("community-main"), false).each { + ant.pathelement(location: it) + } + }) +} + def layoutAll(Map args, String home, String out, Paths _paths = null, buildJps = false) { Paths paths = _paths != null ? _paths : new Paths(out) diff --git a/build/scripts/utils.gant b/build/scripts/utils.gant index 2a57fb8ff01b..29a081c309a7 100644 --- a/build/scripts/utils.gant +++ b/build/scripts/utils.gant @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -14,7 +14,6 @@ * limitations under the License. */ - import org.jetbrains.jps.gant.JpsGantTool import org.jetbrains.jps.gant.TeamCityBuildInfoPrinter import org.jetbrains.jps.model.java.JavaSourceRootType @@ -929,13 +928,18 @@ binding.setVariable("buildSearchableOptions", { String target, List licenses, Cl ant.replace(file: classpathFile, token: File.pathSeparator, value: "\n") ant.java(classname: "com.intellij.rt.execution.CommandLineWrapper", fork: true, failonerror: true) { - jvmarg(line: "-Xbootclasspath/a:${projectBuilder.moduleOutput(findModule("boot"))} -ea -Xmx500m -XX:MaxPermSize=200m") - jvmarg(line: "-Didea.home.path=$home -Didea.system.path=${paths.ideaSystem} -Didea.config.path=${paths.ideaConfig}") + jvmarg(line: "-ea -Xmx500m -XX:MaxPermSize=200m") + jvmarg(value: "-Xbootclasspath/a:${projectBuilder.moduleOutput(findModule("boot"))}") + jvmarg(value: "-Didea.home.path=${home}") + jvmarg(value: "-Didea.system.path=${paths.ideaSystem}") + jvmarg(value: "-Didea.config.path=${paths.ideaConfig}") if (jvmArgs != null) { jvmarg(line: jvmArgs) } - arg(line: "${classpathFile} com.intellij.idea.Main traverseUI ${target}/searchableOptions.xml") + arg(value: "${classpathFile}") + arg(line: "com.intellij.idea.Main traverseUI") + arg(value: "${target}/searchableOptions.xml") classpath() { pathelement(location: "${projectBuilder.moduleOutput(findModule("java-runtime"))}") diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java index 7dcf36afb4ee..231e9d708539 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java @@ -90,7 +90,7 @@ class ContractInferenceInterpreter { if (notNull && contract.returnValue == NOT_NULL_VALUE) { return false; } - return ContractInspection.isReturnTypeCompatible(returnType, contract.returnValue); + return InferenceFromSourceUtil.isReturnTypeCompatible(returnType, contract.returnValue); } }); } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInspection.java index dc86cba28de2..69206a74251a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInspection.java @@ -92,29 +92,10 @@ public class ContractInspection extends BaseJavaBatchLocalInspectionTool { return "Method takes " + paramCount + " parameters, while contract clause number " + (i + 1) + " expects " + contract.arguments.length; } PsiType returnType = method.getReturnType(); - if (returnType != null && !isReturnTypeCompatible(returnType, contract.returnValue)) { + if (returnType != null && !InferenceFromSourceUtil.isReturnTypeCompatible(returnType, contract.returnValue)) { return "Method returns " + returnType.getPresentableText() + " but the contract specifies " + contract.returnValue; } } return null; } - - static boolean isReturnTypeCompatible(@Nullable PsiType returnType, @NotNull MethodContract.ValueConstraint returnValue) { - if (returnValue == MethodContract.ValueConstraint.ANY_VALUE || returnValue == MethodContract.ValueConstraint.THROW_EXCEPTION) { - return true; - } - if (PsiType.VOID.equals(returnType)) return false; - - if (PsiType.BOOLEAN.equals(returnType)) { - return returnValue == MethodContract.ValueConstraint.TRUE_VALUE || - returnValue == MethodContract.ValueConstraint.FALSE_VALUE; - } - - if (returnType instanceof PsiClassType) { - return returnValue == MethodContract.ValueConstraint.NULL_VALUE || - returnValue == MethodContract.ValueConstraint.NOT_NULL_VALUE; - } - - return true; - } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/InferenceFromSourceUtil.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/InferenceFromSourceUtil.java index 408277627937..998abf2318d2 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/InferenceFromSourceUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/InferenceFromSourceUtil.java @@ -23,6 +23,7 @@ import com.intellij.psi.search.searches.MethodReferencesSearch; import com.intellij.psi.util.PsiUtil; import com.intellij.psi.util.PsiUtilCore; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author peter @@ -52,4 +53,23 @@ public class InferenceFromSourceUtil { VirtualFile virtualFile = PsiUtilCore.getVirtualFile(method); return virtualFile != null && FileIndexFacade.getInstance(method.getProject()).isInLibrarySource(virtualFile); } + + static boolean isReturnTypeCompatible(@Nullable PsiType returnType, @NotNull MethodContract.ValueConstraint returnValue) { + if (returnValue == MethodContract.ValueConstraint.ANY_VALUE || returnValue == MethodContract.ValueConstraint.THROW_EXCEPTION) { + return true; + } + if (PsiType.VOID.equals(returnType)) return false; + + if (PsiType.BOOLEAN.equals(returnType)) { + return returnValue == MethodContract.ValueConstraint.TRUE_VALUE || + returnValue == MethodContract.ValueConstraint.FALSE_VALUE; + } + + if (returnType instanceof PsiClassType) { + return returnValue == MethodContract.ValueConstraint.NULL_VALUE || + returnValue == MethodContract.ValueConstraint.NOT_NULL_VALUE; + } + + return false; + } } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy index 2d2aeb7c92e5..9b13347bba7a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy @@ -291,6 +291,15 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase { assert c == [] } + public void "test double constant auto-unboxing"() { + def c = inferContracts(""" + static double method() { + return 1; + } + """) + assert c == [] + } + public void "test non-returning delegation"() { def c = inferContracts(""" static void test2(Object o) { @@ -433,6 +442,15 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase { assert c == ['null -> !null'] } + public void "test primitive return type"() { + def c = inferContracts(""" + String s(String s) { + return s != "a" ? "b" : null; + } + """) + assert c == ['null -> !null'] + } + public void "test return after if without else"() { def c = inferContracts(""" public static boolean isBlank(String s) { diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/compiler/JavaCompilingVisitor.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/compiler/JavaCompilingVisitor.java index 1733ead28937..26b11476cf39 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/compiler/JavaCompilingVisitor.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/compiler/JavaCompilingVisitor.java @@ -589,18 +589,6 @@ public class JavaCompilingVisitor extends JavaRecursiveElementWalkingVisitor { } private MatchingStrategy findStrategy(PsiElement el) { - // identify matching strategy - final MatchingHandler handler = myCompilingVisitor.getContext().getPattern().getHandler(el); - - //if (handler instanceof SubstitutionHandler) { - // final SubstitutionHandler shandler = (SubstitutionHandler) handler; - if (handler.getFilter() instanceof SymbolNodeFilter || - handler.getFilter() instanceof TypedSymbolNodeFilter - ) { - return SymbolMatchingStrategy.getInstance(); - } - //} - if (el instanceof PsiDocComment) { return JavaDocMatchingStrategy.getInstance(); } diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/strategies/ExprMatchingStrategy.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/strategies/ExprMatchingStrategy.java index d19205ff3317..4a38b7f40193 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/strategies/ExprMatchingStrategy.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/strategies/ExprMatchingStrategy.java @@ -7,6 +7,27 @@ import com.intellij.psi.*; */ public class ExprMatchingStrategy extends MatchingStrategyBase { + @Override + public void visitTypeElement(PsiTypeElement type) { + result = true; + } + + @Override public void visitReferenceParameterList(PsiReferenceParameterList psiReferenceParameterList) { + result = true; + } + + @Override public void visitReferenceElement(PsiJavaCodeReferenceElement psiJavaCodeReferenceElement) { + result = true; + } + + @Override public void visitTypeParameterList(PsiTypeParameterList psiTypeParameterList) { + result = true; + } + + @Override public void visitReferenceList(final PsiReferenceList list) { + result = true; + } + @Override public void visitAnnotation(final PsiAnnotation annotation) { result = true; } diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/strategies/SymbolMatchingStrategy.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/strategies/SymbolMatchingStrategy.java deleted file mode 100644 index f31ee37e8aed..000000000000 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/impl/matcher/strategies/SymbolMatchingStrategy.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.intellij.structuralsearch.impl.matcher.strategies; - -import com.intellij.psi.*; - -/** - * CommonStrategy to match symbols - */ -public class SymbolMatchingStrategy extends ExprMatchingStrategy { - @Override public void visitReferenceList(final PsiReferenceList list) { - result = true; - } - - @Override public void visitAnnotation(final PsiAnnotation annotation) { - result = true; - } - - @Override public void visitAnnotationParameterList(final PsiAnnotationParameterList list) { - result = true; - } - - @Override public void visitModifierList(final PsiModifierList list) { - result = true; - } - - @Override public void visitNameValuePair(final PsiNameValuePair pair) { - result = true; - } - - @Override public void visitTypeParameterList(PsiTypeParameterList psiTypeParameterList) { - result = true; - } - - @Override public void visitTypeElement(PsiTypeElement psiTypeElement) { - result = true; - } - - @Override public void visitReferenceElement(PsiJavaCodeReferenceElement psiJavaCodeReferenceElement) { - result = true; - } - - @Override public void visitReferenceParameterList(PsiReferenceParameterList psiReferenceParameterList) { - result = true; - } - - private SymbolMatchingStrategy() {} - - private static class SymbolMatchingStrategyHolder { - private static final SymbolMatchingStrategy instance = new SymbolMatchingStrategy(); - } - - public static MatchingStrategy getInstance() { - return SymbolMatchingStrategyHolder.instance; - } -} diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java index 3710fb4bed88..d85cf16e4837 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java @@ -116,6 +116,17 @@ public class SymlinkHandlingTest extends SymlinkTestCase { link2.getPath() + "/" + link1Home.getName() + "/" + link1.getName()); } + public void testSameTargetShouldBeVisitedSeveralTimesFromSeveralNonRecursiveLinks() throws Exception { + File target = createTestDir(myTempDir, "target"); + File child = createTestDir(myTempDir, "child"); + File link1 = createSymLink(target.getPath(), myTempDir.getPath() + "/link1"); + File link2 = createSymLink(target.getPath(), myTempDir.getPath() + "/link2"); + assertVisitedPaths(myTempDir, + target.getPath(), child.getPath(), + link1.getPath(), link1.getPath() + "/child", + link2.getPath(), link2.getPath() + "/child"); + } + public void testTargetIsWritable() throws Exception { File targetFile = createTestFile(myTempDir, "target.txt"); File linkFile = createSymLink(targetFile.getPath(), myTempDir + "/link"); diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java index f5f6ee36de49..6398627faff1 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java @@ -2445,12 +2445,14 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "}\n"; assertEquals("Find all annotations", 4, findMatchesCount(source2, "@'_Annotation")); - String source3 = "class A {\n" + + String source3 = "class A<@HH T> extends @HH Object {\n" + " @HH final String s = (@HH String) new @HH Object();\n" + " final String t = (String) new Object();\n" + + " Map<@HH String, @HH List<@HH String>> map;\n" + "}\n"; assertEquals("Find annotated casts", 1, findMatchesCount(source3, "(@'_A 'Cast) '_Expression")); assertEquals("Find annotated new expressions", 1, findMatchesCount(source3, "new @'_A 'Type()")); + assertEquals("Find all annotations 2", 8, findMatchesCount(source3, "@'_Annotation")); // package-info.java final String source4 = "/**\n" +