Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
irengrig
2011-02-07 15:24:00 +03:00
390 changed files with 6015 additions and 4590 deletions
+11
View File
@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="JPS">
<CLASSES>
<root url="jar://$PROJECT_DIR$/build/lib/gant/lib/jps.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$PROJECT_DIR$/build/lib/gant/jps-sources.zip!/" />
</SOURCES>
</library>
</component>
+1
View File
@@ -7,6 +7,7 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Groovy" level="project" />
<orderEntry type="library" name="Ant" level="project" />
<orderEntry type="library" name="JPS" level="project" />
</component>
</module>
+16 -23
View File
@@ -4,37 +4,23 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>ipr</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>idea.icns</string>
<key>CFBundleTypeName</key>
<string>IntelliJ IDEA Project File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
@@doc_types@@
<key>CFBundleExecutable</key>
<string>idea</string>
<string>@@executable@@</string>
<key>CFBundleIconFile</key>
<string>idea.icns</string>
<string>@@icns@@</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>IntelliJ IDEA</string>
<string>@@bundle_name@@</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleIdentifier</key>
<string>com.jetbrains.intellij</string>
<string>@@bundle_identifier@@</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleGetInfoString</key>
<string>IntelliJ IDEA @@version@@, build @@build@@. Copyright JetBrains s.r.o., (c) 2000-@@year@@</string>
<string>@@bundle_name@@ @@version@@, build @@build@@. Copyright JetBrains s.r.o., (c) 2000-@@year@@</string>
<key>CFBundleShortVersionString</key>
<string>@@version@@</string>
<key>CFBundleVersion</key>
@@ -49,12 +35,12 @@
<string>YES</string>
<key>Java</key>
<dict>
<dict>
<key>ClassPath</key>
<string>$APP_PACKAGE/lib/bootstrap.jar:$APP_PACKAGE/lib/extensions.jar:$APP_PACKAGE/lib/util.jar:$APP_PACKAGE/lib/jdom.jar:$APP_PACKAGE/lib/log4j.jar</string>
<key>JVMVersion</key>
<string>@@jdk_req@@</string>
<string>1.6*</string>
<key>MainClass</key>
<string>com.intellij.idea.Main</string>
@@ -82,13 +68,20 @@
<string>true</string>
<key>apple.awt.fullscreencapturealldisplays</key>
<string>false</string>
@@platform@@
</dict>
<key>VMOptions</key>
<string>@@vmoptions@@ -Xbootclasspath/a:../lib/boot.jar</string>
<key>VMOptions.i386</key>
<string>@@vmoptions32@@</string>
<key>VMOptions.x86_64</key>
<string>@@vmoptions64@@</string>
<key>WorkingDirectory</key>
<string>$APP_PACKAGE/bin</string>
</dict>
</dict>
</dict>
</plist>
+29 -57
View File
@@ -67,8 +67,6 @@ target('default': 'The default target') {
buildNumber: "IC-104.SNAPSHOT",
version: "IdeaX",
system_selector: "IntelliJIdeaCE10",
jdk_req: "1.6*",
vmoptions: "-Xms128m -Xmx512m -XX:MaxPermSize=250m -ea",
home, out)
}
@@ -93,35 +91,6 @@ public def layoutAll(Map args, String home, String out) {
layoutWin(args, home, paths)
}
boolean isEap() {
return "true" == p("component.version.eap")
}
private def patchPropertiesFile(String where) {
ant.echo(file: "$where/bin/idea.properties", append: "true", message:
isEap() ?
"""
#-----------------------------------------------------------------------
# Change to 'disabled' if you need not to receive instant visual notifications about
# fatal errors that happen to IDEA or plugins installed.
#-----------------------------------------------------------------------
idea.fatal.error.notification=enabled
"""
:
"""
#-----------------------------------------------------------------------
# Change to 'eanbled' if you need to receive instant visual notifications about
# fatal errors that happen to IDEA or plugins installed.
#-----------------------------------------------------------------------
idea.fatal.error.notification=disabled
"""
)
}
private def layoutWin(Map args, String home, Paths paths) {
layout("$paths.distWin") {
dir("bin") {
@@ -131,7 +100,7 @@ private def layoutWin(Map args, String home, Paths paths) {
}
patchPropertiesFile(paths.distWin)
ant.echo(file: "$paths.distWin/bin/idea.exe.vmoptions", message: args.vmoptions.replace(' ', '\n'))
ant.echo(file: "$paths.distWin/bin/idea.exe.vmoptions", message: vmoptions32().replace(' ', '\n'))
def winZipPath = "$paths.artifacts/idea${args.buildNumber}.win.zip"
ant.zip(zipfile: winZipPath) {
@@ -143,35 +112,38 @@ private def layoutWin(Map args, String home, Paths paths) {
private def layoutMac(Map args, String home, Paths paths) {
project.stage("Cleaning up sandbox folder")
args["executable"] = "idea"
args["bundle_name"] = "IntelliJ IDEA"
args["bundleIdentifier"] = "com.jetbrains.intellij.ce"
args["platform_prefix"] = "Idea"
args["doc_types"] = """
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>ipr</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>idea.icns</string>
<key>CFBundleTypeName</key>
<string>IntelliJ IDEA Project File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
"""
ant.copy(todir: "$paths.distMac/bin") {
fileset(dir: "$home/bin") { include(name: "*.*") }
fileset(dir: "$home/bin/nix")
fileset(dir: "$home/bin/mac")
layoutMacApp(paths.distMac, home, args)
layout(paths.distMac) {
dir("bin") {
fileset(dir: "$home/bin") { include(name: "*.*") }
}
}
patchPropertiesFile(paths.distMac)
ant.copy(todir: paths.distMac) {
fileset(dir: "$home/build/conf/mac")
}
def version = isEap() ? p("component.version.codename") : p("component.version.major") + "." + p("component.version.minor")
ant.tstamp() {
format(property: "todayYear", pattern: "yyyy")
}
ant.replace(file: "${paths.distMac}/Contents/Info.plist") {
replacefilter(token: "@@build@@", value: args.buildNumber)
replacefilter(token: "@@year@@", value: "$todayYear")
replacefilter(token: "@@version@@", value: version)
replacefilter(token: "@@vmoptions@@", value: args.vmoptions + " -Xverify:none -XX:+UseCompressedOOPS")
replacefilter(token: "@@system_selector@@", value: args.system_selector)
replacefilter(token: "@@jdk_req@@", value: args.jdk_req)
}
def root = isEap() ? "${p("component.version.codename")}-${args.buildNumber}.app" : "IntelliJ IDEA ${p("component.version.major")} CE.app"
def macZipPath = "$paths.artifacts/idea${args.buildNumber}.mac.zip"
@@ -205,7 +177,7 @@ def layoutLinux(Map args, String home, Paths paths) {
patchPropertiesFile(paths.distUnix)
ant.echo(file: "$paths.distUnix/bin/idea.vmoptions", message: args.vmoptions.replace(' ', '\n') )
ant.echo(file: "$paths.distUnix/bin/idea.vmoptions", message: vmoptions32().replace(' ', '\n') )
ant.fixcrlf(srcdir: "$paths.distUnix/bin", includes: "idea.vmoptions", eol: "unix")
ant.fixcrlf(srcdir: "$paths.distUnix/bin", includes: "*.sh", eol: "unix")
-1
View File
@@ -302,7 +302,6 @@ def layoutFull(String home, String targetDirectory) {
fileset(dir: "$home/plugins/groovy/resources/conf")
fileset(dir: "${home}/plugins/groovy/lib")
}
}
+153
View File
@@ -0,0 +1,153 @@
import org.jetbrains.jps.*
class LibraryLicense {
String name, libraryName, url, version
String license, licenseUrl
}
List<LibraryLicense> licensesList = []
List<String> jetbrainsLibraries = ["tcServiceMessages"]
Map<String, String> predefinedLicenseUrls = ["Apache 2.0": "http://www.apache.org/licenses/LICENSE-2.0"]
binding.setVariable("libraryLicense", {Map args ->
if (args.libraryName == null) {
args.libraryName = args.name;
}
if (args.licenseUrl == null) {
args.licenseUrl = predefinedLicenseUrls[args.license]
}
licensesList << new LibraryLicense(args)
})
binding.setVariable("jetbrainsLibrary", {String name ->
jetbrainsLibraries << name
})
def String getLibraryName(Library lib) {
def name = lib.name
if (name.startsWith("moduleLibrary#")) {
if (lib.classpath.size() != 1) {
project.error("Non-single entry module library $name: $lib.classpath");
}
String filePath = lib.classpath[0]
return filePath.substring(filePath.lastIndexOf('/')+1)
}
return name
}
binding.setVariable("checkLibLicenses", {
def libraries = new HashSet<Library>()
def lib2Module = new HashMap<Library, Module>();
project.modules.values().each {Module module ->
module.getClasspath(ClasspathKind.PRODUCTION_RUNTIME).each {
if (it instanceof Library) {
lib2Module[it] = module
libraries << it
}
}
}
def libWithLicenses = licensesList.collect {it.libraryName} as Set
libWithLicenses.addAll(jetbrainsLibraries)
List<String> withoutLicenses = []
libraries.each {Library lib ->
def name = getLibraryName(lib)
if (!libWithLicenses.contains(name)) {
withoutLicenses << "$name (used in module ${lib2Module[lib].name})".toString()
}
}
if (!withoutLicenses.isEmpty()) {
project.warning("Licenses aren't specified for ${withoutLicenses.size()} libraries:")
withoutLicenses.sort(String.CASE_INSENSITIVE_ORDER)
withoutLicenses.each { project.warning(it); }
}
});
binding.setVariable("checkLibLicensesAndGenerateTable", {String filePath ->
checkLibLicenses();
generateLicensesTable(filePath)
notifyArtifactBuilt(filePath)
})
binding.setVariable("generateLicensesTable", {String filePath ->
Set<Module> modules = project.modules.values().findAll {it["used"] != null}
Set<String> usedLibraries = [] as Set
modules.each {
it.getClasspath(ClasspathKind.PRODUCTION_RUNTIME).each {item ->
if (item instanceof Library) {
usedLibraries << getLibraryName(item)
}
}
}
def licenses = licensesList.findAll {usedLibraries.contains(it.libraryName) }
List<String> lines = licenses.collect { LibraryLicense lib ->
def name = lib.url != null ? "[$lib.name|$lib.url]" : lib.name
def license = lib.licenseUrl != null ? "[$lib.license|$lib.licenseUrl]" : lib.license
return "|$name| $lib.version|$license|".toString()
}
lines.sort(String.CASE_INSENSITIVE_ORDER)
FileWriter out = new FileWriter(filePath)
out.println("|| Software || Version || License ||")
lines.each {
out.println(it)
}
out.close()
})
libraryLicense(name: "Alloy L&F", libraryName: "alloy.jar", version: "1.4.4", license: "link (company license)", url: "http://www.incors.com/lookandfeel/", licenseUrl: "http://lookandfeel.incors.com/display_licence.php?back=purchase.php&selMenu=Purchase")
libraryLicense(name: "Ant", version: "1.7", license: "Apache 2.0", url: "http://ant.apache.org/", licenseUrl: "http://ant.apache.org/license.html")
libraryLicense(name: "ASM Bytecode Manipulation Framework", libraryName: "asm", version: "3.3", license: "BSD", url: "http://asm.objectweb.org/", licenseUrl: "http://asm.objectweb.org/license.html")
libraryLicense(name: "Axis", libraryName: "axis-1.4", version: "1.4", license: "Apache 2.0", url: "http://ws.apache.org/axis/", licenseUrl: "http://svn.jetbrains.org/idea/Trunk/bundled/WebServices/resources/lib/axis-1.4.0/axis.LICENSE")
libraryLicense(name: "CGLib", libraryName: "CGLIB", version: "2.2", license: "Apache", url: "http://cglib.sourceforge.net/", licenseUrl: "http://www.apache.org/foundation/licence-FAQ.html")
libraryLicense(name: "classworlds", libraryName: "classworlds-1.1.jar", version: "1.1", license: "codehaus", url: "http://classworlds.codehaus.org/", licenseUrl: "http://classworlds.codehaus.org/license.html")
libraryLicense(name: "Apache Commons BeanUtils", libraryName: "commons-beanutils.jar", version: "1.6", license: "Apache 2.0", url: "http://commons.apache.org/beanutils/")
libraryLicense(name: "Apache Commons Codec", libraryName: "commons-codec", version: "1.3", license: "Apache 2.0", url: "http://commons.apache.org/codec/", licenseUrl: "http://commons.apache.org/license.html")
libraryLicense(name: "Apache Commons Collections", libraryName: "commons-collections", version: "3.1", license: "Apache 2.0", url: "http://commons.apache.org/collections/", licenseUrl: "http://commons.apache.org/license.html")
libraryLicense(name: "Apache Commons HTTPClient", libraryName: "http-client-3.1", version: "3.1&nbsp; (with patch by JetBrains)", license: "Apache 2.0", url: "http://hc.apache.org/httpclient-3.x")
libraryLicense(name: "Apache Commons Lang", libraryName: "commons-lang", version: "2.4", license: "Apache 2.0", url: "http://commons.apache.org/lang/", licenseUrl: "http://commons.apache.org/lang/license.html")
libraryLicense(name: "Apache Commons Logging", libraryName: "commons-logging", version: "1.1.1", license: "Apache 2.0", url: "http://commons.apache.org/logging/")
libraryLicense(name: "Apache Lucene", libraryName: "lucene-core-2.3.0.jar", version: "2.3.0", license: "Apache 2.0", url: "http://lucene.apache.org/java")
libraryLicense(name: "Automaton", libraryName: "automaton.jar", version: "1.11", license: "BSD", url: "http://www.brics.dk/automaton/", licenseUrl: "http://www.opensource.org/licenses/bsd-license.php")
libraryLicense(name: "DTDParser", version: "1.13", license: "LGPL", url: "http://sourceforge.net/projects/dtdparser/", licenseUrl: "http://www.opensource.org/licenses/lgpl-2.1")
libraryLicense(name: "Ganymed", version: "bundled with SVNKit", license: "BSD", url: "http://www.ganymed.ethz.ch/ssh2/", licenseUrl: "http://www.ganymed.ethz.ch/ssh2/LICENSE.txt")
libraryLicense(name: "Guava", version: "R6", license: "Apache 2.0", url: "http://code.google.com/p/guava-libraries/", licenseUrl: "http://ant.apache.org/license.html")
libraryLicense(name: "Gradle API", libraryName: "gradle-open-api-0.8.jar", version: "0.8", license: "Apache 2.0", url: "http://www.gradle.org/")
libraryLicense(name: "Groovy", version: "1.7.3", license: "Apache 2.0", url: "http://groovy.codehaus.org/")
libraryLicense(name: "Gson", libraryName: "gson-1.3.jar", license: "Apache 2.0", url: "http://code.google.com/p/google-gson/")
libraryLicense(name: "ISO RELAX", libraryName: "isorelax.jar", license: "MIT License", url: "http://sourceforge.net/projects/iso-relax/", licenseUrl: "http://www.opensource.org/licenses/mit-license.html")
libraryLicense(name: "JavaCVS", version: "no version number available (with patches by JetBrains)", license: "Sun Public License", url: "http://javacvs.netbeans.org/library/", licenseUrl: "http://www.netbeans.org/about/legal/spl.html")
libraryLicense(name: "JAXB", libraryName: "JAXB", version: "2.1.10", license: "CDDL 1.1 & GPL 2", url: "http://jaxb.java.net/", licenseUrl: "http://glassfish.java.net/public/CDDL+GPL_1_1.html")
libraryLicense(name: "Jaxen", version: "", license: "modified Apache", url: "http://www.jaxen.org/", licenseUrl: "http://www.jaxen.org/license.html")
libraryLicense(name: "JavaHelp", version: "2.0_02", license: "included as license/javahelp_license.html in IntelliJ IDEA distribution", url: "http://java.sun.com/products/javahelp/")
libraryLicense(name: "JCIP Annotations", libraryName: "jcip-annotations.jar", license: "Creative Commons Attribution License", url: "http://www.jcip.net", licenseUrl: "http://creativecommons.org/licenses/by/2.5")
libraryLicense(name: "JDOM", version: "1.1 (with patches by JetBrains)", license: "modified Apache", url: "http://www.jdom.org/", licenseUrl: "http://www.jdom.org/docs/faq.html#a0030")
libraryLicense(name: "JGoodies Forms", libraryName: "jgoodies-forms", version: "CVS snapshot as of 5 May 2006", license: "BSD ", url: "http://www.jgoodies.com/freeware/forms/", licenseUrl: "http://www.jgoodies.com/downloads/libraries.html")
libraryLicense(name: "JNA", libraryName: "jna", version: "3.2.4", license: "LGPL 2.1", url: "https://jna.dev.java.net/", licenseUrl: "http://www.opensource.org/licenses/lgpl-2.1.php")
libraryLicense(name: "JNA", libraryName: "jna.jar", version: "3.2.7", license: "LGPL 2.1", url: "https://jna.dev.java.net/", licenseUrl: "http://www.opensource.org/licenses/lgpl-2.1.php")
libraryLicense(name: "JUnit", libraryName: "JUnit3", version: "3.8.1", license: "CPL 1.0", url: "http://junit.org/")
libraryLicense(name: "JUnit", libraryName: "JUnit4", version: "4.8", license: "CPL 1.0", url: "http://junit.org/")
libraryLicense(name: "Log4j", libraryName: "Log4J", version: "1.2", license: "Apache 2.0", url: "http://logging.apache.org/log4j/1.2/index.html", licenseUrl: "http://logging.apache.org/license.html")
libraryLicense(name: "Maven", version: "2.2.1", license: "Apache 2.0", url: "http://maven.apache.org/", licenseUrl: "http://maven.apache.org/license.html")
libraryLicense(name: "Microba", libraryName: "microba", version: "0.4.2", license: "BSD", url: "http://microba.sourceforge.net/", licenseUrl: "http://microba.sourceforge.net/license.txt")
libraryLicense(name: "NanoXML", version: "2.2.3", license: "zlib/libpng", url: "http://nanoxml.cyberelf.be/", licenseUrl: "http://devkix.com/nanoxml.php")
libraryLicense(name: "Eclipse JDT Core", libraryName: "Eclipse", version: "3.3", license: "CPL 1.0", url: "http://www.eclipse.org/jdt/core/index.php")
libraryLicense(name: "Jakarta ORO", libraryName: "OroMatcher", version: "2.0.8", license: "Apache", url: "http://jakarta.apache.org/oro/", licenseUrl: "http://svn.apache.org/repos/asf/jakarta/oro/trunk/LICENSE")
libraryLicense(name: "PicoContainer", libraryName: "picocontainer", version: "1.2", license: "BSD", url: "http://www.picocontainer.org/", licenseUrl: "http://docs.codehaus.org/display/PICO/License")
libraryLicense(name: "Plexus Utils", libraryName: "plexus-utils-1.5.5.jar", version: "1.5.5", license: "Apache 2.0", url: "http://plexus.codehaus.org/plexus-utils")
libraryLicense(name: "Relax NG Object Model", libraryName: "rngom-20051226-patched.jar", license: "MIT", url: "http://java.net/projects/rngom/", licenseUrl: "http://www.opensource.org/licenses/mit-license.php")
libraryLicense(name: "SVNKit", libraryName: "svnkit.jar", version: "SVN version, 1.1 branch as of 1 Oct 2007", license: "link (commercial license)", url: "http://www.svnkit.com/", licenseUrl: "http://svnkit.com/license.html")
libraryLicense(name: "TestNG", version: "5.7 snapshot", license: "Apache 2.0", url: "http://testng.org/doc/", licenseUrl: "http://code.google.com/p/testng/")
libraryLicense(name: "Trilead SSH", libraryName: "trilead-ssh2-build213.jar", version: "build 213", license: "BSD style (see LICENSE.txt in trilead-ssh-build213.jar)", url: "http://www.trilead.com/SSH_Library/")
libraryLicense(name: "Trove4j", version: "1.1 (with patches by JetBrains)", license: "LGPL", url: "http://trove4j.sourceforge.net/", licenseUrl: "http://trove4j.sourceforge.net/html/license.html")
libraryLicense(name: "Velocity", version: "1.3", license: "Apache", url: "http://velocity.apache.org/", licenseUrl: "http://velocity.apache.org/index.html")
libraryLicense(name: "winp", version: "1.14", license: "MIT", url: "http://winp.dev.java.net/", licenseUrl: "https://winp.dev.java.net/license.html")
libraryLicense(name: "Xerces", version: "2.8.1", license: "Apache 2.0", url: "http://xerces.apache.org/xerces2-j/", licenseUrl: "http://xerces.apache.org/xerces2-j/")
libraryLicense(name: "XML Commons (xml-apis.jar, resolver.jar)", version: "", license: "Apache 2.0, W3C Software License , public domain", url: "http://xml.apache.org/commons/", licenseUrl: "http://xml.apache.org/commons/licenses.html")
libraryLicense(name: "XMLBeans", libraryName: "XmlBeans", version: "2.3.0", license: "Apache 2.0", url: "http://xmlbeans.apache.org/", licenseUrl: "http://svn.jetbrains.org/idea/Trunk/bundled/WebServices/resources/lib/xmlbeans-2.3.0/xmlbeans.LICENSE")
libraryLicense(name: "XML-RPC", libraryName: "XmlRPC", version: "2.0", license: "Apache 2.0", url: "http://ws.apache.org/xmlrpc/xmlrpc2/", licenseUrl: "http://ws.apache.org/xmlrpc/xmlrpc2/license.html")
libraryLicense(name: "XStream", version: "1.2.1", license: "BSD", url: "http://xstream.codehaus.org/", licenseUrl: "http://xstream.codehaus.org/license.html")
libraryLicense(name: "YourKit Java Profiler", libraryName: "yjp-controller-api-redist.jar", version: "7.0.2", license: "link (commercial license)", url: "http://yourkit.com/", licenseUrl: "http://www.yourkit.com/purchase/license.html")
+89
View File
@@ -21,6 +21,17 @@ binding.setVariable("isMac", {
return System.getProperty("os.name").toLowerCase().startsWith("mac")
})
binding.setVariable("isEap", {
return "true" == p("component.version.eap")
})
binding.setVariable("mem32", "-Xms128m -Xmx512m -XX:MaxPermSize=250m")
binding.setVariable("mem64", "-Xms128m -Xmx800m -XX:MaxPermSize=350m")
binding.setVariable("common_vmoptions", "-ea")
binding.setVariable("vmoptions32", {"$mem32 $common_vmoptions"})
binding.setVariable("vmoptions64", {"$mem64 $common_vmoptions"})
binding.setVariable("isDefined", {String key ->
try {
this[key]
@@ -109,3 +120,81 @@ binding.setVariable("commonJvmArgs", {
"-Xdebug",
"-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5555"]
})
binding.setVariable("layoutMacApp", { String path, String ch, Map args ->
ant.copy(todir: "$path/bin") {
fileset(dir: "$ch/bin/nix")
fileset(dir: "$ch/bin/mac")
}
ant.copy(todir: path) {
fileset(dir: "$ch/build/conf/mac")
}
ant.tstamp() {
format(property: "todayYear", pattern: "yyyy")
}
String icns = "idea.icns"
if (args.icns != null) {
ant.delete(file: "$path/Contents/Resources/idea.icns")
ant.copy(file: args.icns, todir: "$path/Contents/Resources")
icns = new File((String)args.icns).getName();
}
String platform = args.get("platform_prefix", null) != null ?
"""
<key>idea.platform.prefix</key>
<string>$args.platform_prefix</string>
""" : ""
def version = isEap() ? "EAP " + args.buildNumber : p("component.version.major") + "." + p("component.version.minor")
ant.replace(file: "$path/Contents/Info.plist") {
replacefilter(token: "@@build@@", value: args.buildNumber)
replacefilter(token: "@@doc_types@@", value: args.get("doc_types", ""))
replacefilter(token: "@@executable@@", value: args.executable)
replacefilter(token: "@@icns@@", value: icns)
replacefilter(token: "@@bundle_name@@", value: args.bundle_name)
replacefilter(token: "@@bundle_identifier@@", value: args.bundleIdentifier)
replacefilter(token: "@@year@@", value: "$todayYear")
replacefilter(token: "@@version@@", value: version)
replacefilter(token: "@@vmoptions@@", value: "$common_vmoptions -Xverify:none")
replacefilter(token: "@@vmoptions32@@", value: "$mem32")
replacefilter(token: "@@vmoptions64@@", value: "$mem64 -XX:+UseCompressedOOPS")
replacefilter(token: "@@system_selector@@", value: args.system_selector)
replacefilter(token: "@@platform@@", value: platform)
}
if (args.executable != "idea") {
ant.move(file: "$path/Contents/MacOS/idea", tofile: "$path/Contents/MacOS/$args.executable")
}
})
binding.setVariable("patchPropertiesFile", { String where ->
ant.echo(file: "$where/bin/idea.properties", append: "true", message:
isEap() ?
"""
#-----------------------------------------------------------------------
# Change to 'disabled' if you do not need to receive instant visual notifications about
# fatal errors that happen to an IDE or plugins installed.
#-----------------------------------------------------------------------
idea.fatal.error.notification=enabled
"""
:
"""
#-----------------------------------------------------------------------
# Change to 'eanbled' if you need to receive instant visual notifications about
# fatal errors that happen to an IDE or plugins installed.
#-----------------------------------------------------------------------
idea.fatal.error.notification=disabled
"""
)
})
-9
View File
@@ -18,15 +18,6 @@
<orderEntry type="library" name="asm" level="project" />
<orderEntry type="library" name="Eclipse" level="project" />
<orderEntry type="module" module-name="platform-api" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../../../lib/dev/compilerapi.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module" module-name="lang-impl" />
<orderEntry type="module" module-name="jsp-openapi" />
<orderEntry type="module" module-name="java-impl" />
@@ -43,6 +43,7 @@ import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.jsp.JspFile;
import com.intellij.ui.classFilter.ClassFilter;
import com.intellij.util.StringBuilderSpinAllocator;
@@ -444,8 +445,10 @@ public abstract class BreakpointWithHighlighter extends Breakpoint {
return false;
}
final PsiFile psiFile = position.getFile();
final PsiFile oldFile = getSourcePosition().getFile();
final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile);
if (document == null) {
final Document oldDocument = PsiDocumentManager.getInstance(getProject()).getDocument(oldFile);
if (document == null || oldDocument == null) {
return false;
}
final RangeHighlighter newHighlighter = createHighlighter(myProject, document, position.getLine());
@@ -458,13 +461,13 @@ public abstract class BreakpointWithHighlighter extends Breakpoint {
reload();
if(!isValid()) {
document.getMarkupModel(myProject).removeHighlighter(myHighlighter);
oldDocument.getMarkupModel(myProject).removeHighlighter(myHighlighter);
myHighlighter = oldHighlighter;
reload();
return false;
}
document.getMarkupModel(myProject).removeHighlighter(oldHighlighter);
oldDocument.getMarkupModel(myProject).removeHighlighter(oldHighlighter);
DebuggerManagerEx.getInstanceEx(getProject()).getBreakpointManager().fireBreakpointChanged(this);
updateUI();
@@ -666,11 +669,9 @@ public abstract class BreakpointWithHighlighter extends Breakpoint {
public GutterDraggableObject getDraggableObject() {
return new GutterDraggableObject() {
public void removeSelf() {
}
public boolean copy(int line) {
return moveTo(SourcePosition.createFromLine(getSourcePosition().getFile(), line));
public boolean copy(int line, VirtualFile file) {
final PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
return psiFile == null ? false : moveTo(SourcePosition.createFromLine(psiFile, line));
}
public Cursor getCursor(int line) {
@@ -64,10 +64,19 @@ public class ProjectJdksConfigurable extends MasterDetailsComponent {
super();
myProject = project;
myProjectJdksModel = ProjectStructureConfigurable.getInstance(project).getProjectJdksModel();
MasterDetailsStateService.getInstance(project).register("ProjectJDKs.UI", this);
initTree();
}
@Override
protected String getComponentStateKey() {
return "ProjectJDKs.UI";
}
@Override
protected MasterDetailsStateService getStateService() {
return MasterDetailsStateService.getInstance(myProject);
}
protected void initTree() {
super.initTree();
new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
@@ -34,7 +34,6 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorLi
import com.intellij.openapi.roots.ui.configuration.projectRoot.*;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
import com.intellij.openapi.ui.MasterDetailsState;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.packaging.artifacts.*;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
@@ -61,7 +60,11 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
public ArtifactsStructureConfigurable(@NotNull Project project) {
super(project, new ArtifactStructureConfigurableState());
MasterDetailsStateService.getInstance(project).register("ArtifactsStructureConfigurable.UI", this);
}
@Override
protected String getComponentStateKey() {
return "ArtifactsStructureConfigurable.UI";
}
public void init(StructureConfigurableContext context, ModuleStructureConfigurable moduleStructureConfigurable,
@@ -160,7 +163,7 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
}
@Override
public MasterDetailsState getState() {
protected MasterDetailsState getState() {
((ArtifactStructureConfigurableState)myState).setDefaultArtifactSettings(myDefaultSettings.getState());
return super.getState();
}
@@ -209,6 +212,7 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
@Override
public void reset() {
loadComponentState();
myPackagingEditorContext.resetModifiableModel();
super.reset();
}
@@ -32,6 +32,7 @@ import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.*;
import com.intellij.openapi.ui.MasterDetailsComponent;
import com.intellij.openapi.ui.MasterDetailsState;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.Condition;
@@ -100,6 +101,10 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i
});
}
@Override
protected MasterDetailsStateService getStateService() {
return MasterDetailsStateService.getInstance(myProject);
}
public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) {
if (place == null) return new ActionCallback.Done();
@@ -37,7 +37,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
import com.intellij.openapi.ui.DetailsComponent;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.openapi.util.IconLoader;
import org.jetbrains.annotations.NotNull;
@@ -59,10 +58,14 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable {
public FacetStructureConfigurable(final Project project, ModuleManager moduleManager) {
super(project);
MasterDetailsStateService.getInstance(project).register("FacetStructureConfigurable.UI", this);
myModuleManager = moduleManager;
}
@Override
protected String getComponentStateKey() {
return "FacetStructureConfigurable.UI";
}
public static FacetStructureConfigurable getInstance(final @NotNull Project project) {
return ServiceManager.getService(project, FacetStructureConfigurable.class);
}
@@ -19,7 +19,6 @@ import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.ui.MasterDetailsStateService;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -31,10 +30,14 @@ public class GlobalLibrariesConfigurable extends BaseLibrariesConfigurable {
public GlobalLibrariesConfigurable(final Project project) {
super(project);
MasterDetailsStateService.getInstance(project).register("GlobalLibrariesConfigurable.UI", this);
myLevel = LibraryTablesRegistrar.APPLICATION_LEVEL;
}
@Override
protected String getComponentStateKey() {
return "GlobalLibrariesConfigurable.UI";
}
@Nls
public String getDisplayName() {
return "Global Libraries";
@@ -30,7 +30,6 @@ import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.SdkProjectStructureElement;
import com.intellij.openapi.ui.MasterDetailsComponent;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.Nls;
@@ -75,10 +74,15 @@ public class JdkListConfigurable extends BaseStructureConfigurable {
public JdkListConfigurable(final Project project, ProjectStructureConfigurable root) {
super(project);
MasterDetailsStateService.getInstance(project).register("JdkListConfigurable.UI", this);
myJdksTreeModel = root.getProjectJdksModel();
myJdksTreeModel.addListener(myListener);
}
@Override
protected String getComponentStateKey() {
return "JdkListConfigurable.UI";
}
protected void processRemovedItems() {
}
@@ -50,7 +50,6 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProj
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureDaemonAnalyzer;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.openapi.util.Comparing;
@@ -96,10 +95,13 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
public ModuleStructureConfigurable(Project project, ModuleManager manager) {
super(project);
MasterDetailsStateService.getInstance(project).register("ModuleStructureConfigurable.UI", this);
myModuleManager = manager;
}
@Override
protected String getComponentStateKey() {
return "ModuleStructureConfigurable.UI";
}
protected void initTree() {
super.initTree();
@@ -19,7 +19,6 @@ import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.ui.MasterDetailsStateService;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -30,10 +29,14 @@ import javax.swing.*;
public class ProjectLibrariesConfigurable extends BaseLibrariesConfigurable {
public ProjectLibrariesConfigurable(final Project project) {
super(project);
MasterDetailsStateService.getInstance(project).register("ProjectLibrariesConfigurable.UI", this);
myLevel = LibraryTablesRegistrar.PROJECT_LEVEL;
}
@Override
protected String getComponentStateKey() {
return "ProjectLibrariesConfigurable.UI";
}
@Nls
public String getDisplayName() {
return "Libraries";
-1
View File
@@ -4,7 +4,6 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
</content>
<orderEntry type="module" module-name="boot" />
<orderEntry type="inheritedJdk" />
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiType;
import com.intellij.psi.codeStyle.CodeStyleSettings;
@@ -27,6 +28,8 @@ import org.jetbrains.annotations.Nullable;
* @author peter
*/
public class CastingLookupElementDecorator extends LookupElementDecorator<LookupElement> implements TypedLookupItem {
public static final ClassConditionKey<CastingLookupElementDecorator> CLASS_CONDITION_KEY = ClassConditionKey.create(CastingLookupElementDecorator.class);
private final LookupElement myCastItem;
private final PsiType myCastType;
@@ -78,14 +81,4 @@ public class CastingLookupElementDecorator extends LookupElementDecorator<Lookup
static LookupElement createCastingElement(final LookupElement delegate, PsiType castTo) {
return new CastingLookupElementDecorator(delegate, castTo);
}
public static @Nullable CastingLookupElementDecorator from(LookupElement element) {
if (element instanceof CastingLookupElementDecorator) return (CastingLookupElementDecorator)element;
else if (element instanceof LookupElementDecorator) {
element = ((LookupElementDecorator)element).getDelegate();
if (element instanceof CastingLookupElementDecorator) return (CastingLookupElementDecorator)element;
}
return null;
}
}
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.*;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.util.PsiTreeUtil;
@@ -30,6 +31,7 @@ import java.util.Set;
* @author peter
*/
public class JavaChainLookupElement extends LookupElementDecorator<LookupElement> implements TypedLookupItem {
public static final ClassConditionKey<JavaChainLookupElement> CLASS_CONDITION_KEY = ClassConditionKey.create(JavaChainLookupElement.class);
private final LookupElement myQualifier;
private JavaChainLookupElement(LookupElement qualifier, LookupElement main) {
@@ -72,7 +74,7 @@ public class JavaChainLookupElement extends LookupElementDecorator<LookupElement
final LookupElementPresentation qualifierPresentation = new LookupElementPresentation();
myQualifier.renderElement(qualifierPresentation);
String name = maybeAddParentheses(qualifierPresentation.getItemText());
final String qualifierText = myQualifier.as(CastingLookupElementDecorator.class) != null ? "(" + name + ")" : name;
final String qualifierText = myQualifier.as(CastingLookupElementDecorator.CLASS_CONDITION_KEY) != null ? "(" + name + ")" : name;
presentation.setItemText(qualifierText + "." + presentation.getItemText());
}
@@ -122,7 +124,7 @@ public class JavaChainLookupElement extends LookupElementDecorator<LookupElement
@NotNull
private LookupElement getComparableQualifier() {
final CastingLookupElementDecorator casting = CastingLookupElementDecorator.from(myQualifier);
final CastingLookupElementDecorator casting = myQualifier.as(CastingLookupElementDecorator.CLASS_CONDITION_KEY);
return casting == null ? myQualifier : casting.getDelegate();
}
@@ -242,7 +242,7 @@ public class JavaCompletionContributor extends CompletionContributor {
result.addElement(TailTypeDecorator.withTail(element, TailType.createSimpleTailType(':')));
}
else {
final LookupItem item = element.as(LookupItem.class);
final LookupItem item = element.as(LookupItem.CLASS_CONDITION_KEY);
if (originalFile instanceof PsiJavaCodeReferenceCodeFragment &&
!((PsiJavaCodeReferenceCodeFragment)originalFile).isClassesAccepted() && item != null) {
item.setTailType(TailType.NONE);
@@ -19,7 +19,6 @@ import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.statistics.JavaStatisticsManager;
import com.intellij.psi.statistics.StatisticsInfo;
@@ -51,7 +50,7 @@ public class JavaCompletionStatistician extends CompletionStatistician{
}
}
LookupItem item = LookupItem.from(element);
LookupItem item = element.as(LookupItem.CLASS_CONDITION_KEY);
if (item == null) return null;
PsiType qualifierType = JavaCompletionUtil.getQualifierType(item);
@@ -503,13 +503,13 @@ public class JavaCompletionUtil {
@Nullable
public static PsiType getLookupElementType(final LookupElement element) {
TypedLookupItem typed = typedFrom(element);
TypedLookupItem typed = element.as(TypedLookupItem.CLASS_CONDITION_KEY);
if (typed != null) {
return typed.getType();
}
final PsiType qualifierType = getPsiType(element.getObject());
final LookupItem lookupItem = LookupItem.from(element);
final LookupItem lookupItem = element.as(LookupItem.CLASS_CONDITION_KEY);
if (lookupItem != null) {
final Object o = lookupItem.getAttribute(LookupItem.TYPE);
if (o instanceof PsiType) {
@@ -524,16 +524,6 @@ public class JavaCompletionUtil {
return qualifierType;
}
public static @Nullable TypedLookupItem typedFrom(LookupElement element) {
TypedLookupItem typed = null;
if (element instanceof TypedLookupItem) typed = (TypedLookupItem)element;
else if (element instanceof LookupElementDecorator) {
element = ((LookupElementDecorator)element).getDelegate();
if (element instanceof TypedLookupItem) typed = (TypedLookupItem)element;
}
return typed;
}
@Nullable
public static PsiType getQualifiedMemberReferenceType(@Nullable PsiType qualifierType, @NotNull final PsiMember member) {
final ClassCandidateInfo info = TypeConversionUtil.splitType(qualifierType, member);
@@ -605,7 +595,7 @@ public class JavaCompletionUtil {
if (o instanceof PsiMember) {
mentioned.add((PsiMember)o);
}
set.add(mayHighlight ? highlightIfNeeded(qualifierType, item) : item);
set.add(mayHighlight ? highlightIfNeeded(qualifierType, item, o) : item);
}
}
@@ -668,7 +658,8 @@ public class JavaCompletionUtil {
for (CompletionElement completionElement : processor.getResults()) {
final LookupElement item = createLookupElement(completionElement, castTo);
if (item != null) {
set.add(highlightIfNeeded(castTo, castQualifier(project, item, castItem)));
LookupElement item1 = castQualifier(project, item, castItem);
set.add(highlightIfNeeded(castTo, item1, item1.getObject()));
}
}
return castTo;
@@ -706,11 +697,10 @@ public class JavaCompletionUtil {
});
}
private static LookupElement highlightIfNeeded(@NotNull PsiType qualifierType, @NotNull LookupElement item) {
Object o = item.getObject();
public static LookupElement highlightIfNeeded(PsiType qualifierType, LookupElement item, Object object) {
if (qualifierType instanceof PsiArrayType) {
if (o instanceof PsiField || o instanceof PsiMethod) { //length and clone()
PsiElement parent = ((PsiElement)o).getParent();
if (object instanceof PsiField || object instanceof PsiMethod) { //length and clone()
PsiElement parent = ((PsiElement)object).getParent();
if (parent instanceof PsiClass && parent.getContainingFile().getVirtualFile() == null) { //yes, they're a bit dummy
return highlight(item);
}
@@ -718,8 +708,8 @@ public class JavaCompletionUtil {
}
else if (qualifierType instanceof PsiClassType) {
PsiClass qualifierClass = ((PsiClassType)qualifierType).resolve();
if (o instanceof PsiField || o instanceof PsiMethod || o instanceof PsiClass) {
PsiElement parent = ((PsiElement)o).getParent();
if (object instanceof PsiField || object instanceof PsiMethod || object instanceof PsiClass) {
PsiClass parent = ((PsiMember)object).getContainingClass();
if (parent != null && parent.equals(qualifierClass)) {
return highlight(item);
}
@@ -728,14 +718,15 @@ public class JavaCompletionUtil {
return item;
}
private static LookupElementDecorator<LookupElement> highlight(LookupElement decorator) {
return LookupElementDecorator.withRenderer(decorator, new LookupElementRenderer<LookupElementDecorator<LookupElement>>() {
@Override
public void renderElement(LookupElementDecorator<LookupElement> element, LookupElementPresentation presentation) {
element.getDelegate().renderElement(presentation);
presentation.setItemTextBold(true);
}
});
private static LookupElement highlight(LookupElement decorator) {
return PrioritizedLookupElement.withGrouping(
LookupElementDecorator.withRenderer(decorator, new LookupElementRenderer<LookupElementDecorator<LookupElement>>() {
@Override
public void renderElement(LookupElementDecorator<LookupElement> element, LookupElementPresentation presentation) {
element.getDelegate().renderElement(presentation);
presentation.setItemTextBold(true);
}
}), 1);
}
private static LookupItem<?> createLookupElement(CompletionElement completionElement, PsiType qualifierType) {
@@ -974,7 +965,7 @@ public class JavaCompletionUtil {
if (smart || needRightParenth && addCompletionChar) {
TailType toInsert = tailType;
LookupItem lookupItem = item.as(LookupItem.class);
LookupItem lookupItem = item.as(LookupItem.CLASS_CONDITION_KEY);
if (lookupItem == null || lookupItem.getAttribute(LookupItem.TAIL_TYPE_ATTR) != TailType.UNKNOWN) {
if (!hasTail && item.getObject() instanceof PsiMethod && ((PsiMethod)item.getObject()).getReturnType() == PsiType.VOID) {
PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.lookup.*;
import com.intellij.codeInsight.lookup.impl.JavaElementLookupRenderer;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
@@ -34,6 +35,7 @@ import org.jetbrains.annotations.Nullable;
* @author peter
*/
public class JavaMethodCallElement extends LookupItem<PsiMethod> implements TypedLookupItem, StaticallyImportable {
public static final ClassConditionKey<JavaMethodCallElement> CLASS_CONDITION_KEY = ClassConditionKey.create(JavaMethodCallElement.class);
private static final Key<PsiSubstitutor> INFERENCE_SUBSTITUTOR = Key.create("INFERENCE_SUBSTITUTOR");
@Nullable private final PsiClass myContainingClass;
private final PsiMethod myMethod;
@@ -49,7 +49,7 @@ public class JavaMethodMergingContributor extends CompletionContributor {
}
final PsiMethod method = (PsiMethod)o;
final JavaChainLookupElement chain = item.as(JavaChainLookupElement.class);
final JavaChainLookupElement chain = item.as(JavaChainLookupElement.CLASS_CONDITION_KEY);
final String name = method.getName() + "#" + (chain == null ? "" : chain.getQualifier().getLookupString());
if (commonName != null && !commonName.equals(name)) {
return AutoCompletionDecision.SHOW_LOOKUP;
@@ -200,7 +200,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
final CompletionService service = CompletionService.getCompletionService();
new BasicExpressionCompletionContributor().fillCompletionVariants(parameters, service.createResultSet(parameters, new Consumer<LookupElement>() {
public void consume(final LookupElement lookupElement) {
final TypedLookupItem typed = JavaCompletionUtil.typedFrom(lookupElement);
final TypedLookupItem typed = lookupElement.as(TypedLookupItem.CLASS_CONDITION_KEY);
if (typed != null) {
final PsiType psiType = typed.getType();
if (psiType != null && type.isAssignableFrom(psiType)) {
@@ -21,7 +21,6 @@ import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiType;
import com.intellij.psi.PsiTypeParameter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author peter
@@ -29,13 +28,10 @@ import org.jetbrains.annotations.Nullable;
public class PreferNonGenericWeigher extends CompletionWeigher {
public Comparable weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) {
if (location == null) {
return null;
}
final Object object = item.getObject();
if (object instanceof PsiMethod) {
PsiType type = ((PsiMethod)object).getReturnType();
final JavaMethodCallElement callItem = item.as(JavaMethodCallElement.class);
final JavaMethodCallElement callItem = item.as(JavaMethodCallElement.CLASS_CONDITION_KEY);
if (callItem != null) {
type = callItem.getSubstitutor().substitute(type);
}
@@ -18,7 +18,6 @@ package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author peter
@@ -26,14 +25,11 @@ import org.jetbrains.annotations.Nullable;
public class PreferSimpleWeigher extends CompletionWeigher {
public Comparable weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) {
if (location == null) {
return null;
}
final PsiTypeLookupItem lookupItem = PsiTypeLookupItem.from(item);
final PsiTypeLookupItem lookupItem = item.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
if (lookupItem != null) {
return -lookupItem.getBracketsCount();
}
if (CastingLookupElementDecorator.from(item) != null) {
if (item.as(CastingLookupElementDecorator.CLASS_CONDITION_KEY) != null) {
return -239;
}
return 0;
@@ -23,7 +23,6 @@ import com.intellij.psi.filters.ElementFilter;
import com.intellij.psi.search.searches.DeepestSuperMethodsSearch;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author peter
@@ -38,16 +37,12 @@ public class RecursionWeigher extends CompletionWeigher {
}
public Result weigh(@NotNull final LookupElement element, @NotNull final CompletionLocation location) {
if (location == null) {
return null;
}
if (location.getCompletionType() != CompletionType.BASIC && location.getCompletionType() != CompletionType.SMART) return Result.normal;
final Object object = element.getObject();
if (!(object instanceof PsiModifierListOwner) && !(object instanceof PsiExpression)) return Result.normal;
if (!(object instanceof PsiMethod || object instanceof PsiVariable || object instanceof PsiExpression)) return Result.normal;
final PsiMethod positionMethod = JavaCompletionUtil.POSITION_METHOD.getValue(location);
if (positionMethod == null) return Result.normal;
final PsiElement position = location.getCompletionParameters().getPosition();
final ElementFilter filter = JavaCompletionUtil.recursionFilter(position);
@@ -66,7 +61,7 @@ public class RecursionWeigher extends CompletionWeigher {
return Result.passingObjectToItself;
}
if (expression != null) {
if (expression != null && positionMethod != null) {
final ExpectedTypeInfo[] expectedInfos = JavaCompletionUtil.EXPECTED_TYPES.getValue(location);
if (expectedInfos != null) {
final PsiType itemType = JavaCompletionUtil.getLookupElementType(element);
@@ -81,7 +76,7 @@ public class RecursionWeigher extends CompletionWeigher {
return Result.normal;
}
if (object instanceof PsiMethod) {
if (object instanceof PsiMethod && positionMethod != null) {
final PsiMethod method = (PsiMethod)object;
if (PsiTreeUtil.isAncestor(reference, position, false) &&
Comparing.equal(method.getName(), positionMethod.getName()) &&
@@ -167,7 +167,7 @@ public class ReferenceExpressionCompletionContributor {
}), false, parameters);
for (LookupElement lookupElement : elements) {
if (lookupElement.getObject() instanceof PsiMethod) {
final JavaMethodCallElement item = lookupElement.as(JavaMethodCallElement.class);
final JavaMethodCallElement item = lookupElement.as(JavaMethodCallElement.CLASS_CONDITION_KEY);
assert item != null;
final PsiMethod method = (PsiMethod)lookupElement.getObject();
if (SmartCompletionDecorator.hasUnboundTypeParams(method)) {
@@ -58,8 +58,9 @@ public class SmartCompletionDecorator extends TailTypeDecorator<LookupElement> {
return defType;
}
LookupElement item = getDelegate();
Object object = item.getObject();
LookupElement delegate = getDelegate();
LookupItem item = as(LookupItem.CLASS_CONDITION_KEY);
Object object = delegate.getObject();
if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && (object instanceof PsiMethod || object instanceof PsiClass)) {
return TailType.NONE;
}
@@ -67,8 +68,8 @@ public class SmartCompletionDecorator extends TailTypeDecorator<LookupElement> {
final PsiExpression enclosing = PsiTreeUtil.getContextOfType(myPosition, PsiExpression.class, true);
if (enclosing != null && object instanceof PsiElement) {
final PsiType type = getItemType(item);
final TailType itemType = item instanceof LookupItem ? ((LookupItem)item).getTailType() : TailType.NONE;
final PsiType type = JavaCompletionUtil.getLookupElementType(delegate);
final TailType itemType = item != null ? item.getTailType() : TailType.NONE;
TailType cached = itemType;
int cachedPrior = 0;
if (type != null && type.isValid()) {
@@ -108,11 +109,6 @@ public class SmartCompletionDecorator extends TailTypeDecorator<LookupElement> {
return null;
}
@Nullable
private PsiType getItemType(LookupElement element) {
return JavaCompletionUtil.getLookupElementType(element);
}
@Override
public void handleInsert(InsertionContext context) {
myPosition = getPosition(context, this);
@@ -108,7 +108,9 @@ public class HighlightSuppressedWarningsHandler extends HighlightUsagesHandlerBa
public void computeUsages(List<PsiLiteralExpression> targets) {
final Project project = myTarget.getProject();
final PsiElement parent = myTarget.getParent().getParent();
final LocalInspectionsPass pass = new LocalInspectionsPass(myFile, myFile.getViewProvider().getDocument(), parent.getTextRange().getStartOffset(), parent.getTextRange().getEndOffset());
final LocalInspectionsPass pass = new LocalInspectionsPass(myFile, myFile.getViewProvider().getDocument(),
parent.getTextRange().getStartOffset(), parent.getTextRange().getEndOffset(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE,
false);
final InspectionProfile inspectionProfile =
InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
for (PsiLiteralExpression target : targets) {
@@ -128,7 +130,7 @@ public class HighlightSuppressedWarningsHandler extends HighlightUsagesHandlerBa
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
Runnable inspect = new Runnable() {
public void run() {
pass.doInspectInBatch(managerEx, Collections.<InspectionProfileEntry>singletonList(tool), false);
pass.doInspectInBatch(managerEx, Collections.<InspectionProfileEntry>singletonList(tool));
}
};
if (indicator == null) {
@@ -18,9 +18,9 @@ package com.intellij.codeInsight.lookup;
import com.intellij.codeInsight.completion.DefaultInsertHandler;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.codeInsight.completion.JavaPsiClassReferenceElement;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.PsiClassReferenceType;
import com.intellij.psi.util.TypeConversionUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -29,6 +29,8 @@ import org.jetbrains.annotations.Nullable;
* @author peter
*/
public class PsiTypeLookupItem extends LookupItem {
public static final ClassConditionKey<PsiTypeLookupItem> CLASS_CONDITION_KEY = ClassConditionKey.create(PsiTypeLookupItem.class);
public PsiTypeLookupItem(Object o, @NotNull @NonNls String lookupString) {
super(o, lookupString);
}
@@ -130,16 +132,6 @@ public class PsiTypeLookupItem extends LookupItem {
}
return new LookupItem(type, type.getPresentableText());
}
public static @Nullable PsiTypeLookupItem from(LookupElement element) {
if (element instanceof PsiTypeLookupItem) return (PsiTypeLookupItem)element;
else if (element instanceof LookupElementDecorator) {
element = ((LookupElementDecorator)element).getDelegate();
if (element instanceof PsiTypeLookupItem) return (PsiTypeLookupItem)element;
}
return null;
}
@Override
public void renderElement(LookupElementPresentation presentation) {
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.lookup;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.Nullable;
@@ -22,6 +23,8 @@ import org.jetbrains.annotations.Nullable;
* @author peter
*/
public interface TypedLookupItem {
ClassConditionKey<TypedLookupItem> CLASS_CONDITION_KEY = ClassConditionKey.create(TypedLookupItem.class);
@Nullable
PsiType getType();
}
@@ -51,7 +51,7 @@ public class SuggestIndexNameMacro implements Macro{
for(char letter = 'i'; letter <= 'z'; letter++){
for (PsiVariable var : vars) {
PsiIdentifier identifier = var.getNameIdentifier();
if (place.equals(identifier)) continue;
if (identifier == null || place.equals(identifier)) continue;
if (var instanceof PsiLocalVariable) {
PsiElement parent = var.getParent();
if (parent instanceof PsiDeclarationStatement) {
@@ -18,15 +18,8 @@ package com.intellij.codeInspection.inferNullity;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.NullableNotNullManager;
import com.intellij.codeInsight.intention.AddAnnotationFix;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.psi.*;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.searches.OverridingMethodsSearch;
@@ -43,16 +36,12 @@ import java.util.Collection;
import java.util.HashSet;
public class NullityInferrer {
private static final Logger LOG = Logger.getInstance("#" + NullityInferrer.class.getName());
private static final int MAX_PASSES = 10;
private int numAnnotationsAdded = 0;
private final HashSet<SmartPsiElementPointer<? extends PsiModifierListOwner>> myNotNullSet =
new HashSet<SmartPsiElementPointer<? extends PsiModifierListOwner>>();
private final HashSet<SmartPsiElementPointer<? extends PsiModifierListOwner>> myNullableSet =
new HashSet<SmartPsiElementPointer<? extends PsiModifierListOwner>>();
private boolean myAnnotateLocalVariables;
private SmartPointerManager myPointerManager;
private final HashSet<SmartPsiElementPointer<? extends PsiModifierListOwner>> myNotNullSet = new HashSet<SmartPsiElementPointer<? extends PsiModifierListOwner>>();
private final HashSet<SmartPsiElementPointer<? extends PsiModifierListOwner>> myNullableSet = new HashSet<SmartPsiElementPointer<? extends PsiModifierListOwner>>();
private final boolean myAnnotateLocalVariables;
private final SmartPointerManager myPointerManager;
public NullityInferrer(boolean annotateLocalVariables, Project project) {
@@ -260,11 +249,7 @@ public class NullityInferrer {
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
final PsiMethod method = expression.resolveMethod();
if (method == null) {
neverNull = false;
} else {
neverNull = isNotNull(method);
}
neverNull = method != null && isNotNull(method);
}
private boolean isNeverNull() {
@@ -154,7 +154,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
}
}
if (getConstructors().size() == 0 && !isInterface() && !isAnonymous()) {
if (getConstructors().isEmpty() && !isInterface() && !isAnonymous()) {
RefImplicitConstructorImpl refImplicitConstructor = new RefImplicitConstructorImpl(this);
setDefaultConstructor(refImplicitConstructor);
addConstructor(refImplicitConstructor);
@@ -173,7 +173,12 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
final PsiClass applet = getRefJavaManager().getApplet();
setApplet(applet != null && psiClass.isInheritor(applet, true));
getRefManager().fireNodeInitialized(this);
getRefManager().getPsiManager().dropResolveCaches();
PsiManager psiManager = getRefManager().getPsiManager();
psiManager.dropResolveCaches();
PsiFile file = psiClass.getContainingFile();
if (file != null) {
psiManager.dropFileCaches(file);
}
}
private void initializeSuperReferences(PsiClass psiClass) {
@@ -434,7 +439,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
if (super.isReferenced()) return true;
if (isInterface() || isAbstract()) {
if (getSubClasses().size() > 0) return true;
if (!getSubClasses().isEmpty()) return true;
}
return false;
@@ -444,7 +449,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
if (super.hasSuspiciousCallers()) return true;
if (isInterface() || isAbstract()) {
if (getSubClasses().size() > 0) return true;
if (!getSubClasses().isEmpty()) return true;
}
return false;
@@ -670,23 +670,22 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx implements Disposable {
if (element instanceof PsiFileSystemItem) {
return false;
}
if (element == null || element.getParent() == null) return true;
while(true){
if (element instanceof PsiFile || element instanceof PsiDirectory || element == null){
PsiElement parent = element;
while (true) {
if (parent instanceof PsiFile || parent instanceof PsiDirectory || parent == null) {
return false;
}
PsiElement pparent = element.getParent();
if (element instanceof PsiClass) return false; // anonymous or local class
if (element instanceof PsiCodeBlock){
if (pparent instanceof PsiMethod || pparent instanceof PsiClassInitializer){
if (parent instanceof PsiClass) return false; // anonymous or local class
if (parent instanceof PsiModifiableCodeBlock) {
if (!((PsiModifiableCodeBlock)parent).shouldChangeModificationCount(element)) {
return true;
}
}
element = pparent;
parent = parent.getParent();
}
}
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.psi.impl.light;
import com.intellij.lang.StdLanguages;
import com.intellij.psi.*;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.util.IncorrectOperationException;
@@ -40,7 +41,7 @@ public class LightFieldBuilder extends LightVariableBuilder<LightFieldBuilder> i
}
public LightFieldBuilder(PsiManager manager, @NotNull String name, @NotNull PsiType type) {
super(manager, name, type);
super(manager, name, type, StdLanguages.JAVA);
}
public LightFieldBuilder setContainingClass(PsiClass psiClass) {
@@ -180,7 +180,7 @@ public class LightMethodBuilder extends LightElement implements PsiMethod {
}
public LightMethodBuilder addParameter(@NotNull String name, @NotNull PsiType type) {
return addParameter(new LightParameter(name, type, this));
return addParameter(new LightParameter(name, type, this, StdLanguages.JAVA));
}
@NotNull
@@ -1,5 +1,6 @@
package com.intellij.psi.impl.light;
import com.intellij.lang.Language;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
@@ -11,8 +12,8 @@ public class LightParameter extends LightVariableBuilder implements PsiParameter
private final String myName;
private final PsiElement myDeclarationScope;
public LightParameter(@NotNull String name, @NotNull PsiType type, PsiElement declarationScope) {
super(declarationScope.getManager(), name, type);
public LightParameter(@NotNull String name, @NotNull PsiType type, PsiElement declarationScope, Language language) {
super(declarationScope.getManager(), name, type, language);
myName = name;
myDeclarationScope = declarationScope;
}
@@ -1,5 +1,6 @@
package com.intellij.psi.impl.light;
import com.intellij.lang.Language;
import com.intellij.lang.StdLanguages;
import com.intellij.psi.*;
import com.intellij.psi.impl.ElementPresentationUtil;
@@ -25,12 +26,12 @@ public class LightVariableBuilder<T extends LightVariableBuilder> extends LightE
}
public LightVariableBuilder(@NotNull String name, @NotNull PsiType type, @NotNull PsiElement navigationElement) {
this(navigationElement.getManager(), name, type);
this(navigationElement.getManager(), name, type, StdLanguages.JAVA);
setNavigationElement(navigationElement);
}
public LightVariableBuilder(PsiManager manager, @NotNull String name, @NotNull PsiType type) {
super(manager, StdLanguages.JAVA);
public LightVariableBuilder(PsiManager manager, @NotNull String name, @NotNull PsiType type, Language language) {
super(manager, language);
myName = name;
myType = type;
myModifierList = new LightModifierList(manager);
@@ -15,12 +15,11 @@
*/
package com.intellij.psi.impl.smartPointers;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiIdentifier;
import com.intellij.psi.PsiJavaCodeReferenceElement;
import com.intellij.psi.xml.XmlToken;
import com.intellij.psi.xml.XmlTokenType;
import org.jetbrains.annotations.NotNull;
@@ -29,72 +28,21 @@ import org.jetbrains.annotations.Nullable;
/**
* User: cdr
*/
class AnchorElementInfo implements SmartPointerElementInfo {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.smartPointers.AnchorElementInfo");
private PsiFile myFile;
private final RangeMarker myMarker;
private int mySyncStartOffset;
private int mySyncEndOffset;
private boolean mySyncMarkerIsValid;
private final Project myProject;
AnchorElementInfo(@NotNull PsiElement anchor) {
LOG.assertTrue(anchor.isPhysical());
LOG.assertTrue(anchor.isValid());
myFile = anchor.getContainingFile();
myProject = myFile.getProject();
TextRange range = anchor.getTextRange();
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
Document document = documentManager.getDocument(myFile);
LOG.assertTrue(!documentManager.isUncommited(document));
if (myFile.getTextLength() != document.getTextLength()) {
final String docText = document.getText();
myFile.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
super.visitElement(element);
TextRange elementRange = element.getTextRange();
final String rangeText = docText.length() <= elementRange.getEndOffset() ? "(IOOBE: "+docText.length()+" is out of "+elementRange+")" : elementRange.substring(docText);
final String elemText = element.getText();
if (!rangeText.equals(elemText)) {
throw new AssertionError("PSI text doesn't equal to the document's one: element" + element + "\ndocText=" + rangeText + "\npsiText" + elemText);
}
}
});
LOG.error("File=" + myFile);
}
myMarker = document.createRangeMarker(range.getStartOffset(), range.getEndOffset(), true);
mySyncStartOffset = range.getStartOffset();
mySyncEndOffset = range.getEndOffset();
mySyncMarkerIsValid = true;
}
public Document getDocumentToSynchronize() {
return myMarker.getDocument();
}
public void documentAndPsiInSync() {
if (!myMarker.isValid()) {
mySyncMarkerIsValid = false;
return;
}
mySyncStartOffset = myMarker.getStartOffset();
mySyncEndOffset = myMarker.getEndOffset();
class AnchorElementInfo extends SelfElementInfo {
AnchorElementInfo(@NotNull PsiElement anchor, PsiFile containingFile) {
super(anchor, containingFile);
}
@Nullable
public PsiElement restoreElement() {
if (!mySyncMarkerIsValid) return null;
myFile = SelfElementInfo.restoreFile(myFile, myProject);
if (myFile == null) return null;
PsiElement anchor = myFile.findElementAt(mySyncStartOffset);
PsiFile file = SelfElementInfo.restoreFileFromVirtual(myVirtualFile, myProject);
if (file == null) return null;
PsiElement anchor = file.findElementAt(getSyncStartOffset());
if (anchor == null) return null;
TextRange range = anchor.getTextRange();
if (range.getStartOffset() != mySyncStartOffset || range.getEndOffset() != mySyncEndOffset) return null;
if (range.getStartOffset() != getSyncStartOffset() || range.getEndOffset() != getSyncEndOffset()) return null;
if (anchor instanceof PsiIdentifier) {
PsiElement parent = anchor.getParent();
@@ -106,20 +54,10 @@ class AnchorElementInfo implements SmartPointerElementInfo {
return parent;
}
else if (anchor instanceof XmlToken) {
if (anchor instanceof XmlToken) {
XmlToken token = (XmlToken)anchor;
return token.getTokenType() == XmlTokenType.XML_NAME ? token.getParent() : null;
}
else {
return null;
}
}
@Override
public void dispose() {
if (myMarker != null) {
myMarker.dispose();
}
return null;
}
}
@@ -29,7 +29,7 @@ public class AnchorElementInfoFactory implements SmartPointerElementInfoFactory
public SmartPointerElementInfo createElementInfo(@NotNull PsiElement element) {
PsiElement anchor = getAnchor(element);
if (anchor != null) {
return new AnchorElementInfo(anchor);
return new AnchorElementInfo(anchor, element.getContainingFile());
}
return null;
}
@@ -55,7 +55,7 @@ public class AnchorElementInfoFactory implements SmartPointerElementInfoFactory
else if (element instanceof XmlTag) {
anchor = XmlTagUtil.getStartTagNameElement((XmlTag)element);
}
if (anchor != null && !anchor.isPhysical()) return null;
if (anchor != null && (!anchor.isPhysical() || anchor.getTextRange()==null)) return null;
return anchor;
}
@@ -15,15 +15,20 @@
*/
package com.intellij.psi.impl.smartPointers;
import org.jetbrains.annotations.Nullable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.ImplicitVariable;
import com.intellij.psi.PsiIdentifier;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Segment;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.ImplicitVariable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiIdentifier;
import com.intellij.psi.util.PsiUtilBase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ImplicitVariableElementInfoFactory implements SmartPointerElementInfoFactory {
@Nullable
public SmartPointerElementInfo createElementInfo(final PsiElement element) {
public SmartPointerElementInfo createElementInfo(@NotNull final PsiElement element) {
if (element instanceof ImplicitVariable) {
return new ImplicitVariableInfo((ImplicitVariable) element);
}
@@ -54,5 +59,38 @@ public class ImplicitVariableElementInfoFactory implements SmartPointerElementIn
public void documentAndPsiInSync() {
}
@Override
public void fastenBelt(int offset) {
}
@Override
public void unfastenBelt(int offset) {
}
@Override
public int elementHashCode() {
return myVar.hashCode();
}
@Override
public boolean pointsToTheSameElementAs(SmartPointerElementInfo other) {
if (other instanceof ImplicitVariableInfo) {
return myVar == ((ImplicitVariableInfo)other).myVar;
}
return Comparing.equal(restoreElement(), other.restoreElement());
}
@Override
public VirtualFile getVirtualFile() {
return PsiUtilBase.getVirtualFile(myVar);
}
@Override
public Segment getSegment() {
PsiIdentifier psiIdentifier = myVar.getNameIdentifier();
if (psiIdentifier == null || !psiIdentifier.isValid()) return null;
return psiIdentifier.getTextRange();
}
}
}
@@ -15,42 +15,30 @@
*/
package com.intellij.psi.impl.smartPointers;
import org.jetbrains.annotations.Nullable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiJavaFile;
import com.intellij.psi.PsiImportList;
import com.intellij.openapi.editor.Document;
import com.intellij.psi.PsiJavaFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ImportListElementInfoFactory implements SmartPointerElementInfoFactory {
@Nullable
public SmartPointerElementInfo createElementInfo(final PsiElement element) {
public SmartPointerElementInfo createElementInfo(@NotNull final PsiElement element) {
if (element instanceof PsiImportList) {
return new ImportListInfo((PsiJavaFile)element.getContainingFile());
}
return null;
}
private static class ImportListInfo implements SmartPointerElementInfo {
private final PsiJavaFile myFile;
public ImportListInfo(PsiJavaFile file) {
myFile = file;
private static class ImportListInfo extends FileElementInfo {
public ImportListInfo(@NotNull PsiJavaFile file) {
super(file);
}
public PsiElement restoreElement() {
if (!myFile.isValid()) return null;
return myFile.getImportList();
}
@Override
public void dispose() {
}
public Document getDocumentToSynchronize() {
return null;
}
public void documentAndPsiInSync() {
PsiElement element = super.restoreElement();
if (!(element instanceof PsiJavaFile)) return null;
return ((PsiJavaFile)element).getImportList();
}
}
}
@@ -221,4 +221,9 @@ public class PsiCodeBlockImpl extends LazyParseablePsiElement implements PsiCode
}
return true;
}
public boolean shouldChangeModificationCount(PsiElement place) {
PsiElement pparent = getParent();
return !(pparent instanceof PsiMethod || pparent instanceof PsiClassInitializer);
}
}
@@ -227,6 +227,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
final PsiMethod caller = RefactoringUtil.getEnclosingMethod(ref);
if (toChangeArguments) {
final PsiExpressionList list = RefactoringUtil.getArgumentListByMethodReference(ref);
LOG.assertTrue(list != null);
boolean toInsertDefaultValue = needDefaultValue(changeInfo, caller);
if (toInsertDefaultValue && ref instanceof PsiReferenceExpression) {
final PsiExpression qualifierExpression = ((PsiReferenceExpression)ref).getQualifierExpression();
@@ -209,7 +209,7 @@ class JavaChangeSignatureUsageSearcher {
if (!isToCatchExceptions) {
if (RefactoringUtil.isMethodUsage(element)) {
PsiExpressionList list = RefactoringUtil.getArgumentListByMethodReference(element);
if (!method.isVarArgs() && list.getExpressions().length != parameterCount) continue;
if (list == null || !method.isVarArgs() && list.getExpressions().length != parameterCount) continue;
}
}
if (RefactoringUtil.isMethodUsage(element)) {
@@ -46,6 +46,7 @@ import com.intellij.refactoring.util.RefactoringMessageUtil;
import com.intellij.ui.RecentsManager;
import com.intellij.ui.ReferenceEditorComboWithBrowseButton;
import com.intellij.ui.StateRestoringCheckBox;
import com.intellij.usageView.UsageViewUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ui.UIUtil;
import gnu.trove.THashSet;
@@ -396,6 +397,9 @@ class IntroduceConstantDialog extends DialogWrapper {
errorString = RefactoringBundle.message("no.field.name.specified");
} else if (!JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(fieldName)) {
errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName);
} else if (!myParentClass.getLanguage().equals(newClass.getLanguage())) {
errorString = RefactoringBundle.message("move.to.different.language", UsageViewUtil.getType(myParentClass),
myParentClass.getQualifiedName(), newClass.getQualifiedName());
}
if (errorString != null) {
CommonRefactoringUtil.showErrorMessage(
@@ -60,6 +60,7 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
final PsiElement ref = usage.getElement();
PsiCall callExpression = RefactoringUtil.getCallExpressionByMethodReference(ref);
PsiExpressionList argList = RefactoringUtil.getArgumentListByMethodReference(ref);
if (argList == null) return true;
PsiExpression[] oldArgs = argList.getExpressions();
final PsiExpression anchor;
@@ -261,4 +262,4 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
processChangeMethodUsage(data, new ExternalUsageInfo(((PsiMethodCallExpression)superCall.getExpression()).getMethodExpression()), usages);
return false;
}
}
}
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.ExpectedTypesProvider;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
import com.intellij.codeInsight.highlighting.HighlightManager;
import com.intellij.lang.StdLanguages;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
@@ -618,7 +619,9 @@ public class RefactoringUtil {
}
public static boolean isMethodUsage(PsiElement element) {
if (element instanceof PsiEnumConstant) return true;
if (element instanceof PsiEnumConstant) {
return StdLanguages.JAVA.equals(element.getLanguage());
}
if (!(element instanceof PsiJavaCodeReferenceElement)) return false;
PsiElement parent = element.getParent();
if (parent instanceof PsiCall) {
@@ -630,6 +633,7 @@ public class RefactoringUtil {
return false;
}
@Nullable
public static PsiExpressionList getArgumentListByMethodReference(PsiElement ref) {
if (ref instanceof PsiEnumConstant) return ((PsiEnumConstant)ref).getArgumentList();
PsiElement parent = ref.getParent();
@@ -100,20 +100,16 @@ public class ClassGroupingRule implements UsageGroupingRule {
private final SmartPsiElementPointer myClassPointer;
private final String myText;
private final String myQName;
private Icon myIcon;
private final Icon myIcon;
public ClassUsageGroup(PsiClass aClass) {
myQName = aClass.getQualifiedName();
myText = createText(aClass);
SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(aClass.getProject());
myClassPointer = smartPointerManager.createLazyPointer(aClass);
update();
myClassPointer = SmartPointerManager.getInstance(aClass.getProject()).createSmartPsiElementPointer(aClass);
myIcon = getPsiClass().getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
}
public void update() {
if (isValid()) {
myIcon = getPsiClass().getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
}
}
private static String createText(PsiClass aClass) {
@@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Iconable;
import com.intellij.openapi.util.Segment;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
@@ -69,7 +70,7 @@ public class MethodGroupingRule implements UsageGroupingRule {
private static class MethodUsageGroup implements UsageGroup, TypeSafeDataProvider {
private final SmartPsiElementPointer<PsiMethod> myMethodPointer;
private final String myName;
private Icon myIcon;
private final Icon myIcon;
private final Project myProject;
public MethodUsageGroup(PsiMethod psiMethod) {
@@ -80,15 +81,12 @@ public class MethodGroupingRule implements UsageGroupingRule {
PsiFormatUtilBase.SHOW_TYPE
);
myProject = psiMethod.getProject();
myMethodPointer = SmartPointerManager.getInstance(myProject).createLazyPointer(psiMethod);
myMethodPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(psiMethod);
myIcon = getIconImpl(psiMethod);
}
public void update() {
if (isValid()) {
myIcon = getIconImpl(getMethod());
}
}
private static Icon getIconImpl(PsiMethod psiMethod) {
@@ -104,10 +102,8 @@ public class MethodGroupingRule implements UsageGroupingRule {
return false;
}
MethodUsageGroup group = (MethodUsageGroup) object;
if (isValid() && group.isValid()) {
return getMethod().getManager().areElementsEquivalent(getMethod(), group.getMethod());
}
return Comparing.equal(myName, ((MethodUsageGroup)object).myName);
return Comparing.equal(myName, ((MethodUsageGroup)object).myName)
&& SmartPointerManager.getInstance(myProject).pointToTheSameElement(myMethodPointer, group.myMethodPointer);
}
public Icon getIcon(boolean isOpen) {
@@ -151,10 +147,15 @@ public class MethodGroupingRule implements UsageGroupingRule {
LOG.error("MethodUsageGroup expected but " + usageGroup.getClass() + " found");
}
MethodUsageGroup other = (MethodUsageGroup)usageGroup;
PsiMethod myMethod = myMethodPointer.getElement();
PsiMethod otherMethod = other.myMethodPointer.getElement();
if (myMethod != null && otherMethod != null && !UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY) {
return myMethod.getTextOffset() < otherMethod.getTextOffset() ? -1 : 1;
if (SmartPointerManager.getInstance(myProject).pointToTheSameElement(myMethodPointer, other.myMethodPointer)) {
return 0;
}
if (!UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY) {
Segment segment1 = myMethodPointer.getSegment();
Segment segment2 = other.myMethodPointer.getSegment();
if (segment1 != null && segment2 != null) {
return segment1.getStartOffset() - segment2.getStartOffset();
}
}
return myName.compareTo(other.myName);
@@ -17,13 +17,18 @@
package com.intellij.util.xml;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.ClassKind;
import com.intellij.psi.xml.XmlElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -97,7 +102,16 @@ public class PsiClassConverter extends Converter<PsiClass> implements CustomRefe
@Nullable
protected GlobalSearchScope getScope(final GenericDomValue domValue) {
final Module module = domValue.getModule();
return module == null ? null : GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
if (module == null) return null;
XmlElement element = domValue.getXmlElement();
if (element == null) return null;
PsiFile file = element.getContainingFile();
if (file == null) return null;
file = file.getOriginalFile();
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) return null;
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(file.getProject()).getFileIndex();
return GlobalSearchScope.moduleRuntimeScope(module, fileIndex.isInTestSourceContent(virtualFile));
}
public static class AnnotationType extends PsiClassConverter {
@@ -0,0 +1,7 @@
import foo.Foo;
class Bar {
{
Foo.foo(Foo<caret>x)
}
}
@@ -0,0 +1,15 @@
class Foo {
void fromSuper() {}
void overridden() {}
}
class FooImpl extends Foo {
void overridden() {}
void fromThis() {}
}
class Bar {
{
new FooImpl().<caret>
}
}
@@ -444,4 +444,37 @@ class JavaAutoPopupTest extends CompletionAutoPopupTestCase {
assert !lookup
}
public void testResumeAfterBackspace() {
myFixture.configureByText("a.java", """
class A {
Object foo() { this<caret> }
}
""")
type '.'
assert lookup
type 'a'
assert !lookup
type '\b'
assert !lookup
type 'c'
assert lookup
}
public void testHideOnInvalidSymbolAfterBackspace() {
myFixture.configureByText("a.java", """
class A {
Object foo() { this<caret> }
}
""")
type '.'
assert lookup
type 'c'
assert lookup
type '\b'
assert lookup
type 'x'
assert !lookup
}
}
@@ -160,4 +160,19 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
assertEquals("Foooo.Bar", presentation.getItemText());*/
}
public void testClassInCallOfItsMethod() throws Throwable {
final VirtualFile foo = getSourceRoot().createChildDirectory(this, "foo");
VfsUtil.saveText(foo.createChildData(this, "Foo.java"), "package foo; public interface Foo {}");
final VirtualFile bar = getSourceRoot().createChildDirectory(this, "bar");
VfsUtil.saveText(bar.createChildData(this, "Foo.java"), "package bar; public interface Foo {}");
checkPreferredItems(0, "Foo", "Foo");
assertEquals("foo.Foo", ((JavaPsiClassReferenceElement)getLookup().getCurrentItem()).getQualifiedName());
}
public void testDeclaredMembersGoFirst() throws Exception {
invokeCompletion(getBasePath() + "/" + getTestName(false) + ".java");
assertStringItems("fromThis", "overridden", "fromSuper", "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait", "wait", "wait");
}
}
@@ -194,7 +194,7 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
}
public void testFactoryMethodForDefaultType() throws Throwable {
checkPreferredItems(0, "create", "map", "this", "getClass");
checkPreferredItems(0, "create", "this", "map", "getClass");
}
public void testLocalVarsBeforeClassLiterals() throws Throwable {
@@ -37,7 +37,7 @@ import com.intellij.psi.JavaDirectoryService;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiJavaFile;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.PlatformTestUtil;
import javax.swing.*;
import java.io.IOException;
@@ -56,16 +56,16 @@ public class NavigateFromSourceTest extends BaseProjectViewTestCase {
checkNavigateFromSourceBehaviour(psiClass, virtualFile, pane);
IdeaTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" +
" -PsiDirectory: showClassMembers\n" +
" -PsiDirectory: src\n" +
" -PsiDirectory: com\n" +
" -PsiDirectory: package1\n" +
" [Class1]\n" +
" Class2\n" +
getRootFiles() +
" +External Libraries\n"
, true);
PlatformTestUtil.assertTreeEqual(pane.getTree(), "-Project\n" +
" -PsiDirectory: showClassMembers\n" +
" -PsiDirectory: src\n" +
" -PsiDirectory: com\n" +
" -PsiDirectory: package1\n" +
" [Class1]\n" +
" Class2\n" +
getRootFiles() +
" +External Libraries\n"
, true);
changeClassTextAndTryToNavigate("class Class11 {}", (PsiJavaFile)containingFile, pane, "-Project\n" +
" -PsiDirectory: showClassMembers\n" +
@@ -102,19 +102,20 @@ public class NavigateFromSourceTest extends BaseProjectViewTestCase {
assertEquals(1, tree.getSelectionCount());
}
private void changeClassTextAndTryToNavigate(final String newClassString,
PsiJavaFile psiFile,
final AbstractProjectViewPSIPane pane,
final String expected) throws IOException, InterruptedException {
private static void changeClassTextAndTryToNavigate(final String newClassString,
PsiJavaFile psiFile,
final AbstractProjectViewPSIPane pane,
final String expected) throws IOException, InterruptedException {
PsiClass psiClass = psiFile.getClasses()[0];
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
final JTree tree = pane.getTree();
writeToFile(virtualFile, newClassString.getBytes());
IdeaTestUtil.waitForAlarm(600);
PlatformTestUtil.waitForAlarm(600);
psiClass = psiFile.getClasses()[0];
pane.select(psiClass, virtualFile, true);
IdeaTestUtil.assertTreeEqual(tree, expected, true);
PlatformTestUtil.assertTreeEqual(tree, expected, true);
}
private static void writeToFile(final VirtualFile virtualFile, final byte[] b) throws IOException {
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Represents a Java code block, usually surrounded by curly braces.
*/
public interface PsiCodeBlock extends PsiElement {
public interface PsiCodeBlock extends PsiElement, PsiModifiableCodeBlock {
/**
* The empty array of PSI code blocks which can be reused to avoid unnecessary allocations.
*/
@@ -0,0 +1,28 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi;
/**
* Represents psi element, which can be modified without caches reset.
* @see com.intellij.psi.util.PsiModificationTracker#getOutOfCodeBlockModificationCount()
*/
public interface PsiModifiableCodeBlock {
/**
* @param place where change was detected
* @return false if specific caches could be saved after the change
*/
boolean shouldChangeModificationCount(PsiElement place);
}
@@ -16,6 +16,9 @@
package com.intellij.util.xml;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
@@ -32,7 +35,7 @@ public class DomJavaUtil {
}
@Nullable
public static PsiClass findClass(@Nullable String name, @NotNull final PsiFile file, @Nullable final Module module, @Nullable final GlobalSearchScope searchScope) {
public static PsiClass findClass(@Nullable String name, @NotNull PsiFile file, @Nullable final Module module, @Nullable final GlobalSearchScope searchScope) {
if (name == null) return null;
if (name.indexOf('$')>=0) name = name.replace('$', '.');
@@ -40,7 +43,15 @@ public class DomJavaUtil {
if (searchScope == null) {
if (module != null) {
scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
file = file.getOriginalFile();
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
scope = GlobalSearchScope.moduleRuntimeScope(module, true);
}
else {
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(file.getProject()).getFileIndex();
scope = GlobalSearchScope.moduleRuntimeScope(module, fileIndex.isInTestSourceContent(virtualFile));
}
}
else {
scope = file.getResolveScope();
@@ -19,6 +19,7 @@ import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiModificationTrackerImpl;
import com.intellij.psi.search.ProjectScope;
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture;
@@ -51,7 +52,7 @@ public class JavaCodeInsightTestFixtureImpl extends CodeInsightTestFixtureImpl i
return psiClass;
}
private PsiClass addClass(@NonNls final String rootPath, @NotNull @NonNls final String classText) throws IOException {
private PsiClass addClass(@NonNls final String rootPath, @NotNull @NonNls final String classText) {
final PsiClass aClass = ((PsiJavaFile)PsiFileFactory.getInstance(getProject()).createFileFromText("a.java", classText)).getClasses()[0];
final String qName = aClass.getQualifiedName();
assert qName != null;
@@ -65,6 +66,13 @@ public class JavaCodeInsightTestFixtureImpl extends CodeInsightTestFixtureImpl i
return ((PsiJavaFile)psiFile).getClasses()[0];
}
@Override
protected PsiFile addFileToProject(String rootPath, String relativePath, String fileText) {
PsiFile file = super.addFileToProject(rootPath, relativePath, fileText);
((PsiModificationTrackerImpl)PsiManager.getInstance(getProject()).getModificationTracker()).incCounter();
return file;
}
@Override
@NotNull
public PsiClass findClass(@NotNull @NonNls final String name) {
Binary file not shown.
+1 -1
View File
@@ -16,7 +16,7 @@
<orderEntry type="library" scope="TEST" name="JMock1" level="project" />
<orderEntry type="library" scope="TEST" name="asm" level="project" />
<orderEntry type="library" scope="TEST" name="CGLIB" level="project" />
<orderEntry type="library" name="Mocks" level="project" />
<orderEntry type="library" scope="TEST" name="Mocks" level="project" />
</component>
<component name="copyright">
<Base>
@@ -125,22 +125,21 @@ public class ExtensionPointImpl<T> implements ExtensionPoint<T> {
private void internalRegisterExtension(T extension, ExtensionComponentAdapter adapter, int index, boolean runNotifications) {
if (myExtensions.contains(extension)) {
myLogger.error("Extension was already added: " + extension);
return;
}
else {
myExtensions.add(index, extension);
myLoadedAdapters.add(index, adapter);
if (runNotifications) {
if (extension instanceof Extension) {
try {
((Extension)extension).extensionAdded(this);
}
catch (Throwable e) {
myLogger.error(e);
}
myExtensions.add(index, extension);
myLoadedAdapters.add(index, adapter);
if (runNotifications) {
if (extension instanceof Extension) {
try {
((Extension)extension).extensionAdded(this);
}
catch (Throwable e) {
myLogger.error(e);
}
notifyListenersOnAdd(extension, adapter.getPluginDescriptor());
}
notifyListenersOnAdd(extension, adapter.getPluginDescriptor());
}
}
@@ -163,31 +162,28 @@ public class ExtensionPointImpl<T> implements ExtensionPoint<T> {
result = myExtensionsCache;
if (result == null) {
processAdapters();
List<T> extensions = new ArrayList<T>(myExtensions);
List<T> problemExtensions = new ArrayList<T>();
final Class<T> extensionClass = getExtensionClass();
for (Iterator<T> iterator = extensions.iterator(); iterator.hasNext();) {
T t = iterator.next();
//noinspection unchecked
result = myExtensions.toArray((T[])Array.newInstance(extensionClass, myExtensions.size()));
for (int i = result.length - 1; i >= 0; i--) {
T t = result[i];
if (i > 0 && result[i] == result[i - 1]) {
LOG.error("Duplicate extension found: " + t + "; " +
" Result: "+ Arrays.asList(result)+";\n" +
" extensions: "+ myExtensions+";\n" +
" getExtensionClass(): "+ extensionClass +";\n" +
" size:"+myExtensions.size()+";"+result.length);
}
if (!extensionClass.isAssignableFrom(t.getClass())) {
problemExtensions.add(t);
iterator.remove();
LOG.error("Extension '" + t.getClass() + "' must be an instance of '" + extensionClass + "'",
new ExtensionException(t.getClass()));
result = ArrayUtil.remove(result, i); // we assume that usually all extensions are OK
}
}
for (T problemExtension : problemExtensions) {
LOG.error("Extension '" + problemExtension.getClass() + "' should be instance of '" + extensionClass + "'", new ExtensionException(problemExtension.getClass()));
}
//noinspection unchecked
myExtensionsCache = result = extensions.toArray((T[])Array.newInstance(extensionClass, extensions.size()));
for (int i = 1; i < result.length; i++) {
assert result[i] != result[i - 1] : "Result: "+ Arrays.asList(result)+";\n" +
" extensions: "+ extensions+";\n" +
" getExtensionClass(): "+ extensionClass +";\n" +
" size:"+extensions.size()+";"+result.length;
}
myExtensionsCache = result;
}
}
}
@@ -341,18 +341,23 @@ public class AnalysisScope {
if (needReadAction) {
PsiDocumentManager.getInstance(psiManager.getProject()).commitAndRunReadAction(new Runnable(){
public void run() {
file.accept(visitor);
psiManager.dropResolveCaches();
doProcessFile(visitor, psiManager, file);
}
});
} else {
file.accept(visitor);
psiManager.dropResolveCaches();
}
else {
doProcessFile(visitor, psiManager, file);
}
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
return indicator == null || !indicator.isCanceled();
}
private static void doProcessFile(PsiElementVisitor visitor, PsiManager psiManager, PsiFile file) {
file.accept(visitor);
psiManager.dropResolveCaches();
psiManager.dropFileCaches(file);
}
protected void accept(@NotNull final PsiDirectory dir, @NotNull final PsiElementVisitor visitor, final boolean needReadAction) {
final Project project = dir.getProject();
final PsiManager psiManager = PsiManager.getInstance(project);
@@ -18,7 +18,7 @@ package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementDecorator;
import org.jetbrains.annotations.Nullable;
import com.intellij.openapi.util.ClassConditionKey;
/**
* Use only when you want to control lookup sorting & preference in simple cases when you have control over ALL the items in lookup.
@@ -28,6 +28,7 @@ import org.jetbrains.annotations.Nullable;
* @author peter
*/
public class PrioritizedLookupElement<T extends LookupElement> extends LookupElementDecorator<T> {
public static final ClassConditionKey<PrioritizedLookupElement> CLASS_CONDITION_KEY = ClassConditionKey.create(PrioritizedLookupElement.class);
private final double myPriority;
private final int myGrouping;
@@ -46,18 +47,12 @@ public class PrioritizedLookupElement<T extends LookupElement> extends LookupEle
}
public static LookupElement withPriority(LookupElement element, double priority) {
final PrioritizedLookupElement prioritized = PrioritizedLookupElement.from(element);
final PrioritizedLookupElement prioritized = element.as(CLASS_CONDITION_KEY);
return new PrioritizedLookupElement<LookupElement>(element, priority, prioritized == null ? 0 : prioritized.getGrouping());
}
public static LookupElement withGrouping(LookupElement element, int grouping) {
final PrioritizedLookupElement prioritized = PrioritizedLookupElement.from(element);
final PrioritizedLookupElement prioritized = element.as(CLASS_CONDITION_KEY);
return new PrioritizedLookupElement<LookupElement>(element, prioritized == null ? 0 : prioritized.getPriority(), grouping);
}
public static @Nullable PrioritizedLookupElement from(LookupElement element) {
if (element instanceof PrioritizedLookupElement) return (PrioritizedLookupElement)element;
if (element instanceof LookupElementDecorator) return from (((LookupElementDecorator)element).getDelegate());
return null;
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.lookup;
import com.intellij.openapi.util.ClassConditionKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -56,7 +57,7 @@ public enum AutoCompletionPolicy {
@Nullable
public static AutoCompletionPolicy getPolicy(LookupElement element) {
final PolicyDecorator decorator = element.as(PolicyDecorator.class);
final PolicyDecorator decorator = element.as(PolicyDecorator.CLASS_CONDITION_KEY);
if (decorator != null) {
return decorator.myPolicy;
}
@@ -64,6 +65,7 @@ public enum AutoCompletionPolicy {
}
private static class PolicyDecorator extends LookupElementDecorator<LookupElement> {
public static final ClassConditionKey<PolicyDecorator> CLASS_CONDITION_KEY = ClassConditionKey.create(PolicyDecorator.class);
private final AutoCompletionPolicy myPolicy;
public PolicyDecorator(LookupElement element, AutoCompletionPolicy policy) {
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.lookup;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.codeInsight.completion.PrefixMatcher;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
@@ -82,10 +83,18 @@ public abstract class LookupElement extends UserDataHolderBase {
presentation.setItemText(getLookupString());
}
/**
* use {@link #as(com.intellij.openapi.util.ClassConditionKey)} instead
*/
@Deprecated
@Nullable
public <T> T as(Class<T> aClass) {
//noinspection unchecked
return aClass.isInstance(this) ? (T) this : null;
public final <T> T as(Class<T> aClass) {
return as(ClassConditionKey.create(aClass));
}
@Nullable
public <T> T as(ClassConditionKey<T> conditionKey) {
return conditionKey.isInstance(this) ? (T) this : null;
}
public boolean isCaseSensitive() {
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.completion.CompletionService;
import com.intellij.codeInsight.completion.InsertHandler;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.codeInsight.completion.PrefixMatcher;
import com.intellij.openapi.util.ClassConditionKey;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
@@ -108,9 +109,9 @@ public abstract class LookupElementDecorator<T extends LookupElement> extends Lo
}
@Override
public <T> T as(Class<T> aClass) {
final T t = super.as(aClass);
return t == null ? myDelegate.as(aClass) : t;
public <T> T as(ClassConditionKey<T> conditionKey) {
final T t = super.as(conditionKey);
return t == null ? myDelegate.as(conditionKey) : t;
}
public boolean isCaseSensitive() {
@@ -15,72 +15,16 @@
*/
package com.intellij.facet.frameworks;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.text.StringUtil;
import org.jdom.Document;
import org.jdom.Element;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class LibrariesDownloadConnectionService {
private static final Logger LOG = Logger.getInstance("com.intellij.facet.frameworks.LibrariesDownloadConnectionService");
private static final String DOWNLOAD_SERVICE_SETTINGS_URL = "http://jetbrains.com/idea/download-assistant.xml ";
private static final String SERVICE_URL_ATTR_NAME = "url";
private static final String myAgentID = "IntelliJ IDEA";
public class LibrariesDownloadConnectionService extends SettingsConnectionService {
private static final LibrariesDownloadConnectionService myInstance = new LibrariesDownloadConnectionService();
private String myServiceUrl;
public static LibrariesDownloadConnectionService getInstance() {
return myInstance;
}
private LibrariesDownloadConnectionService() {
super("http://jetbrains.com/idea/download-assistant.xml", "http://frameworks.jetbrains.com");
}
private static String readServiceUrl() {
try {
final URL url = new URL(DOWNLOAD_SERVICE_SETTINGS_URL);
final InputStream is = getStream(url);
final Document document = JDOMUtil.loadDocument(is);
final Element root = document.getRootElement();
return StringUtil.notNullize(root.getAttributeValue(SERVICE_URL_ATTR_NAME), "");
}
catch (MalformedURLException e) {
LOG.error(e);
}
catch (IOException e) {
// no route to host, unknown host, etc.
}
catch (Exception e) {
LOG.error(e);
}
// default
return "http://frameworks.jetbrains.com";
}
private static InputStream getStream(URL url) throws IOException {
final URLConnection connection = url.openConnection();
if (connection instanceof HttpURLConnection) {
connection.setRequestProperty("User-agent", myAgentID);
}
return connection.getInputStream();
}
@Nullable
public String getServiceUrl() {
if (myServiceUrl == null) {
myServiceUrl = readServiceUrl();
}
return myServiceUrl;
}
}
@@ -0,0 +1,112 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.facet.frameworks;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.util.containers.hash.HashMap;
import org.jdom.Document;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;
public abstract class SettingsConnectionService {
private static final Logger LOG = Logger.getInstance("com.intellij.facet.frameworks.SettingsConnectionService");
protected static final String SERVICE_URL_ATTR_NAME = "url";
private static final String myAgentID = "IntelliJ IDEA";
private Map<String, String> myAttributesMap;
@NotNull
protected String[] getAttributeNames() {
return new String[] {SERVICE_URL_ATTR_NAME};
}
private String mySettingsUrl;
@Nullable private String myDefaultServiceUrl;
protected SettingsConnectionService(@NotNull String settingsUrl, @Nullable String defaultServiceUrl) {
mySettingsUrl = settingsUrl;
myDefaultServiceUrl = defaultServiceUrl;
}
public String getSettingsUrl() {
return mySettingsUrl;
}
@Nullable
public String getDefaultServiceUrl() {
return myDefaultServiceUrl;
}
@Nullable
private Map<String, String> readSettings(String... attributes) {
Map<String, String> settings = new HashMap<String, String>();
try {
final URL url = new URL(getSettingsUrl());
final InputStream is = getStream(url);
final Document document = JDOMUtil.loadDocument(is);
final Element root = document.getRootElement();
for (String s : attributes) {
settings.put(s, root.getAttributeValue(s));
}
}
catch (MalformedURLException e) {
LOG.error(e);
}
catch (IOException e) {
// no route to host, unknown host, etc.
}
catch (Exception e) {
LOG.error(e);
}
return settings;
}
private static InputStream getStream(URL url) throws IOException {
final URLConnection connection = url.openConnection();
if (connection instanceof HttpURLConnection) {
connection.setRequestProperty("User-agent", myAgentID);
}
return connection.getInputStream();
}
@Nullable
public String getServiceUrl() {
final String serviceUrl = getSettingValue(SERVICE_URL_ATTR_NAME);
return serviceUrl == null ? getDefaultServiceUrl() : serviceUrl;
}
@Nullable
protected String getSettingValue(@NotNull String attributeValue) {
if (myAttributesMap == null) {
myAttributesMap = readSettings(getAttributeNames());
}
return myAttributesMap != null ? myAttributesMap.get(attributeValue) : null;
}
}
@@ -21,9 +21,12 @@ import org.jetbrains.annotations.Nullable;
/**
* Represents a module content root.
* You can get existing entries with {@link com.intellij.openapi.roots.ModuleRootModel#getContentEntries()} or
* create a new one with {@link ModifiableRootModel#addContentEntry(com.intellij.openapi.vfs.VirtualFile)}.
*
* @author dsl
* @see ModuleRootModel#getContentEntries()
* @see ModifiableRootModel#addContentEntry(com.intellij.openapi.vfs.VirtualFile)
*/
public interface ContentEntry extends Synthetic {
/**
@@ -20,14 +20,15 @@
package com.intellij.psi;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Segment;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
public class IdentitySmartPointer<T extends PsiElement> implements SmartPsiElementPointer<T> {
private T myElement;
private final PsiFile myFile;
public IdentitySmartPointer(T element, PsiFile file) {
public IdentitySmartPointer(@NotNull T element, @NotNull PsiFile file) {
myElement = element;
myFile = file;
}
@@ -41,11 +42,17 @@ public class IdentitySmartPointer<T extends PsiElement> implements SmartPsiEleme
return myFile.getProject();
}
@Override
public VirtualFile getVirtualFile() {
return myFile.getVirtualFile();
}
public T getElement() {
if (myElement != null && !myElement.isValid()) {
myElement = null;
T element = myElement;
if (element != null && !element.isValid()) {
element = null;
}
return myElement;
return element;
}
public int hashCode() {
@@ -54,10 +61,17 @@ public class IdentitySmartPointer<T extends PsiElement> implements SmartPsiEleme
}
public boolean equals(Object obj) {
return obj instanceof SmartPsiElementPointer && Comparing.equal(getElement(), ((SmartPsiElementPointer)obj).getElement());
return obj instanceof SmartPsiElementPointer
&& SmartPointerManager.getInstance(getProject()).pointToTheSameElement(this, (SmartPsiElementPointer)obj);
}
public PsiFile getContainingFile() {
return myFile;
}
@Override
public Segment getSegment() {
T element = myElement;
return element == null ? null : element.getTextRange();
}
}
@@ -33,7 +33,6 @@ import org.jetbrains.annotations.Nullable;
* The main entry point for accessing the PSI services for a project.
*/
public abstract class PsiManager extends UserDataHolderBase {
/**
* Returns the PSI manager instance for the specified project.
*
@@ -239,4 +238,5 @@ public abstract class PsiManager extends UserDataHolderBase {
public abstract void unregisterLanguageInjector(@NotNull LanguageInjector injector);
public abstract void dropFileCaches(@NotNull PsiFile file);
}
@@ -39,9 +39,17 @@ public abstract class SmartPointerManager {
/**
* Creates a smart pointer to the specified PSI element which doesn't hold a strong reference to the PSI
* element.
*
* @deprecated use {@link #createSmartPsiElementPointer(PsiElement)} instead
* @param element the element to create a pointer to.
* @return the smart pointer instance.
*/
@NotNull public abstract <E extends PsiElement> SmartPsiElementPointer<E> createLazyPointer(@NotNull E element);
/**
* @param pointer1 smart pointer to compare
* @param pointer2 smart pointer to compare
* @return true if both pointers point to the same PSI element.
* This method is cheaper than dereferencing both pointers and comparing the result.
*/
public abstract boolean pointToTheSameElement(@NotNull SmartPsiElementPointer pointer1, @NotNull SmartPsiElementPointer pointer2);
}
@@ -16,6 +16,8 @@
package com.intellij.psi;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Segment;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -41,4 +43,8 @@ public interface SmartPsiElementPointer<E extends PsiElement> {
@NotNull
Project getProject();
VirtualFile getVirtualFile();
Segment getSegment();
}
@@ -19,11 +19,10 @@ package com.intellij.psi.impl;
import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.NativeFileType;
import com.intellij.openapi.fileTypes.INativeFileType;
import com.intellij.openapi.fileTypes.UnknownFileType;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Iconable;
import com.intellij.openapi.util.UserDataHolderBase;
@@ -31,6 +30,8 @@ import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.SmartPointerManager;
import com.intellij.psi.SmartPsiElementPointer;
import com.intellij.ui.IconDeferrer;
import com.intellij.ui.LayeredIcon;
import com.intellij.ui.RowIcon;
@@ -48,6 +49,14 @@ public abstract class ElementBase extends UserDataHolderBase implements Iconable
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.ElementBase");
public static final int FLAGS_LOCKED = 0x800;
private static final NullableFunction<ElementIconRequest,Icon> ICON_COMPUTE = new NullableFunction<ElementIconRequest, Icon>() {
public Icon fun(ElementIconRequest request) {
final PsiElement element = request.getElement();
if (!element.isValid()) return null;
if (element.getProject().isDisposed()) return null;
return computeIconNow(element, request.getFlags());
}
};
private TIntObjectHashMap<Icon> myBaseIcon;
private static final Icon VISIBILITY_ICON_PLACHOLDER = new EmptyIcon(Icons.PUBLIC_ICON);
@@ -88,18 +97,10 @@ public abstract class ElementBase extends UserDataHolderBase implements Iconable
baseIcon = myBaseIcon.get(flags);
}
final Project project = psiElement.getProject();
if (isToDeferIconLoading()) {
return IconDeferrer.getInstance().defer(baseIcon, new ElementIconRequest(psiElement, flags), new NullableFunction<ElementIconRequest, Icon>() {
public Icon fun(ElementIconRequest request) {
if (project.isDisposed()) return null;
final PsiElement element = request.getElement();
if (!element.isValid()) return null;
if (element.getProject().isDisposed()) return null;
return computeIconNow(element, request.getFlags());
}
});
} else {
return IconDeferrer.getInstance().defer(baseIcon, new ElementIconRequest(psiElement, flags), ICON_COMPUTE);
}
else {
if (!psiElement.isValid()) return null;
return computeIconNow(psiElement, flags);
}
@@ -110,12 +111,12 @@ public abstract class ElementBase extends UserDataHolderBase implements Iconable
}
@Nullable
private Icon computeIconNow(PsiElement element, int flags) {
private static Icon computeIconNow(PsiElement element, int flags) {
final Icon providersIcon = PsiIconUtil.getProvidersIcon(element, flags);
if (providersIcon != null) {
return providersIcon instanceof RowIcon ? (RowIcon)providersIcon : createLayeredIcon(providersIcon, flags);
}
return getElementIcon(flags);
return ((ElementBase)element).getElementIcon(flags);
}
protected Icon computeBaseIcon(int flags) {
@@ -135,7 +136,7 @@ public abstract class ElementBase extends UserDataHolderBase implements Iconable
}
public static boolean isNativeFileType(FileType fileType) {
return fileType instanceof NativeFileType || fileType instanceof UnknownFileType;
return fileType instanceof INativeFileType || fileType instanceof UnknownFileType;
}
protected Icon getAdjustedBaseIcon(Icon icon, int flags) {
@@ -177,11 +178,16 @@ public abstract class ElementBase extends UserDataHolderBase implements Iconable
public static class ElementIconRequest extends ComparableObject.Impl {
public ElementIconRequest(PsiElement element, int flags) {
super(new Object[] {element, flags});
super(new Object[] {createPointer(element), flags});
}
private static Object createPointer(PsiElement element) {
return SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
}
public PsiElement getElement() {
return (PsiElement)getEqualityObjects()[0];
SmartPsiElementPointer pointer = (SmartPsiElementPointer)getEqualityObjects()[0];
return pointer.getElement();
}
public int getFlags() {
@@ -15,11 +15,12 @@
*/
package com.intellij.usageView;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Segment;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
@@ -29,8 +30,7 @@ import org.jetbrains.annotations.Nullable;
public class UsageInfo {
public static final UsageInfo[] EMPTY_ARRAY = new UsageInfo[0];
private static final Logger LOG = Logger.getInstance("#com.intellij.usageView.UsageInfo");
private final SmartPsiElementPointer mySmartPointer;
private final VirtualFile myVirtualFile;
private final SmartPsiElementPointer<?> mySmartPointer;
public final int startOffset; // in navigation element
public final int endOffset; // in navigation element
@@ -38,9 +38,19 @@ public class UsageInfo {
public UsageInfo(@NotNull PsiElement element, int startOffset, int endOffset, boolean isNonCodeUsage) {
LOG.assertTrue(element.isValid());
LOG.assertTrue(element == element.getNavigationElement());
mySmartPointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
myVirtualFile = element.getContainingFile().getVirtualFile();
element = element.getNavigationElement();
SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(element.getProject());
mySmartPointer = smartPointerManager.createSmartPsiElementPointer(element);
if (startOffset == -1 && endOffset == -1) {
// calculate natural element range
TextRange range = element.getTextRange();
if (range == null) {
LOG.error("text range null for " + element + "; " + element.getClass());
}
startOffset = element.getTextOffset() - range.getStartOffset();
endOffset = range.getEndOffset() - range.getStartOffset();
}
this.startOffset = startOffset;
this.endOffset = endOffset;
this.isNonCodeUsage = isNonCodeUsage;
@@ -49,22 +59,7 @@ public class UsageInfo {
}
public UsageInfo(@NotNull PsiElement element, boolean isNonCodeUsage) {
LOG.assertTrue(element.isValid());
element = element.getNavigationElement();
mySmartPointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
myVirtualFile = element.getContainingFile().getVirtualFile();
TextRange range = element.getTextRange();
if (range == null) {
LOG.error("text range null for " + element+"; "+element.getClass());
}
startOffset = element.getTextOffset() - range.getStartOffset();
endOffset = range.getEndOffset() - range.getStartOffset();
this.isNonCodeUsage = isNonCodeUsage;
LOG.assertTrue(startOffset >= 0, startOffset);
LOG.assertTrue(endOffset >= startOffset, endOffset-startOffset);
this(element, -1, -1, isNonCodeUsage);
}
public UsageInfo(@NotNull PsiElement element, int startOffset, int endOffset) {
@@ -105,15 +100,25 @@ public class UsageInfo {
}
public final void navigateTo(boolean requestFocus) {
PsiElement element = getElement();
if (element == null) return;
VirtualFile file = element.getContainingFile().getVirtualFile();
TextRange range = element.getTextRange();
int offset = range.getStartOffset() + startOffset;
Project project = element.getProject();
int offset = getNavigationOffset();
VirtualFile file = getVirtualFile();
Project project = getProject();
FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, file, offset), requestFocus);
}
public int getNavigationOffset() {
PsiElement element = getElement();
if (element == null) return -1;
TextRange range = element.getTextRange();
return range.getStartOffset() + startOffset;
}
public Segment getSegment() {
PsiElement element = getElement();
if (element == null) return null;
TextRange range = element.getTextRange();
return new TextRange(range.getStartOffset() + startOffset, Math.min(range.getEndOffset(), range.getStartOffset() + endOffset));
}
public Project getProject() {
return mySmartPointer.getProject();
}
@@ -132,9 +137,8 @@ public class UsageInfo {
if (endOffset != usageInfo.endOffset) return false;
if (isNonCodeUsage != usageInfo.isNonCodeUsage) return false;
if (startOffset != usageInfo.startOffset) return false;
PsiElement thisElement = mySmartPointer.getElement();
PsiElement thatElement = usageInfo.mySmartPointer.getElement();
return Comparing.equal(thisElement, thatElement);
return SmartPointerManager.getInstance(getProject()).pointToTheSameElement(mySmartPointer, usageInfo.mySmartPointer);
}
public int hashCode() {
@@ -150,7 +154,12 @@ public class UsageInfo {
return mySmartPointer.getContainingFile();
}
@Nullable
public VirtualFile getVirtualFile() {
return myVirtualFile;
return mySmartPointer.getVirtualFile();
}
public void dispose() {
((Disposable)mySmartPointer).dispose();
}
}
@@ -16,9 +16,7 @@
package com.intellij.codeInsight;
import com.intellij.codeInsight.completion.CodeCompletionHandlerBase;
import com.intellij.codeInsight.completion.CompletionProgressIndicator;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.completion.impl.CompletionServiceImpl;
import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler;
import com.intellij.codeInsight.hint.ShowParameterInfoHandler;
@@ -101,7 +99,7 @@ public class AutoPopupController implements Disposable {
if (!file.isValid()) return;
if (condition != null && !condition.value(file)) return;
new CodeCompletionHandlerBase(CompletionType.BASIC, false, true).invoke(myProject, editor, file);
CompletionAutoPopupHandler.invokeAutoPopupCompletion(myProject, editor);
}
};
@@ -452,7 +452,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
return policy;
}
final LookupItem item = element.as(LookupItem.class);
final LookupItem item = element.as(LookupItem.CLASS_CONDITION_KEY);
if (item != null) {
return item.getAutoCompletionPolicy();
}
@@ -505,8 +505,8 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
protected void run(Result result) throws Throwable {
String uniqueText = _uniqueText;
if (item.getObject() instanceof DeferredUserLookupValue && item.as(LookupItem.class) != null) {
if (!((DeferredUserLookupValue)item.getObject()).handleUserSelection(item.as(LookupItem.class), context.getProject())) {
if (item.getObject() instanceof DeferredUserLookupValue && item.as(LookupItem.CLASS_CONDITION_KEY) != null) {
if (!((DeferredUserLookupValue)item.getObject()).handleUserSelection(item.as(LookupItem.CLASS_CONDITION_KEY), context.getProject())) {
return;
}
@@ -18,7 +18,6 @@ package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.LookupElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author peter
@@ -26,10 +25,7 @@ import org.jetbrains.annotations.Nullable;
public class GroupingWeigher extends CompletionWeigher {
@Override
public Integer weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
if (location == null) {
return null;
}
final PrioritizedLookupElement prioritized = element.as(PrioritizedLookupElement.class);
final PrioritizedLookupElement prioritized = element.as(PrioritizedLookupElement.CLASS_CONDITION_KEY);
if (prioritized != null) {
return -prioritized.getGrouping();
}
@@ -19,7 +19,6 @@ package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupItem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author peter
@@ -27,15 +26,12 @@ import org.jetbrains.annotations.Nullable;
public class PriorityWeigher extends CompletionWeigher {
@Override
public Double weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
if (location == null) {
return null;
}
final PrioritizedLookupElement prioritized = PrioritizedLookupElement.from(element);
final PrioritizedLookupElement prioritized = element.as(PrioritizedLookupElement.CLASS_CONDITION_KEY);
if (prioritized != null) {
return -prioritized.getPriority();
}
final LookupItem item = LookupItem.from(element);
final LookupItem item = element.as(LookupItem.CLASS_CONDITION_KEY);
if (item != null) {
return -item.getPriority();
}
@@ -159,7 +159,8 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx
List<HighlightInfo> result = new ArrayList<HighlightInfo>();
result.addAll(action1.getHighlights());
LocalInspectionsPass action3 = new LocalInspectionsPass(psiFile, document, 0, psiFile.getTextLength());
LocalInspectionsPass action3 = new LocalInspectionsPass(psiFile, document, 0,
psiFile.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true);
action3.doCollectInformation(progress);
result.addAll(action3.getHighlights());
@@ -46,7 +46,6 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.util.text.StringUtil;
@@ -58,7 +57,7 @@ import com.intellij.util.ConcurrencyUtil;
import com.intellij.util.Function;
import com.intellij.util.Processor;
import com.intellij.util.containers.ConcurrentHashMap;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.containers.TransferToEDTQueue;
import com.intellij.xml.util.XmlStringUtil;
import gnu.trove.THashMap;
import gnu.trove.THashSet;
@@ -67,9 +66,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* @author max
@@ -77,9 +74,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass implements DumbAware {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.LocalInspectionsPass");
private static final int NUM_ELEMENTS_PER_CHECK_CANCELLED = 5;
public static final TextRange EMPTY_PRIORITY_RANGE = new TextRange(0, 0);
private final int myStartOffset;
private final int myEndOffset;
private final TextRange myPriorityRange;
private final boolean myIgnoreSuppressed;
private final ConcurrentMap<PsiFile, List<InspectionResult>> result = new ConcurrentHashMap<PsiFile, List<InspectionResult>>();
static final String PRESENTABLE_NAME = DaemonBundle.message("pass.inspection");
private volatile List<HighlightInfo> myInfos = Collections.emptyList();
@@ -88,14 +87,17 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
private final InspectionProfileWrapper myProfileWrapper;
private boolean myFailFastOnAcquireReadAction;
public LocalInspectionsPass(@NotNull PsiFile file, @Nullable Document document, int startOffset, int endOffset) {
this(file, document, startOffset, endOffset, new TextRange(0, 0));
}
public LocalInspectionsPass(@NotNull PsiFile file, @Nullable Document document, int startOffset, int endOffset, @NotNull TextRange priorityRange) {
public LocalInspectionsPass(@NotNull PsiFile file,
@Nullable Document document,
int startOffset,
int endOffset,
@NotNull TextRange priorityRange,
boolean ignoreSuppressed) {
super(file.getProject(), document, PRESENTABLE_NAME, file, true);
myStartOffset = startOffset;
myEndOffset = endOffset;
myPriorityRange = priorityRange;
myIgnoreSuppressed = ignoreSuppressed;
setId(Pass.LOCAL_INSPECTIONS);
final KeymapManager keymapManager = KeymapManager.getInstance();
@@ -113,7 +115,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
if (customizationStrategy != null) {
profileToUse = customizationStrategy.fun(profileToUse);
}
myProfileWrapper = profileToUse;
mySeverityRegistrar = ((SeverityProvider)myProfileWrapper.getInspectionProfile().getProfileManager()).getSeverityRegistrar();
LOG.assertTrue(mySeverityRegistrar != null);
@@ -128,7 +130,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
final InspectionManagerEx iManager = (InspectionManagerEx)InspectionManager.getInstance(myProject);
final InspectionProfileWrapper profile = myProfileWrapper;
final List<LocalInspectionTool> tools = DumbService.getInstance(myProject).filterByDumbAwareness(getInspectionTools(profile));
inspect(tools, iManager, true, true, true, progress);
inspect(tools, iManager, true, true, progress);
}
finally {
disposeDescriptors();
@@ -146,7 +148,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
result.clear();
}
public void doInspectInBatch(final InspectionManagerEx iManager, List<InspectionProfileEntry> toolWrappers, boolean ignoreSuppressed) {
public void doInspectInBatch(final InspectionManagerEx iManager, List<InspectionProfileEntry> toolWrappers) {
Map<LocalInspectionTool, LocalInspectionToolWrapper> tool2Wrapper = new THashMap<LocalInspectionTool, LocalInspectionToolWrapper>(toolWrappers.size());
for (InspectionProfileEntry toolWrapper : toolWrappers) {
tool2Wrapper.put(((LocalInspectionToolWrapper)toolWrapper).getTool(), (LocalInspectionToolWrapper)toolWrapper);
@@ -154,7 +156,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
List<LocalInspectionTool> tools = new ArrayList<LocalInspectionTool>(tool2Wrapper.keySet());
ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
inspect(tools, iManager, false, ignoreSuppressed, false, progress);
inspect(tools, iManager, false, false, progress);
addDescriptorsFromInjectedResults(tool2Wrapper, iManager);
List<InspectionResult> resultList = result.get(myFile);
if (resultList == null) return;
@@ -163,7 +165,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
LocalInspectionToolWrapper toolWrapper = tool2Wrapper.get(tool);
if (toolWrapper == null) continue;
for (ProblemDescriptor descriptor : inspectionResult.foundProblems) {
toolWrapper.addProblemDescriptors(Collections.singletonList(descriptor), ignoreSuppressed);
toolWrapper.addProblemDescriptors(Collections.singletonList(descriptor), myIgnoreSuppressed);
}
}
}
@@ -214,7 +216,6 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
private void inspect(final List<LocalInspectionTool> tools,
final InspectionManagerEx iManager,
final boolean isOnTheFly,
final boolean ignoreSuppressed,
boolean failFastOnAcquireReadAction,
@NotNull final ProgressIndicator indicator) {
myFailFastOnAcquireReadAction = failFastOnAcquireReadAction;
@@ -231,8 +232,8 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
List<Trinity<LocalInspectionTool, ProblemsHolder, PsiElementVisitor>> init = new ArrayList<Trinity<LocalInspectionTool, ProblemsHolder, PsiElementVisitor>>();
boolean finished = false;
try {
visitPriorityElementsAndInit(tools, iManager, isOnTheFly, ignoreSuppressed, indicator, inside, session, init);
visitRestElementsAndCleanup(tools,iManager,isOnTheFly,ignoreSuppressed, indicator, outside, session, init);
visitPriorityElementsAndInit(tools, iManager, isOnTheFly, indicator, inside, session, init);
visitRestElementsAndCleanup(tools,iManager,isOnTheFly, indicator, outside, session, init);
finished = true;
}
finally {
@@ -253,13 +254,12 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
indicator.checkCanceled();
myInfos = new ArrayList<HighlightInfo>();
addHighlightsFromResults(myInfos, ignoreSuppressed);
addHighlightsFromResults(myInfos);
}
private void visitPriorityElementsAndInit(@NotNull List<LocalInspectionTool> tools,
@NotNull final InspectionManagerEx iManager,
final boolean isOnTheFly,
final boolean ignoreSuppressed,
@NotNull final ProgressIndicator indicator,
@NotNull final List<PsiElement> elements,
@NotNull final LocalInspectionToolSession session,
@@ -276,7 +276,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
public void registerProblem(@NotNull ProblemDescriptor descriptor) {
super.registerProblem(descriptor);
if (applyIncrementally[0]) {
addDescriptorIncrementally(descriptor, tool, ignoreSuppressed, indicator);
addDescriptorIncrementally(descriptor, tool, indicator);
}
}
};
@@ -295,7 +295,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
}
}, myFailFastOnAcquireReadAction, indicator);
if (!result) throw new ProcessCanceledException();
inspectInjectedPsi(elements, tools, isOnTheFly, ignoreSuppressed, indicator, iManager, true);
inspectInjectedPsi(elements, tools, isOnTheFly, indicator, iManager, true);
}
private static PsiElementVisitor createVisitorAndAcceptElements(@NotNull LocalInspectionTool tool,
@@ -324,7 +324,6 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
private void visitRestElementsAndCleanup(@NotNull List<LocalInspectionTool> tools,
@NotNull InspectionManagerEx iManager,
final boolean isOnTheFly,
final boolean ignoreSuppressed,
@NotNull final ProgressIndicator indicator,
@NotNull final List<PsiElement> elements,
@NotNull final LocalInspectionToolSession session,
@@ -341,7 +340,8 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
ProblemsHolder holder = trinity.second;
PsiElementVisitor elementVisitor = trinity.third;
for (int i = 0, elementsSize = elements.size(); i < elementsSize; i++) {
elements.get(i).accept(elementVisitor);
PsiElement element = elements.get(i);
element.accept(elementVisitor);
if (i % NUM_ELEMENTS_PER_CHECK_CANCELLED == 0) indicator.checkCanceled();
}
@@ -359,13 +359,12 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
if (!result) {
throw new ProcessCanceledException();
}
inspectInjectedPsi(elements, tools, isOnTheFly, ignoreSuppressed, indicator, iManager, false);
inspectInjectedPsi(elements, tools, isOnTheFly, indicator, iManager, false);
}
private void inspectInjectedPsi(@NotNull final List<PsiElement> elements,
@NotNull final List<LocalInspectionTool> tools,
final boolean onTheFly,
final boolean ignoreSuppressed,
@NotNull final ProgressIndicator indicator,
@NotNull final InspectionManagerEx iManager,
final boolean inVisibleRange) {
@@ -380,7 +379,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
if (injected.isEmpty()) return;
if (!JobUtil.invokeConcurrentlyUnderProgress(new ArrayList<PsiFile>(injected), new Processor<PsiFile>() {
public boolean process(final PsiFile injectedPsi) {
doInspectInjectedPsi(injectedPsi, tools, onTheFly, ignoreSuppressed, indicator, iManager, inVisibleRange);
doInspectInjectedPsi(injectedPsi, tools, onTheFly, indicator, iManager, inVisibleRange);
return true;
}
}, myFailFastOnAcquireReadAction, indicator)) throw new ProcessCanceledException();
@@ -389,7 +388,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
public Collection<HighlightInfo> getHighlights() {
List<HighlightInfo> highlights = new ArrayList<HighlightInfo>();
addHighlightsFromResults(highlights, true);
addHighlightsFromResults(highlights);
return highlights;
}
@@ -410,56 +409,52 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
severity, problemDescriptor.isAfterEndOfLine(), null, isFileLevel);
}
private final AtomicBoolean haveInfosToProcess = new AtomicBoolean();
private final ConcurrentLinkedQueue<Pair<ProblemDescriptor, LocalInspectionTool>> infosToAdd = new ConcurrentLinkedQueue<Pair<ProblemDescriptor, LocalInspectionTool>>();
private final TransferToEDTQueue<Trinity<ProblemDescriptor, LocalInspectionTool,ProgressIndicator>> myTransferToEDTQueue;
{
myTransferToEDTQueue =
new TransferToEDTQueue<Trinity<ProblemDescriptor, LocalInspectionTool,ProgressIndicator>>(new Processor<Trinity<ProblemDescriptor, LocalInspectionTool,ProgressIndicator>>() {
private final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
private final InjectedLanguageManager ilManager = InjectedLanguageManager.getInstance(myProject);
private final List<HighlightInfo> infos = new ArrayList<HighlightInfo>(2);
private final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
@Override
public boolean process(Trinity<ProblemDescriptor, LocalInspectionTool,ProgressIndicator> trinity) {
ProgressIndicator indicator = trinity.getThird();
if (indicator.isCanceled()) {
return false;
}
ProblemDescriptor descriptor = trinity.first;
LocalInspectionTool tool = trinity.second;
PsiElement psiElement = descriptor.getPsiElement();
if (psiElement == null) return true;
PsiFile file = psiElement.getContainingFile();
Document thisDocument = documentManager.getDocument(file);
HighlightSeverity severity = inspectionProfile.getErrorLevel(HighlightDisplayKey.find(tool.getShortName()), file).getSeverity();
infos.clear();
createHighlightsForDescriptor(infos, emptyActionRegistered, ilManager, file, thisDocument, tool, severity, descriptor);
for (HighlightInfo info : infos) {
final EditorColorsScheme colorsScheme = getColorsScheme();
UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, myFile, myStartOffset, myEndOffset,
info, colorsScheme, getId());
}
return true;
}
}, myProject.getDisposed());
}
private final Set<TextRange> emptyActionRegistered = Collections.synchronizedSet(new HashSet<TextRange>());
private void addDescriptorIncrementally(@NotNull final ProblemDescriptor descriptor,
@NotNull final LocalInspectionTool tool,
final boolean ignoreSuppressed,
@NotNull final ProgressIndicator indicator) {
if (ignoreSuppressed && InspectionManagerEx.inspectionResultSuppressed(descriptor.getPsiElement(), tool)) {
if (myIgnoreSuppressed && InspectionManagerEx.inspectionResultSuppressed(descriptor.getPsiElement(), tool)) {
return;
}
infosToAdd.offer(Pair.create(descriptor, tool));
if (haveInfosToProcess.getAndSet(true)) return;
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
// extra invoke later is harmless, missing invoke is not
UIUtil.invokeLaterIfNeeded(new Runnable() {
public void run() {
if (myProject.isDisposed()) return;
InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
InjectedLanguageManager ilManager = InjectedLanguageManager.getInstance(myProject);
List<HighlightInfo> infos = new ArrayList<HighlightInfo>(2);
while (haveInfosToProcess.compareAndSet(true, false)) {
for (Pair<ProblemDescriptor, LocalInspectionTool> pair = infosToAdd.poll(); pair != null; pair = infosToAdd.poll()) {
if (indicator.isCanceled()) {
infosToAdd.clear();
return;
}
ProblemDescriptor descriptor = pair.first;
LocalInspectionTool tool = pair.second;
PsiElement psiElement = descriptor.getPsiElement();
if (psiElement == null) continue;
PsiFile file = psiElement.getContainingFile();
Document thisDocument = documentManager.getDocument(file);
HighlightSeverity severity = inspectionProfile.getErrorLevel(HighlightDisplayKey.find(tool.getShortName()), file).getSeverity();
infos.clear();
createHighlightsForDescriptor(infos, emptyActionRegistered, ilManager, file, thisDocument, tool, severity, descriptor, ignoreSuppressed);
for (HighlightInfo info : infos) {
final EditorColorsScheme colorsScheme = getColorsScheme();
UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, myFile, myStartOffset, myEndOffset,
info, colorsScheme, getId());
}
}
}
}
});
myTransferToEDTQueue.offer(Trinity.create(descriptor, tool, indicator));
}
private void appendDescriptors(PsiFile file, List<ProblemDescriptor> descriptors, LocalInspectionTool tool) {
@@ -519,7 +514,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, myStartOffset, myEndOffset, myInfos, getColorsScheme(), getId());
}
private void addHighlightsFromResults(final List<HighlightInfo> outInfos, boolean ignoreSuppressed) {
private void addHighlightsFromResults(final List<HighlightInfo> outInfos) {
InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
InjectedLanguageManager ilManager = InjectedLanguageManager.getInstance(myProject);
@@ -534,8 +529,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
LocalInspectionTool tool = inspectionResult.tool;
HighlightSeverity severity = inspectionProfile.getErrorLevel(HighlightDisplayKey.find(tool.getShortName()), file).getSeverity();
for (ProblemDescriptor descriptor : inspectionResult.foundProblems) {
createHighlightsForDescriptor(outInfos, emptyActionRegistered, ilManager, file, documentRange, tool, severity, descriptor,
ignoreSuppressed);
createHighlightsForDescriptor(outInfos, emptyActionRegistered, ilManager, file, documentRange, tool, severity, descriptor);
}
}
}
@@ -548,10 +542,10 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
Document documentRange,
LocalInspectionTool tool,
HighlightSeverity severity,
ProblemDescriptor descriptor, boolean ignoreSuppressed) {
ProblemDescriptor descriptor) {
PsiElement psiElement = descriptor.getPsiElement();
if (psiElement == null) return;
if (ignoreSuppressed && InspectionManagerEx.inspectionResultSuppressed(psiElement, tool)) return;
if (myIgnoreSuppressed && InspectionManagerEx.inspectionResultSuppressed(psiElement, tool)) return;
HighlightInfoType level = highlightTypeFromDescriptor(descriptor, severity);
HighlightInfo info = createHighlightInfo(descriptor, tool, level, emptyActionRegistered);
if (info == null) return;
@@ -677,7 +671,6 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
private void doInspectInjectedPsi(@NotNull PsiFile injectedPsi,
@NotNull List<LocalInspectionTool> tools,
final boolean isOnTheFly,
final boolean ignoreSuppressed,
@NotNull final ProgressIndicator indicator,
@NotNull InspectionManagerEx iManager,
final boolean inVisibleRange) {
@@ -689,7 +682,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
}
for (final LocalInspectionTool tool : tools) {
indicator.checkCanceled();
if (host != null && ignoreSuppressed && InspectionManagerEx.inspectionResultSuppressed(host, tool)) {
if (host != null && myIgnoreSuppressed && InspectionManagerEx.inspectionResultSuppressed(host, tool)) {
continue;
}
ProblemsHolder holder = new ProblemsHolder(iManager, injectedPsi, isOnTheFly) {
@@ -697,7 +690,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
public void registerProblem(@NotNull ProblemDescriptor descriptor) {
super.registerProblem(descriptor);
if (isOnTheFly && inVisibleRange) {
addDescriptorIncrementally(descriptor, tool, ignoreSuppressed, indicator);
addDescriptorIncrementally(descriptor, tool, indicator);
}
}
};
@@ -55,7 +55,7 @@ public class LocalInspectionsPassFactory extends AbstractProjectComponent implem
if (textRange == null) return new ProgressableTextEditorHighlightingPass.EmptyPass(myProject, editor.getDocument()
);
TextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
return new LocalInspectionsPass(file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), visibleRange){
return new LocalInspectionsPass(file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), visibleRange, true){
List<LocalInspectionTool> getInspectionTools(InspectionProfileWrapper profile) {
List<LocalInspectionTool> tools = super.getInspectionTools(profile);
List<LocalInspectionTool> result = new ArrayList<LocalInspectionTool>(tools.size());
@@ -90,7 +90,7 @@ public class WholeFileLocalInspectionsPassFactory extends AbstractProjectCompone
public TextEditorHighlightingPass createHighlightingPass(@NotNull final PsiFile file, @NotNull final Editor editor) {
TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.LOCAL_INSPECTIONS);
if (textRange == null || myFileTools.containsKey(file) && !myFileTools.get(file)) return null;
return new LocalInspectionsPass(file, editor.getDocument(), 0, file.getTextLength()) {
return new LocalInspectionsPass(file, editor.getDocument(), 0, file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true) {
List<LocalInspectionTool> getInspectionTools(InspectionProfileWrapper profile) {
List<LocalInspectionTool> tools = super.getInspectionTools(profile);
List<LocalInspectionTool> result = new ArrayList<LocalInspectionTool>();
@@ -886,7 +886,7 @@ public class DocumentationManager {
void showHint(final JBPopup hint) {
final Lookup lookup = LookupManager.getActiveLookup(myEditor);
if (lookup != null) {
if (lookup != null && lookup.getCurrentItem() != null) {
lookup.showItemPopup(hint);
return;
}
@@ -112,37 +112,41 @@ public class CompletionAutoPopupHandler extends TypedHandlerDelegate {
if (ApplicationManager.getApplication().isWriteAccessAllowed()) return; //it will fail anyway
if (DumbService.getInstance(project).isDumb()) return;
new CodeCompletionHandlerBase(CompletionType.BASIC, false, true).invoke(project, editor);
final AutoPopupState state = new AutoPopupState(project, editor);
editor.putUserData(STATE_KEY, state);
final Lookup lookup = LookupManager.getActiveLookup(editor);
if (lookup != null) {
lookup.addLookupListener(new LookupAdapter() {
@Override
public void itemSelected(LookupEvent event) {
final AutoPopupState state = getAutoPopupState(editor);
if (state != null) {
state.stopAutoPopup();
}
}
@Override
public void lookupCanceled(LookupEvent event) {
final AutoPopupState state = getAutoPopupState(editor);
if (event.isCanceledExplicitly() && state != null) {
state.stopAutoPopup();
}
}
});
}
invokeAutoPopupCompletion(project, editor);
}
};
AutoPopupController.getInstance(project).invokeAutoPopupRunnable(request, CodeInsightSettings.getInstance().AUTO_LOOKUP_DELAY);
return Result.STOP;
}
public static void invokeAutoPopupCompletion(Project project, final Editor editor) {
new CodeCompletionHandlerBase(CompletionType.BASIC, false, true).invoke(project, editor);
final AutoPopupState state = new AutoPopupState(project, editor);
editor.putUserData(STATE_KEY, state);
final Lookup lookup = LookupManager.getActiveLookup(editor);
if (lookup != null) {
lookup.addLookupListener(new LookupAdapter() {
@Override
public void itemSelected(LookupEvent event) {
final AutoPopupState state = getAutoPopupState(editor);
if (state != null) {
state.stopAutoPopup();
}
}
@Override
public void lookupCanceled(LookupEvent event) {
final AutoPopupState state = getAutoPopupState(editor);
if (event.isCanceledExplicitly() && state != null) {
state.stopAutoPopup();
}
}
});
}
}
@Nullable
private static AutoPopupState getAutoPopupState(Editor editor) {
return editor.getUserData(STATE_KEY);
@@ -49,6 +49,7 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class EnterHandler extends BaseEnterHandler {
@@ -196,6 +197,9 @@ public class EnterHandler extends BaseEnterHandler {
lexer.advance();
continue;
}
else if (isInvalidPsi(comment)) {
return false;
}
return lexer.getTokenEnd() - lexer.getTokenStart() == 1;
}
if (tokenType == commenter.getDocumentationCommentTokenType() || tokenType == commenter.getBlockCommentTokenType()) {
@@ -205,6 +209,48 @@ public class EnterHandler extends BaseEnterHandler {
}
}
/**
* There is a following possible use-case:
* <pre>
* <ul>
* <li>
* <b>Particular document has valid text:</b>
* <pre>
* [caret]
* class A {
* int foo() {
* return 1 *&#47;*comment*&#47; 1;
* }
* }
* </pre>
* </li>
* <li>
* <b>The user starts comment (inserts comment start symbols):</b>
* <pre>
* &#47;**[caret]
* class A {
* int foo() {
* return 1 *&#47;*comment*&#47; 1;
* }
* }
* </pre>
* </li>
* <li>The user presses <code>'enter'</code>;</li>
* </ul>
* </pre>
* We want to understand that doc comment is incomplete now, i.e. don't want to consider '*&#47;' before
* '*comment*&#47; 1;' as comment end. Current approach is to check if next PSI sibling to the current PSI comment is invalid.
* This method allows to perform such an examination.
*/
private static boolean isInvalidPsi(@NotNull PsiElement base) {
for (PsiElement current = base.getNextSibling(); current != null; current = current.getNextSibling()) {
if (current.getTextLength() != 0) {
return current instanceof PsiErrorElement;
}
}
return false;
}
private static boolean isDocComment(final PsiElement element, final CodeDocumentationAwareCommenter commenter) {
if (!(element instanceof PsiComment)) return false;
PsiComment comment = (PsiComment) element;
@@ -259,8 +305,8 @@ public class EnterHandler extends BaseEnterHandler {
final PsiElement parent = element.getParent();
if (text.equals(commentContext.commenter.getDocumentationCommentPrefix()) && isDocComment(parent, commentContext.commenter) ||
text.startsWith(commentContext.commenter.getDocumentationCommentPrefix()) && element instanceof PsiComment
) {
text.startsWith(commentContext.commenter.getDocumentationCommentPrefix()) && element instanceof PsiComment)
{
PsiComment comment = isDocComment(parent, commentContext.commenter) ? (PsiComment)parent:(PsiComment)element;
int commentEnd = comment.getTextRange().getEndOffset();
@@ -321,7 +367,7 @@ public class EnterHandler extends BaseEnterHandler {
String indentInsideJavadoc = null;
int line = myDocument.getLineNumber(myOffset);
if (line > 0) {
if (line > 0 && (commentContext.docAsterisk || commentContext.docStart)) {
indentInsideJavadoc = CodeDocumentationUtil.getIndentInsideJavadoc(myDocument, myDocument.getLineStartOffset(line - 1));
}
@@ -29,6 +29,7 @@ import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.util.Segment;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ui.RangeBlinker;
import org.jetbrains.annotations.NonNls;
@@ -78,23 +79,28 @@ class IntentionUsagePanel extends JPanel{
}
private void setupSpots(Document document) {
List<RangeMarker> markers = new ArrayList<RangeMarker>();
List<Segment> markers = new ArrayList<Segment>();
while (true) {
String text = document.getText();
int spotStart = text.indexOf("<" + SPOT_MARKER + ">");
final int spotStart = text.indexOf("<" + SPOT_MARKER + ">");
if (spotStart < 0) break;
int spotEnd = text.indexOf("</" + SPOT_MARKER + ">", spotStart);
final int spotEnd = text.indexOf("</" + SPOT_MARKER + ">", spotStart);
if (spotEnd < 0) break;
document.deleteString(spotEnd, spotEnd + SPOT_MARKER.length() + 3);
document.deleteString(spotStart, spotStart + SPOT_MARKER.length() + 2);
final RangeMarker spotMarker = document.createRangeMarker(spotStart, spotEnd - SPOT_MARKER.length() - 2);
if (spotMarker == null) {
break;
}
else {
markers.add(spotMarker);
}
Segment spotMarker = new Segment() {
@Override
public int getStartOffset() {
return spotStart;
}
@Override
public int getEndOffset() {
return spotEnd - SPOT_MARKER.length() - 2;
}
};
markers.add(spotMarker);
}
myRangeBlinker.resetMarkers(markers);
if (!markers.isEmpty()) {
@@ -25,6 +25,7 @@ import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.codeInsight.lookup.impl.ElementLookupRenderer;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Key;
import com.intellij.util.containers.ContainerUtil;
@@ -42,6 +43,8 @@ import java.util.Set;
* This class represents an item of a lookup list.
*/
public class LookupItem<T> extends MutableLookupElement<T> implements Comparable {
public static final ClassConditionKey<LookupItem> CLASS_CONDITION_KEY = ClassConditionKey.create(LookupItem.class);
public static final Object HIGHLIGHTED_ATTR = Key.create("highlighted");
public static final Object ICON_ATTR = Key.create("icon");
public static final Object TYPE_TEXT_ATTR = Key.create("typeText");
@@ -358,24 +361,8 @@ public class LookupItem<T> extends MutableLookupElement<T> implements Comparable
return myAllLookupStrings;
}
public void copyAttributes(final LookupItem item) {
if (myAttributes == null) {
if (item.myAttributes == null) return;
myAttributes = new HashMap<Object, Object>(5);
}
myAttributes.putAll(item.myAttributes);
}
@Override
public boolean isCaseSensitive() {
return !Boolean.TRUE.equals(getAttribute(CASE_INSENSITIVE));
}
public static @Nullable LookupItem from(LookupElement lookupElement) {
if (lookupElement instanceof LookupElementDecorator) {
lookupElement = ((LookupElementDecorator)lookupElement).getDelegate();
}
if (lookupElement instanceof LookupItem) return (LookupItem)lookupElement;
return null;
}
}
@@ -46,7 +46,7 @@ public abstract class TailTypeDecorator<T extends LookupElement> extends LookupE
final LookupElement delegate = getDelegate();
final TailType tailType = computeTailType(context);
final LookupItem lookupItem = delegate.as(LookupItem.class);
final LookupItem lookupItem = delegate.as(LookupItem.CLASS_CONDITION_KEY);
if (lookupItem != null && tailType != null) {
lookupItem.setTailType(TailType.UNKNOWN);
}
@@ -16,9 +16,8 @@
package com.intellij.codeInsight.lookup.impl;
import com.intellij.codeInsight.completion.CompletionProcess;
import com.intellij.codeInsight.completion.CompletionProgressIndicator;
import com.intellij.codeInsight.completion.CompletionService;
import com.intellij.codeInsight.completion.impl.CompletionServiceImpl;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
@@ -45,14 +44,14 @@ public class BackspaceHandler extends EditorActionHandler {
}
});
if (lookup.truncatePrefix()) {
final CompletionProgressIndicator process = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
if (lookup.truncatePrefix(process == null || !process.isAutopopupCompletion())) {
return;
}
if (lookup.getLookupStart() < editor.getCaretModel().getOffset()) {
final CompletionProcess process = CompletionService.getCompletionService().getCurrentCompletion();
if (process instanceof CompletionProgressIndicator) {
((CompletionProgressIndicator)process).scheduleRestart();
if (process != null) {
process.scheduleRestart();
return;
}
}
@@ -317,11 +317,13 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
ListScrollingUtil.ensureIndexIsVisible(myList, myList.getSelectedIndex(), 1);
}
public boolean truncatePrefix() {
public boolean truncatePrefix(boolean preserveSelection) {
final int len = myAdditionalPrefix.length();
if (len == 0) return false;
markSelectionTouched();
if (preserveSelection) {
markSelectionTouched();
}
myAdditionalPrefix = myAdditionalPrefix.substring(0, len - 1);
myInitialPrefix = null;
@@ -593,8 +595,8 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
if (item == null ||
item instanceof EmptyLookupItem ||
item.getObject() instanceof DeferredUserLookupValue &&
item.as(LookupItem.class) != null &&
!((DeferredUserLookupValue)item.getObject()).handleUserSelection(item.as(LookupItem.class), myProject)) {
item.as(LookupItem.CLASS_CONDITION_KEY) != null &&
!((DeferredUserLookupValue)item.getObject()).handleUserSelection(item.as(LookupItem.CLASS_CONDITION_KEY), myProject)) {
fireItemSelected(null, completionChar);
return;
}
@@ -133,7 +133,7 @@ public class LookupManagerImpl extends LookupManager {
final Alarm alarm = new Alarm();
final Runnable request = new Runnable() {
public void run() {
if (myActiveLookup == lookup) {
if (myActiveLookup == lookup && lookup.getCurrentItem() != null) {
final CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion();
if (completion == null || !completion.isAutopopupCompletion()) {
DocumentationManager.getInstance(myProject).showJavaDocInfo(editor, psiFile, false);
@@ -32,6 +32,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.ElementBase;
import com.intellij.psi.search.PsiElementProcessor;
import com.intellij.ui.components.JBList;
import org.jetbrains.annotations.NotNull;
@@ -89,11 +90,20 @@ public final class NavigationUtil {
}
public static void activateFileWithPsiElement(@NotNull PsiElement elt) {
if (!activatePsiElementIfOpen(elt)) {
boolean openAsNative = false;
if (elt instanceof PsiFile) {
VirtualFile virtualFile = ((PsiFile)elt).getVirtualFile();
if (virtualFile != null) {
openAsNative = ElementBase.isNativeFileType(virtualFile.getFileType());
}
}
if (openAsNative || !activatePsiElementIfOpen(elt)) {
((NavigationItem)elt).navigate(true);
}
}
private static boolean activatePsiElementIfOpen(@NotNull PsiElement elt) {
if (!elt.isValid()) return false;
elt = elt.getNavigationElement();

Some files were not shown because too many files have changed in this diff Show More