mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -45,7 +45,7 @@ public abstract class BuildArtifactsBeforeRunTaskBase<Self extends BuildArtifact
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) {
|
||||
public void readExternal(@NotNull Element element) {
|
||||
super.readExternal(element);
|
||||
final List<Element> children = element.getChildren(myElementName);
|
||||
final ArtifactPointerManager pointerManager = ArtifactPointerManager.getInstance(myProject);
|
||||
@@ -62,7 +62,7 @@ public abstract class BuildArtifactsBeforeRunTaskBase<Self extends BuildArtifact
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) {
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
super.writeExternal(element);
|
||||
for (ArtifactPointer pointer : myArtifactPointers) {
|
||||
element.addContent(new Element(myElementName).setAttribute(NAME_ATTRIBUTE, pointer.getArtifactName()));
|
||||
|
||||
+5
-5
@@ -80,7 +80,7 @@ public abstract class BuildArtifactsBeforeRunTaskProviderBase<T extends BuildArt
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean configureTask(RunConfiguration runConfiguration, T task) {
|
||||
public boolean configureTask(@NotNull RunConfiguration runConfiguration, @NotNull T task) {
|
||||
final Artifact[] artifacts = ArtifactManager.getInstance(myProject).getArtifacts();
|
||||
Set<ArtifactPointer> pointers = new THashSet<>();
|
||||
for (Artifact artifact : artifacts) {
|
||||
@@ -111,7 +111,7 @@ public abstract class BuildArtifactsBeforeRunTaskProviderBase<T extends BuildArt
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteTask(RunConfiguration configuration, T task) {
|
||||
public boolean canExecuteTask(@NotNull RunConfiguration configuration, @NotNull T task) {
|
||||
for (ArtifactPointer pointer : (List<ArtifactPointer>)task.getArtifactPointers()) {
|
||||
if (pointer.getArtifact() != null) {
|
||||
return true;
|
||||
@@ -121,9 +121,9 @@ public abstract class BuildArtifactsBeforeRunTaskProviderBase<T extends BuildArt
|
||||
}
|
||||
|
||||
public boolean executeTask(DataContext context,
|
||||
RunConfiguration configuration,
|
||||
final ExecutionEnvironment env,
|
||||
final T task) {
|
||||
@NotNull RunConfiguration configuration,
|
||||
@NotNull final ExecutionEnvironment env,
|
||||
@NotNull final T task) {
|
||||
final Ref<Boolean> result = Ref.create(false);
|
||||
final Semaphore finished = new Semaphore();
|
||||
|
||||
|
||||
@@ -106,16 +106,7 @@ public class CompileStepBeforeRun extends BeforeRunTaskProvider<CompileStepBefor
|
||||
return !(configuration instanceof RemoteConfiguration) && configuration instanceof RunProfileWithCompileBeforeLaunchOption;
|
||||
}
|
||||
|
||||
public boolean configureTask(RunConfiguration runConfiguration, MakeBeforeRunTask task) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteTask(RunConfiguration configuration, MakeBeforeRunTask task) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean executeTask(DataContext context, final RunConfiguration configuration, final ExecutionEnvironment env, MakeBeforeRunTask task) {
|
||||
public boolean executeTask(DataContext context, @NotNull final RunConfiguration configuration, @NotNull final ExecutionEnvironment env, @NotNull MakeBeforeRunTask task) {
|
||||
return doMake(myProject, configuration, env, false);
|
||||
}
|
||||
|
||||
@@ -187,10 +178,6 @@ public class CompileStepBeforeRun extends BeforeRunTaskProvider<CompileStepBefor
|
||||
return result.get();
|
||||
}
|
||||
|
||||
public boolean isConfigurable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static RunConfiguration getRunConfiguration(final CompileContext context) {
|
||||
return getRunConfiguration(context.getCompileScope());
|
||||
|
||||
+3
-18
@@ -61,31 +61,16 @@ public class CompileStepBeforeRunNoErrorCheck
|
||||
return CompileStepBeforeRun.shouldCreateTask(runConfiguration) ? new MakeBeforeRunTaskNoErrorCheck() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configureTask(RunConfiguration runConfiguration, MakeBeforeRunTaskNoErrorCheck task) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigurable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return ExecutionBundle.message("before.launch.compile.step.no.error.check");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteTask(RunConfiguration configuration, MakeBeforeRunTaskNoErrorCheck task) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeTask(DataContext context,
|
||||
RunConfiguration configuration,
|
||||
ExecutionEnvironment env,
|
||||
MakeBeforeRunTaskNoErrorCheck task) {
|
||||
@NotNull RunConfiguration configuration,
|
||||
@NotNull ExecutionEnvironment env,
|
||||
@NotNull MakeBeforeRunTaskNoErrorCheck task) {
|
||||
return CompileStepBeforeRun.doMake(myProject, configuration, env, true);
|
||||
}
|
||||
|
||||
|
||||
+1
-18
@@ -53,10 +53,6 @@ public class MakeProjectStepBeforeRun extends BeforeRunTaskProvider<MakeProjectS
|
||||
return ExecutionBundle.message("before.launch.make.project.step");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription(MakeProjectBeforeRunTask task) {
|
||||
return getName();
|
||||
}
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return AllIcons.Actions.Compile;
|
||||
@@ -67,23 +63,10 @@ public class MakeProjectStepBeforeRun extends BeforeRunTaskProvider<MakeProjectS
|
||||
return AllIcons.Actions.Compile;
|
||||
}
|
||||
|
||||
public boolean configureTask(RunConfiguration runConfiguration, MakeProjectBeforeRunTask task) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteTask(RunConfiguration configuration, MakeProjectBeforeRunTask task) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean executeTask(DataContext context, final RunConfiguration configuration, final ExecutionEnvironment env, MakeProjectBeforeRunTask task) {
|
||||
public boolean executeTask(DataContext context, @NotNull final RunConfiguration configuration, @NotNull final ExecutionEnvironment env, @NotNull MakeProjectBeforeRunTask task) {
|
||||
return CompileStepBeforeRun.doMake(myProject, configuration, env, false, true);
|
||||
}
|
||||
|
||||
public boolean isConfigurable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static RunConfiguration getRunConfiguration(final CompileContext context) {
|
||||
return getRunConfiguration(context.getCompileScope());
|
||||
|
||||
@@ -25,121 +25,108 @@ import com.intellij.lang.jvm.JvmClassKind
|
||||
import com.intellij.lang.jvm.JvmModifier
|
||||
import com.intellij.lang.jvm.actions.CreateFieldRequest
|
||||
import com.intellij.lang.jvm.actions.EP_NAME
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.util.PsiTreeUtil.getParentOfType
|
||||
import com.intellij.psi.util.PsiUtil.resolveClassInClassTypeOnly
|
||||
import com.intellij.psi.util.parentOfType
|
||||
import com.intellij.psi.util.parentsOfType
|
||||
import com.intellij.util.VisibilityUtil
|
||||
import java.util.*
|
||||
import kotlin.collections.LinkedHashSet
|
||||
|
||||
fun generateActions(ref: PsiReferenceExpression): List<IntentionAction> {
|
||||
ref.referenceName ?: return emptyList()
|
||||
if (ref.referenceName == null) return emptyList()
|
||||
val fieldRequests = CreateFieldRequests(ref).collectRequests()
|
||||
val extensions = EP_NAME.extensions
|
||||
return generateRequests(ref).flatMap { (clazz, request) ->
|
||||
return fieldRequests.flatMap { (clazz, request) ->
|
||||
extensions.flatMap { ext ->
|
||||
ext.createAddFieldActions(clazz, request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateRequests(ref: PsiReferenceExpression): List<Pair<JvmClass, CreateFieldRequest>> {
|
||||
val (instanceContext, staticContext) = collectTargets(ref) ?: return emptyList()
|
||||
private class CreateFieldRequests(val myRef: PsiReferenceExpression) {
|
||||
|
||||
val instanceFieldRequests = instanceContext.filter {
|
||||
it.classKind !in STATIC_ONLY
|
||||
}.map {
|
||||
it to generateRequest(ref, it, false)
|
||||
}
|
||||
val staticFieldRequests = staticContext.map {
|
||||
it to generateRequest(ref, it, true)
|
||||
private val requests = LinkedHashMap<JvmClass, CreateFieldRequest>()
|
||||
|
||||
fun collectRequests(): Map<JvmClass, CreateFieldRequest> {
|
||||
doCollectRequests()
|
||||
return requests
|
||||
}
|
||||
|
||||
return instanceFieldRequests + staticFieldRequests
|
||||
private fun doCollectRequests() {
|
||||
val qualifier = myRef.qualifierExpression
|
||||
|
||||
if (qualifier != null) {
|
||||
val instanceClass = resolveClassInClassTypeOnly(qualifier.type)
|
||||
if (instanceClass != null) {
|
||||
processHierarchy(instanceClass)
|
||||
}
|
||||
else {
|
||||
val staticClass = (qualifier as? PsiJavaCodeReferenceElement)?.resolve() as? PsiClass
|
||||
if (staticClass != null) {
|
||||
processClass(staticClass, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
val baseClass = extractBaseClassFromSwitchStatement()
|
||||
if (baseClass != null) {
|
||||
processHierarchy(baseClass)
|
||||
}
|
||||
else {
|
||||
processOuterAndImported()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun extractBaseClassFromSwitchStatement(): PsiClass? {
|
||||
val parent = myRef.parent as? PsiSwitchLabelStatement ?: return null
|
||||
val switchStatement = parent.parentOfType<PsiSwitchStatement>() ?: return null
|
||||
return resolveClassInClassTypeOnly(switchStatement.expression?.type)
|
||||
}
|
||||
|
||||
private fun processHierarchy(baseClass: PsiClass) {
|
||||
for (clazz in hierarchy(baseClass)) {
|
||||
processClass(clazz, false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun processOuterAndImported() {
|
||||
val inStaticContext = myRef.isInStaticContext()
|
||||
for (outerClass in collectOuterClasses(myRef)) {
|
||||
processClass(outerClass, inStaticContext)
|
||||
}
|
||||
for (imported in collectOnDemandImported(myRef)) {
|
||||
processClass(imported, true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun processClass(target: JvmClass, staticContext: Boolean) {
|
||||
if (!staticContext && target.classKind in STATIC_ONLY) return
|
||||
val modifiers = mutableSetOf<JvmModifier>()
|
||||
|
||||
if (staticContext) {
|
||||
modifiers += JvmModifier.STATIC
|
||||
}
|
||||
|
||||
if (shouldCreateFinalField(myRef, target)) {
|
||||
modifiers += JvmModifier.FINAL
|
||||
}
|
||||
|
||||
val ownerClass = myRef.parentOfType<PsiClass>()
|
||||
val visibility = computeVisibility(myRef.project, ownerClass, target)
|
||||
if (visibility != null) {
|
||||
modifiers += visibility
|
||||
}
|
||||
|
||||
val request = CreateFieldFromJavaUsageRequest(
|
||||
modifiers = modifiers,
|
||||
reference = myRef,
|
||||
useAnchor = target.toJavaClassOrNull() == ownerClass,
|
||||
constant = false
|
||||
)
|
||||
requests[target] = request
|
||||
}
|
||||
}
|
||||
|
||||
private val STATIC_ONLY = arrayOf(JvmClassKind.INTERFACE, JvmClassKind.ANNOTATION)
|
||||
|
||||
private fun generateRequest(ref: PsiReferenceExpression, target: JvmClass, static: Boolean): CreateFieldRequest {
|
||||
val modifiers = mutableSetOf<JvmModifier>()
|
||||
|
||||
if (static) {
|
||||
modifiers += JvmModifier.STATIC
|
||||
}
|
||||
|
||||
if (shouldCreateFinalField(ref, target)) {
|
||||
modifiers += JvmModifier.FINAL
|
||||
}
|
||||
|
||||
val ownerClass = getParentOfType(ref, PsiClass::class.java)
|
||||
val visibility = computeVisibility(ref.project, ownerClass, target)
|
||||
if (visibility != null) {
|
||||
modifiers += visibility
|
||||
}
|
||||
|
||||
return CreateFieldFromJavaUsageRequest(
|
||||
modifiers = modifiers,
|
||||
reference = ref,
|
||||
useAnchor = target.toJavaClassOrNull() == ownerClass,
|
||||
constant = false
|
||||
)
|
||||
}
|
||||
|
||||
private typealias Couple<T> = Pair<T, T>
|
||||
|
||||
private fun collectTargets(ref: PsiReferenceExpression): Couple<List<JvmClass>>? {
|
||||
var baseClass: PsiClass? = null
|
||||
var inStaticContext = false
|
||||
val qualifier: PsiExpression? = ref.qualifierExpression
|
||||
|
||||
if (qualifier == null) {
|
||||
val parent = ref.parent
|
||||
if (parent is PsiSwitchLabelStatement) {
|
||||
val switchStatement = getParentOfType(parent, PsiSwitchStatement::class.java)
|
||||
if (switchStatement != null) {
|
||||
baseClass = resolveClassInClassTypeOnly(switchStatement.expression?.type)
|
||||
}
|
||||
}
|
||||
if (baseClass == null) {
|
||||
return collectOuterAndImported(ref)
|
||||
}
|
||||
}
|
||||
else {
|
||||
baseClass = resolveClassInClassTypeOnly(qualifier.type)
|
||||
if (baseClass == null) {
|
||||
inStaticContext = true
|
||||
baseClass = (qualifier as? PsiJavaCodeReferenceElement)?.resolve() as? PsiClass
|
||||
}
|
||||
}
|
||||
baseClass ?: return null
|
||||
if (inStaticContext) {
|
||||
return Pair(emptyList(), listOf(baseClass))
|
||||
}
|
||||
val hierarchy = hierarchy(baseClass).filter { it !is PsiTypeParameter }
|
||||
return Pair(hierarchy, emptyList())
|
||||
}
|
||||
|
||||
private fun collectOuterAndImported(place: PsiElement): Couple<List<JvmClass>> {
|
||||
val inStaticContext = place.parentOfType<PsiMember>()?.hasModifierProperty(PsiModifier.STATIC) ?: false
|
||||
val outerClasses = collectOuterClasses(place)
|
||||
val importedClasses = collectOnDemandImported(place)
|
||||
return if (inStaticContext) Pair(emptyList(), outerClasses + importedClasses) else Pair(outerClasses, importedClasses)
|
||||
}
|
||||
|
||||
private fun collectOuterClasses(place: PsiElement): List<JvmClass> {
|
||||
val result = mutableListOf<PsiClass>()
|
||||
for (clazz in place.parentsOfType<PsiClass>()) {
|
||||
result.add(clazz)
|
||||
if (clazz.hasModifierProperty(PsiModifier.STATIC)) break
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Given unresolved unqualified reference,
|
||||
* this reference could be resolved into static member if some class which has it's members imported.
|
||||
@@ -155,41 +142,7 @@ private fun collectOnDemandImported(place: PsiElement): List<JvmClass> {
|
||||
return onDemandImports.mapNotNull { it.resolveTargetClass() }
|
||||
}
|
||||
|
||||
private fun hierarchy(clazz: PsiClass): Collection<PsiClass> {
|
||||
val result = LinkedHashSet<PsiClass>()
|
||||
val queue = LinkedList<PsiClass>()
|
||||
queue.add(clazz)
|
||||
while (queue.isNotEmpty()) {
|
||||
val current = queue.removeFirst()
|
||||
if (result.add(current)) {
|
||||
queue.addAll(current.supers)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun shouldCreateFinalField(ref: PsiReferenceExpression, targetClass: JvmClass): Boolean {
|
||||
val javaClass = targetClass.toJavaClassOrNull() ?: return false
|
||||
return CreateFieldFromUsageFix.shouldCreateFinalMember(ref, javaClass)
|
||||
}
|
||||
|
||||
private fun computeVisibility(project: Project, ownerClass: PsiClass?, targetClass: JvmClass): JvmModifier? {
|
||||
if (targetClass.classKind == JvmClassKind.INTERFACE || targetClass.classKind == JvmClassKind.ANNOTATION) return JvmModifier.PUBLIC
|
||||
if (ownerClass != null) {
|
||||
targetClass.toJavaClassOrNull()?.let { javaClass ->
|
||||
if (javaClass == ownerClass || PsiTreeUtil.isAncestor(javaClass, ownerClass, false)) {
|
||||
return JvmModifier.PRIVATE
|
||||
}
|
||||
}
|
||||
}
|
||||
val setting = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings::class.java).VISIBILITY
|
||||
if (setting == VisibilityUtil.ESCALATE_VISIBILITY) {
|
||||
return null // TODO
|
||||
}
|
||||
else if (setting == PsiModifier.PACKAGE_LOCAL) {
|
||||
return JvmModifier.PACKAGE_LOCAL
|
||||
}
|
||||
else {
|
||||
return JvmModifier.valueOf(setting.toUpperCase())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.lang.java.request
|
||||
|
||||
import com.intellij.lang.java.actions.toJavaClassOrNull
|
||||
import com.intellij.lang.jvm.JvmClass
|
||||
import com.intellij.lang.jvm.JvmClassKind
|
||||
import com.intellij.lang.jvm.JvmModifier
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.util.parentOfType
|
||||
import com.intellij.psi.util.parents
|
||||
import com.intellij.psi.util.parentsOfType
|
||||
import com.intellij.util.VisibilityUtil
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
internal fun PsiExpression.isInStaticContext(): Boolean {
|
||||
return isWithinStaticMember() || isWithinConstructorCall()
|
||||
}
|
||||
|
||||
internal fun PsiExpression.isWithinStaticMember(): Boolean {
|
||||
return parentOfType<PsiMember>()?.hasModifierProperty(PsiModifier.STATIC) ?: false
|
||||
}
|
||||
|
||||
//usages inside delegating constructor call
|
||||
internal fun PsiExpression.isWithinConstructorCall(): Boolean {
|
||||
val owner = parentOfType<PsiModifierListOwner>() as? PsiMethod ?: return false
|
||||
if (!owner.isConstructor) return false
|
||||
|
||||
val parent = parents().firstOrNull { it !is PsiExpression } as? PsiExpressionList ?: return false
|
||||
val grandParent = parent.parent as? PsiMethodCallExpression ?: return false
|
||||
|
||||
val calleText = grandParent.methodExpression.text
|
||||
return calleText == PsiKeyword.SUPER || calleText == PsiKeyword.THIS
|
||||
}
|
||||
|
||||
internal fun computeVisibility(project: Project, ownerClass: PsiClass?, targetClass: JvmClass): JvmModifier? {
|
||||
if (targetClass.classKind == JvmClassKind.INTERFACE || targetClass.classKind == JvmClassKind.ANNOTATION) return JvmModifier.PUBLIC
|
||||
if (ownerClass != null) {
|
||||
targetClass.toJavaClassOrNull()?.let { javaClass ->
|
||||
if (javaClass == ownerClass || PsiTreeUtil.isAncestor(javaClass, ownerClass, false)) {
|
||||
return JvmModifier.PRIVATE
|
||||
}
|
||||
}
|
||||
}
|
||||
val setting = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings::class.java).VISIBILITY
|
||||
if (setting == VisibilityUtil.ESCALATE_VISIBILITY) {
|
||||
return null // TODO
|
||||
}
|
||||
else if (setting == PsiModifier.PACKAGE_LOCAL) {
|
||||
return JvmModifier.PACKAGE_LOCAL
|
||||
}
|
||||
else {
|
||||
return JvmModifier.valueOf(setting.toUpperCase())
|
||||
}
|
||||
}
|
||||
|
||||
internal fun collectOuterClasses(place: PsiElement): List<PsiClass> {
|
||||
val result = ArrayList<PsiClass>()
|
||||
for (clazz in place.parentsOfType<PsiClass>()) {
|
||||
result.add(clazz)
|
||||
if (clazz.hasModifierProperty(PsiModifier.STATIC)) break
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
internal fun hierarchy(clazz: PsiClass): List<PsiClass> { // TODO implementation based on JvmClasses
|
||||
val result = LinkedHashSet<PsiClass>()
|
||||
val queue = LinkedList<PsiClass>()
|
||||
queue.add(clazz)
|
||||
while (queue.isNotEmpty()) {
|
||||
val current = queue.removeFirst()
|
||||
if (result.add(current)) {
|
||||
queue.addAll(current.supers)
|
||||
}
|
||||
}
|
||||
return result.filter { it !is PsiTypeParameter }
|
||||
}
|
||||
@@ -16,15 +16,17 @@
|
||||
package com.intellij.psi.util
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
inline fun <reified T : PsiElement> PsiElement.parentOfType(): T? {
|
||||
return PsiTreeUtil.getParentOfType(this, T::class.java)
|
||||
inline fun <reified T : PsiElement> PsiElement.parentOfType(): T? = parentOfType(T::class)
|
||||
|
||||
fun <T : PsiElement> PsiElement.parentOfType(vararg classes: KClass<out T>): T? {
|
||||
return PsiTreeUtil.getParentOfType(this, *classes.map { it.java }.toTypedArray())
|
||||
}
|
||||
|
||||
inline fun <reified T : PsiElement> PsiElement?.parentsOfType(): Sequence<T> {
|
||||
return parentsOfType(T::class.java)
|
||||
}
|
||||
|
||||
fun <T : PsiElement> PsiElement?.parentsOfType(clazz: Class<T>): Sequence<T> {
|
||||
return generateSequence(this) { it.parent }.filterIsInstance(clazz)
|
||||
}
|
||||
inline fun <reified T : PsiElement> PsiElement.parentsOfType(): Sequence<T> = parentsOfType(T::class.java)
|
||||
|
||||
fun <T : PsiElement> PsiElement.parentsOfType(clazz: Class<out T>): Sequence<T> = parents().filterIsInstance(clazz)
|
||||
|
||||
fun PsiElement.parents(): Sequence<PsiElement> = generateSequence(this) { it.parent }
|
||||
|
||||
+3
-2
@@ -60,6 +60,7 @@ import com.intellij.psi.xml.XmlToken;
|
||||
import com.intellij.psi.xml.XmlTokenType;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.VfsTestUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -196,10 +197,10 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
}
|
||||
finally {
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
VirtualFile file = FileDocumentManager.getInstance().getFile(e.getDocument());
|
||||
VirtualFile file = ObjectUtils.notNull(FileDocumentManager.getInstance().getFile(e.getDocument()));
|
||||
FileEditorManager.getInstance(getProject()).closeFile(file);
|
||||
VfsTestUtil.deleteFile(file);
|
||||
VirtualFile file2 = FileDocumentManager.getInstance().getFile(e2.getDocument());
|
||||
VirtualFile file2 = ObjectUtils.notNull(FileDocumentManager.getInstance().getFile(e2.getDocument()));
|
||||
FileEditorManager.getInstance(getProject()).closeFile(file2);
|
||||
VfsTestUtil.deleteFile(file2);
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ public class RootsChangedTest extends ModuleTestCase {
|
||||
rootModelB.addLibraryEntry(libraryA);
|
||||
rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
|
||||
rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
|
||||
ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
|
||||
ModifiableRootModel[] rootModels = {rootModelA, rootModelB};
|
||||
if (rootModels.length > 0) {
|
||||
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
|
||||
}
|
||||
@@ -317,7 +317,7 @@ public class RootsChangedTest extends ModuleTestCase {
|
||||
final Library libraryQ = libraryTable.createLibrary("Q");
|
||||
assertEventsCount(0);
|
||||
|
||||
ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
|
||||
ModifiableRootModel[] rootModels = {rootModelA, rootModelB};
|
||||
if (rootModels.length > 0) {
|
||||
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
|
||||
}
|
||||
@@ -337,8 +337,8 @@ public class RootsChangedTest extends ModuleTestCase {
|
||||
}
|
||||
|
||||
private static class MyModuleRootListener implements ModuleRootListener {
|
||||
private int beforeCount = 0;
|
||||
private int afterCount = 0;
|
||||
private int beforeCount;
|
||||
private int afterCount;
|
||||
|
||||
@Override
|
||||
public void beforeRootsChange(ModuleRootEvent event) {
|
||||
|
||||
@@ -73,7 +73,6 @@ public abstract class SuppressIntentionAction implements Iconable, IntentionActi
|
||||
* @param project the project in which the file is opened.
|
||||
* @param editor the editor for the file.
|
||||
* @param element the element under cursor.
|
||||
* @throws IncorrectOperationException
|
||||
*
|
||||
*/
|
||||
public abstract void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException;
|
||||
|
||||
@@ -37,6 +37,8 @@ import java.net.URL;
|
||||
* Date: 9/28/11
|
||||
*/
|
||||
public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E extends InspectionEP> {
|
||||
public static final InspectionToolWrapper[] EMPTY_ARRAY = new InspectionToolWrapper[0];
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionToolWrapper");
|
||||
|
||||
protected T myTool;
|
||||
|
||||
+3
-1
@@ -50,7 +50,8 @@ public class SuppressIntentionActionFromFix extends SuppressIntentionAction {
|
||||
|
||||
@NotNull
|
||||
public static SuppressIntentionAction[] convertBatchToSuppressIntentionActions(@NotNull SuppressQuickFix[] actions) {
|
||||
return ContainerUtil.map2Array(actions, SuppressIntentionAction.class, fix -> convertBatchToSuppressIntentionAction(fix));
|
||||
return ContainerUtil.map2Array(actions, SuppressIntentionAction.class,
|
||||
SuppressIntentionActionFromFix::convertBatchToSuppressIntentionAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,6 +94,7 @@ public class SuppressIntentionActionFromFix extends SuppressIntentionAction {
|
||||
return myFix.getFamilyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuppressAll() {
|
||||
return myFix.isSuppressAll();
|
||||
}
|
||||
|
||||
+2
@@ -165,6 +165,7 @@ class CompilationContextImpl implements CompilationContext {
|
||||
unpackCompiledClasses(messages, ant, classesOutput, options)
|
||||
outputDirectoriesToKeep.add(classesDirName)
|
||||
}
|
||||
messages.info("Incremental compilation: " + options.incrementalCompilation)
|
||||
if (options.incrementalCompilation) {
|
||||
outputDirectoriesToKeep.add(dataDirName)
|
||||
outputDirectoriesToKeep.add(classesDirName)
|
||||
@@ -211,6 +212,7 @@ class CompilationContextImpl implements CompilationContext {
|
||||
messages.info("Skipped cleaning for $file.absolutePath")
|
||||
}
|
||||
else {
|
||||
messages.info("Deleting $file.absolutePath")
|
||||
FileUtil.delete(file)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -44,7 +44,7 @@ public class ExternalSystemBeforeRunTask extends BeforeRunTask<ExternalSystemBef
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) {
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
super.writeExternal(element);
|
||||
|
||||
element.setAttribute("tasks", StringUtil.join(myTaskExecutionSettings.getTaskNames(), " "));
|
||||
@@ -58,7 +58,7 @@ public class ExternalSystemBeforeRunTask extends BeforeRunTask<ExternalSystemBef
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) {
|
||||
public void readExternal(@NotNull Element element) {
|
||||
super.readExternal(element);
|
||||
myTaskExecutionSettings.setTaskNames(StringUtil.split(StringUtil.notNullize(element.getAttributeValue("tasks")), " "));
|
||||
myTaskExecutionSettings.setExternalProjectPath(element.getAttributeValue("externalProjectPath"));
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -75,7 +75,7 @@ public abstract class ExternalSystemBeforeRunTaskProvider extends BeforeRunTaskP
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configureTask(RunConfiguration runConfiguration, ExternalSystemBeforeRunTask task) {
|
||||
public boolean configureTask(@NotNull RunConfiguration runConfiguration, @NotNull ExternalSystemBeforeRunTask task) {
|
||||
ExternalSystemEditTaskDialog dialog = new ExternalSystemEditTaskDialog(myProject, task.getTaskExecutionSettings(), mySystemId);
|
||||
dialog.setTitle(ExternalSystemBundle.message("tasks.select.task.title", mySystemId.getReadableName()));
|
||||
|
||||
@@ -87,7 +87,7 @@ public abstract class ExternalSystemBeforeRunTaskProvider extends BeforeRunTaskP
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteTask(RunConfiguration configuration, ExternalSystemBeforeRunTask beforeRunTask) {
|
||||
public boolean canExecuteTask(@NotNull RunConfiguration configuration, @NotNull ExternalSystemBeforeRunTask beforeRunTask) {
|
||||
final ExternalSystemTaskExecutionSettings executionSettings = beforeRunTask.getTaskExecutionSettings();
|
||||
|
||||
final List<ExternalTaskPojo> tasks = ContainerUtilRt.newArrayList();
|
||||
@@ -106,9 +106,9 @@ public abstract class ExternalSystemBeforeRunTaskProvider extends BeforeRunTaskP
|
||||
|
||||
@Override
|
||||
public boolean executeTask(DataContext context,
|
||||
RunConfiguration configuration,
|
||||
ExecutionEnvironment env,
|
||||
ExternalSystemBeforeRunTask beforeRunTask) {
|
||||
@NotNull RunConfiguration configuration,
|
||||
@NotNull ExecutionEnvironment env,
|
||||
@NotNull ExternalSystemBeforeRunTask beforeRunTask) {
|
||||
|
||||
final ExternalSystemTaskExecutionSettings executionSettings = beforeRunTask.getTaskExecutionSettings();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.execution;
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -27,6 +28,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
public abstract class BeforeRunTask<T extends BeforeRunTask> implements Cloneable {
|
||||
@NotNull
|
||||
protected final Key<T> myProviderId;
|
||||
|
||||
// cannot be set to true by default, because RunManager.getHardcodedBeforeRunTasks creates before run task for each provider
|
||||
// and some providers set enabled to true in the constructor to indicate, that before run task should be added to RC by default (on create)
|
||||
private boolean myIsEnabled;
|
||||
|
||||
protected BeforeRunTask(@NotNull Key<T> providerId) {
|
||||
@@ -46,18 +50,27 @@ public abstract class BeforeRunTask<T extends BeforeRunTask> implements Cloneabl
|
||||
myIsEnabled = isEnabled;
|
||||
}
|
||||
|
||||
public void writeExternal(Element element) {
|
||||
element.setAttribute("enabled", String.valueOf(myIsEnabled));
|
||||
/**
|
||||
* @deprecated Use PersistentStateComponent (see LaunchBrowserBeforeRunTask for example).
|
||||
*/
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
if (this instanceof PersistentStateComponent) {
|
||||
((PersistentStateComponent)this).getState();
|
||||
}
|
||||
else {
|
||||
element.setAttribute("enabled", String.valueOf(myIsEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
public void readExternal(Element element) {
|
||||
/**
|
||||
* @deprecated Use PersistentStateComponent (see LaunchBrowserBeforeRunTask for example).
|
||||
*/
|
||||
public void readExternal(@NotNull Element element) {
|
||||
String attribValue = element.getAttributeValue("enabled");
|
||||
if (attribValue == null) {
|
||||
attribValue = element.getAttributeValue("value"); // maintain compatibility with old format
|
||||
}
|
||||
if (attribValue == null)
|
||||
attribValue = "true";
|
||||
myIsEnabled = Boolean.valueOf(attribValue).booleanValue();
|
||||
myIsEnabled = attribValue == null || Boolean.parseBoolean(attribValue);
|
||||
}
|
||||
|
||||
//Task may aggregate several items or targets to do (e.g. BuildArtifactsBeforeRunTask)
|
||||
|
||||
@@ -41,15 +41,18 @@ public abstract class BeforeRunTaskProvider<T extends BeforeRunTask> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract String getDescription(T task);
|
||||
|
||||
public String getDescription(T task) {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Icon getTaskIcon(T task) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean isConfigurable();
|
||||
public boolean isConfigurable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'before run' task for the configuration or null, if the task from this provider is not applicable to the specified configuration
|
||||
@@ -60,11 +63,15 @@ public abstract class BeforeRunTaskProvider<T extends BeforeRunTask> {
|
||||
/**
|
||||
* @return {@code true} if task configuration is changed
|
||||
*/
|
||||
public abstract boolean configureTask(final RunConfiguration runConfiguration, T task);
|
||||
public boolean configureTask(@NotNull RunConfiguration runConfiguration, @NotNull T task) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract boolean canExecuteTask(RunConfiguration configuration, T task);
|
||||
public boolean canExecuteTask(@NotNull RunConfiguration configuration, @NotNull T task) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, T task);
|
||||
public abstract boolean executeTask(DataContext context, @NotNull RunConfiguration configuration, @NotNull ExecutionEnvironment env, @NotNull T task);
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
+1
@@ -250,6 +250,7 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr
|
||||
@Override
|
||||
public void setDocument(Document doc) {
|
||||
super.setDocument(doc);
|
||||
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
|
||||
if (doc instanceof StyledDocument) {
|
||||
doc.putProperty("imageCache", myImageProvider);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import java.util.Map;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class GotoInspectionModel extends SimpleChooseByNameModel {
|
||||
private static final InspectionToolWrapper[] EMPTY_WRAPPERS_ARRAY = new InspectionToolWrapper[0];
|
||||
private final Map<String, InspectionToolWrapper> myToolNames = new HashMap<>();
|
||||
private final String[] myNames;
|
||||
private final InspectionListCellRenderer myListCellRenderer = new InspectionListCellRenderer();
|
||||
@@ -69,7 +68,7 @@ public class GotoInspectionModel extends SimpleChooseByNameModel {
|
||||
public Object[] getElementsByName(final String name, final String pattern) {
|
||||
final InspectionToolWrapper tool = myToolNames.get(name);
|
||||
if (tool == null) {
|
||||
return EMPTY_WRAPPERS_ARRAY;
|
||||
return InspectionToolWrapper.EMPTY_ARRAY;
|
||||
}
|
||||
return new InspectionToolWrapper[] {tool};
|
||||
}
|
||||
|
||||
+8
-8
@@ -125,7 +125,7 @@ extends BeforeRunTaskProvider<RunConfigurationBeforeRunProvider.RunConfigurableB
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configureTask(RunConfiguration runConfiguration, RunConfigurableBeforeRunTask task) {
|
||||
public boolean configureTask(@NotNull RunConfiguration runConfiguration, @NotNull RunConfigurableBeforeRunTask task) {
|
||||
SelectionDialog dialog =
|
||||
new SelectionDialog(task.getSettings(), getAvailableConfigurations(runConfiguration));
|
||||
dialog.show();
|
||||
@@ -159,8 +159,8 @@ extends BeforeRunTaskProvider<RunConfigurationBeforeRunProvider.RunConfigurableB
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteTask(RunConfiguration configuration,
|
||||
RunConfigurableBeforeRunTask task) {
|
||||
public boolean canExecuteTask(@NotNull RunConfiguration configuration,
|
||||
@NotNull RunConfigurableBeforeRunTask task) {
|
||||
RunnerAndConfigurationSettings settings = task.getSettings();
|
||||
if (settings == null) {
|
||||
return false;
|
||||
@@ -172,9 +172,9 @@ extends BeforeRunTaskProvider<RunConfigurationBeforeRunProvider.RunConfigurableB
|
||||
|
||||
@Override
|
||||
public boolean executeTask(final DataContext dataContext,
|
||||
RunConfiguration configuration,
|
||||
final ExecutionEnvironment env,
|
||||
RunConfigurableBeforeRunTask task) {
|
||||
@NotNull RunConfiguration configuration,
|
||||
@NotNull final ExecutionEnvironment env,
|
||||
@NotNull RunConfigurableBeforeRunTask task) {
|
||||
RunnerAndConfigurationSettings settings = task.getSettings();
|
||||
if (settings == null) {
|
||||
return true; // ignore missing configurations: IDEA-155476 Run/debug silently fails when 'Run another configuration' step is broken
|
||||
@@ -291,7 +291,7 @@ extends BeforeRunTaskProvider<RunConfigurationBeforeRunProvider.RunConfigurableB
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) {
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
super.writeExternal(element);
|
||||
if (myConfigurationName != null && myConfigurationType != null) {
|
||||
element.setAttribute("run_configuration_name", myConfigurationName);
|
||||
@@ -304,7 +304,7 @@ extends BeforeRunTaskProvider<RunConfigurationBeforeRunProvider.RunConfigurableB
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) {
|
||||
public void readExternal(@NotNull Element element) {
|
||||
super.readExternal(element);
|
||||
|
||||
myConfigurationName = element.getAttributeValue("run_configuration_name");
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package com.intellij.execution.impl
|
||||
|
||||
import com.intellij.ProjectTopics
|
||||
import com.intellij.configurationStore.OLD_NAME_CONVERTER
|
||||
import com.intellij.configurationStore.SchemeManagerIprProvider
|
||||
import com.intellij.configurationStore.save
|
||||
import com.intellij.configurationStore.*
|
||||
import com.intellij.execution.*
|
||||
import com.intellij.execution.compound.CompoundRunConfiguration
|
||||
import com.intellij.execution.configurations.*
|
||||
@@ -58,6 +56,7 @@ import kotlin.concurrent.write
|
||||
private val SELECTED_ATTR = "selected"
|
||||
internal val METHOD = "method"
|
||||
private val OPTION = "option"
|
||||
private val RECENT = "recent_temporary"
|
||||
|
||||
// open for Upsource (UpsourceRunManager overrides to disable loadState (empty impl))
|
||||
@State(name = "RunManager", defaultStateAsResource = true, storages = arrayOf(Storage(StoragePathMacros.WORKSPACE_FILE)))
|
||||
@@ -65,7 +64,6 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi
|
||||
companion object {
|
||||
@JvmField
|
||||
val CONFIGURATION = "configuration"
|
||||
private val RECENT = "recent_temporary"
|
||||
@JvmField
|
||||
val NAME_ATTR = "name"
|
||||
|
||||
@@ -607,7 +605,15 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi
|
||||
for (task in tasks) {
|
||||
val child = Element(OPTION)
|
||||
child.setAttribute(NAME_ATTR, task.providerId.toString())
|
||||
task.writeExternal(child)
|
||||
if (task is PersistentStateComponent<*>) {
|
||||
if (!task.isEnabled) {
|
||||
child.setAttribute("enabled", "false")
|
||||
}
|
||||
task.serializeStateInto(child)
|
||||
}
|
||||
else {
|
||||
task.writeExternal(child)
|
||||
}
|
||||
methodElement.addContent(child)
|
||||
}
|
||||
return methodElement
|
||||
@@ -800,7 +806,14 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi
|
||||
val key = methodElement.getAttributeValue(NAME_ATTR)
|
||||
val provider = stringIdToBeforeRunProvider.getOrPut(key) { UnknownBeforeRunTaskProvider(key) }
|
||||
val beforeRunTask = (if (provider is RunConfigurationBeforeRunProvider) provider.createTask(settings.configuration, this) else provider.createTask(settings.configuration)) ?: continue
|
||||
beforeRunTask.readExternal(methodElement)
|
||||
if (beforeRunTask is PersistentStateComponent<*>) {
|
||||
// for PersistentStateComponent we don't write default value for enabled, so, set it to true explicitly
|
||||
beforeRunTask.isEnabled = true
|
||||
beforeRunTask.deserializeAndLoadState(methodElement)
|
||||
}
|
||||
else {
|
||||
beforeRunTask.readExternal(methodElement)
|
||||
}
|
||||
if (result == null) {
|
||||
result = SmartList()
|
||||
}
|
||||
@@ -996,8 +1009,8 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi
|
||||
private fun getHardcodedBeforeRunTasks(configuration: RunConfiguration): List<BeforeRunTask<*>> {
|
||||
var result: MutableList<BeforeRunTask<*>>? = null
|
||||
for (provider in Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, project)) {
|
||||
val task = provider.createTask(configuration)
|
||||
if (task != null && task.isEnabled) {
|
||||
val task = provider.createTask(configuration) ?: continue
|
||||
if (task.isEnabled) {
|
||||
configuration.factory.configureBeforeRunTaskDefaults(provider.id, task)
|
||||
if (task.isEnabled) {
|
||||
if (result == null) {
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ package com.intellij.execution.impl
|
||||
|
||||
import com.intellij.configurationStore.SerializableScheme
|
||||
import com.intellij.configurationStore.deserializeAndLoadState
|
||||
import com.intellij.configurationStore.serializeInto
|
||||
import com.intellij.configurationStore.serializeStateInto
|
||||
import com.intellij.execution.*
|
||||
import com.intellij.execution.configurations.*
|
||||
import com.intellij.execution.runners.ProgramRunner
|
||||
@@ -282,7 +282,7 @@ class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(private val m
|
||||
|
||||
private fun serializeConfigurationInto(configuration: RunConfiguration, element: Element) {
|
||||
if (configuration is PersistentStateComponent<*>) {
|
||||
configuration.state!!.serializeInto(element)
|
||||
configuration.serializeStateInto(element)
|
||||
}
|
||||
else {
|
||||
configuration.writeExternal(element)
|
||||
|
||||
+7
-12
@@ -57,25 +57,20 @@ public class UnknownBeforeRunTaskProvider extends BeforeRunTaskProvider<UnknownB
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configureTask(RunConfiguration runConfiguration, UnknownTask task) {
|
||||
public boolean configureTask(@NotNull RunConfiguration runConfiguration, @NotNull UnknownTask task) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteTask(RunConfiguration configuration, UnknownTask task) {
|
||||
public boolean canExecuteTask(@NotNull RunConfiguration configuration, @NotNull UnknownTask task) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, UnknownTask task) {
|
||||
public boolean executeTask(DataContext context, @NotNull RunConfiguration configuration, @NotNull ExecutionEnvironment env, @NotNull UnknownTask task) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigurable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnknownTask createTask(@NotNull RunConfiguration runConfiguration) {
|
||||
return new UnknownTask(getId());
|
||||
@@ -89,20 +84,20 @@ public class UnknownBeforeRunTaskProvider extends BeforeRunTaskProvider<UnknownB
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) {
|
||||
public void readExternal(@NotNull Element element) {
|
||||
myConfig = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) {
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
if (myConfig != null) {
|
||||
element.removeContent();
|
||||
final List attributes = myConfig.getAttributes();
|
||||
for (Object attribute : attributes) {
|
||||
element.setAttribute((Attribute)((Attribute)attribute).clone());
|
||||
element.setAttribute(((Attribute)attribute).clone());
|
||||
}
|
||||
for (Object child : myConfig.getChildren()) {
|
||||
element.addContent((Element)((Element)child).clone());
|
||||
element.addContent(((Element)child).clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -38,7 +38,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
},
|
||||
additionalExportFile = CodeStyleSchemesImpl.CODE_STYLES_DIR_PATH
|
||||
)
|
||||
class PersistableCodeStyleSchemes extends CodeStyleSchemesImpl implements PersistentStateComponent<Element> {
|
||||
public class PersistableCodeStyleSchemes extends CodeStyleSchemesImpl implements PersistentStateComponent<Element> {
|
||||
public String CURRENT_SCHEME_NAME = CodeStyleSchemeImpl.DEFAULT_SCHEME_NAME;
|
||||
|
||||
public PersistableCodeStyleSchemes(@NotNull SchemeManagerFactory schemeManagerFactory) {
|
||||
@@ -65,6 +65,7 @@ class PersistableCodeStyleSchemes extends CodeStyleSchemesImpl implements Persis
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
CURRENT_SCHEME_NAME = CodeStyleSchemeImpl.DEFAULT_SCHEME_NAME;
|
||||
XmlSerializer.deserializeInto(this, state);
|
||||
CodeStyleScheme current = CURRENT_SCHEME_NAME == null ? null : mySchemeManager.findSchemeByName(CURRENT_SCHEME_NAME);
|
||||
setCurrentScheme(current == null ? getDefaultScheme() : current);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -51,7 +51,7 @@ public abstract class AbstractToolBeforeRunTask<ToolBeforeRunTask extends Abstra
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) {
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
super.writeExternal(element);
|
||||
if (myToolActionId != null) {
|
||||
element.setAttribute(ACTION_ID_ATTRIBUTE, myToolActionId);
|
||||
@@ -59,7 +59,7 @@ public abstract class AbstractToolBeforeRunTask<ToolBeforeRunTask extends Abstra
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) {
|
||||
public void readExternal(@NotNull Element element) {
|
||||
super.readExternal(element);
|
||||
myToolActionId = element.getAttributeValue(ACTION_ID_ATTRIBUTE);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -22,6 +22,7 @@ import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -37,7 +38,7 @@ public abstract class AbstractToolBeforeRunTaskProvider<T extends AbstractToolBe
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configureTask(RunConfiguration runConfiguration, T task) {
|
||||
public boolean configureTask(@NotNull RunConfiguration runConfiguration, @NotNull T task) {
|
||||
final ToolSelectDialog dialog = new ToolSelectDialog(runConfiguration.getProject(), task.getToolActionId(), createToolsPanel());
|
||||
if (!dialog.showAndGet()) {
|
||||
return false;
|
||||
@@ -59,7 +60,7 @@ public abstract class AbstractToolBeforeRunTaskProvider<T extends AbstractToolBe
|
||||
protected abstract BaseToolsPanel createToolsPanel();
|
||||
|
||||
@Override
|
||||
public boolean canExecuteTask(RunConfiguration configuration, T task) {
|
||||
public boolean canExecuteTask(@NotNull RunConfiguration configuration, @NotNull T task) {
|
||||
return task.isExecutable();
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ public abstract class AbstractToolBeforeRunTaskProvider<T extends AbstractToolBe
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, T task) {
|
||||
public boolean executeTask(DataContext context, @NotNull RunConfiguration configuration, @NotNull ExecutionEnvironment env, @NotNull T task) {
|
||||
if (!task.isExecutable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -191,6 +191,11 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected State getStateInner() {
|
||||
return myState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(final State state) {
|
||||
state.makePathsSystemIndependent();
|
||||
|
||||
@@ -68,7 +68,7 @@ public class Utils{
|
||||
private static void handleUpdateException(AnAction action, Presentation presentation, Throwable exc) {
|
||||
String id = ActionManager.getInstance().getId(action);
|
||||
if (id != null) {
|
||||
LOG.error("update failed for AnAction with ID=" + id, exc);
|
||||
LOG.error("update failed for AnAction(" + action.getClass().getName() + ") with ID=" + id, exc);
|
||||
}
|
||||
else {
|
||||
LOG.error("update failed for ActionGroup: " + action + "[" + presentation.getText() + "]", exc);
|
||||
|
||||
@@ -317,9 +317,12 @@ private fun createComponentConstraints(constraints: Array<out CCFlags>? = null,
|
||||
}
|
||||
|
||||
if (growPolicy == GrowPolicy.SHORT_TEXT) {
|
||||
// cc().minWidth("210")
|
||||
cc().maxWidth("210")
|
||||
}
|
||||
else if (growPolicy == GrowPolicy.MEDIUM_TEXT) {
|
||||
cc().minWidth("210")
|
||||
cc().maxWidth("350")
|
||||
}
|
||||
|
||||
return _cc
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -148,5 +148,5 @@ abstract class Row() {
|
||||
}
|
||||
|
||||
enum class GrowPolicy {
|
||||
SHORT_TEXT
|
||||
SHORT_TEXT, MEDIUM_TEXT
|
||||
}
|
||||
@@ -585,6 +585,8 @@
|
||||
key="browsers.settings" bundle="messages.IdeBundle"/>
|
||||
<lang.inspectionSuppressor language="XML" implementationClass="com.intellij.codeInspection.XmlInspectionSuppressor"/>
|
||||
<smartPointer.anchorProvider implementation="com.intellij.psi.impl.smartPointers.XmlAnchorProvider"/>
|
||||
|
||||
<stepsBeforeRunProvider implementation="com.intellij.ide.browsers.LaunchBrowserBeforeRunTaskProvider"/>
|
||||
</extensions>
|
||||
<extensions defaultExtensionNs="org.jetbrains">
|
||||
<urlOpener implementation="com.intellij.ide.browsers.impl.DefaultUrlOpener" order="last"/>
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ fun <T> deserializeState(stateElement: Element?, stateClass: Class<T>, mergeInto
|
||||
stateClass == Element::class.java -> stateElement as T?
|
||||
JDOMExternalizable::class.java.isAssignableFrom(stateClass) -> {
|
||||
if (mergeInto != null) {
|
||||
LOG.error("State is ${stateClass.name}, merge into is ${mergeInto.toString()}, state element text is ${JDOMUtil.writeElement(stateElement)}")
|
||||
LOG.error("State is ${stateClass.name}, merge into is $mergeInto, state element text is ${JDOMUtil.writeElement(stateElement)}")
|
||||
}
|
||||
|
||||
val t = ReflectionUtil.newInstance(stateClass)
|
||||
|
||||
@@ -119,15 +119,24 @@ fun PersistentStateComponent<*>.deserializeAndLoadState(element: Element) {
|
||||
(this as PersistentStateComponent<Any>).loadState(state)
|
||||
}
|
||||
|
||||
fun PersistentStateComponent<*>.serializeStateInto(element: Element) {
|
||||
state?.let { serializeObjectInto(it, element) }
|
||||
}
|
||||
|
||||
@Deprecated("")
|
||||
fun <T : Any> T.serializeInto(target: Element) {
|
||||
if (this is Element) {
|
||||
val iterator = children.iterator()
|
||||
serializeObjectInto(this, target)
|
||||
}
|
||||
|
||||
fun serializeObjectInto(o: Any, target: Element) {
|
||||
if (o is Element) {
|
||||
val iterator = o.children.iterator()
|
||||
for (child in iterator) {
|
||||
iterator.remove()
|
||||
target.addContent(child)
|
||||
}
|
||||
|
||||
val attributeIterator = attributes.iterator()
|
||||
val attributeIterator = o.attributes.iterator()
|
||||
for (attribute in attributeIterator) {
|
||||
attributeIterator.remove()
|
||||
target.setAttribute(attribute)
|
||||
@@ -135,8 +144,8 @@ fun <T : Any> T.serializeInto(target: Element) {
|
||||
return
|
||||
}
|
||||
|
||||
val binding = serializer.getClassBinding(javaClass)
|
||||
(binding as BeanBinding).serializeInto(this, target, null)
|
||||
val binding = serializer.getClassBinding(o.javaClass)
|
||||
(binding as BeanBinding).serializeInto(o, target, getDefaultSerializationFilter())
|
||||
}
|
||||
|
||||
private val serializer = object : XmlSerializerImpl.XmlSerializerBase() {
|
||||
|
||||
@@ -455,7 +455,7 @@ public class RootModelImpl extends RootModelBase implements ModifiableRootModel
|
||||
for (ModuleExtension extension : myExtensions) {
|
||||
if (extension instanceof PersistentStateComponent) {
|
||||
//noinspection ConstantConditions
|
||||
XmlSerializer.serializeInto(((PersistentStateComponent)extension).getState(), element);
|
||||
XmlSerializer.serializeStateInto(((PersistentStateComponent)extension), element);
|
||||
}
|
||||
else {
|
||||
//noinspection deprecation
|
||||
|
||||
+2
-1
@@ -53,7 +53,8 @@ public class ServerTaskExecutorImpl implements ServerTaskExecutor {
|
||||
}
|
||||
catch (Throwable e) {
|
||||
LOG.info(e);
|
||||
callback.errorOccurred(e.getMessage());
|
||||
String message = e.getMessage();
|
||||
callback.errorOccurred(message != null ? message : e.getClass().getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.Set;
|
||||
* @author peter
|
||||
*/
|
||||
public class MockInspectionProfile extends InspectionProfileImpl {
|
||||
private InspectionToolWrapper[] myInspectionTools = new InspectionToolWrapper[0];
|
||||
private InspectionToolWrapper[] myInspectionTools = InspectionToolWrapper.EMPTY_ARRAY;
|
||||
private final Set<InspectionToolWrapper> myDisabledTools = new THashSet<>();
|
||||
|
||||
public MockInspectionProfile() {
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.project.ex.ProjectEx
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx
|
||||
import com.intellij.openapi.project.impl.ProjectManagerImpl
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl
|
||||
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS
|
||||
@@ -101,6 +100,7 @@ class ProjectRule(val projectDescriptor: LightProjectDescriptor = LightProjectDe
|
||||
sharedProject = null
|
||||
sharedModule = null
|
||||
(ProjectManager.getInstance() as ProjectManagerImpl).forceCloseProject(project, true)
|
||||
(VirtualFilePointerManager.getInstance() as VirtualFilePointerManagerImpl).assertPointersAreDisposed()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(GuiTestLocalRunner.class)
|
||||
public abstract class GuiTestBase {
|
||||
protected Robot myRobot;
|
||||
public Robot myRobot;
|
||||
|
||||
private final Logger LOG = Logger.getInstance(GuiTestBase.class);
|
||||
|
||||
|
||||
+7
-5
@@ -38,7 +38,9 @@ import kotlin.reflect.KClass
|
||||
|
||||
|
||||
class GuiTestLocalRunner @Throws(InitializationError::class)
|
||||
constructor(testClass: Class<*>) : BlockJUnit4ClassRunner(testClass) {
|
||||
constructor(testClass: Class<*>, val ide: Ide?) : BlockJUnit4ClassRunner(testClass) {
|
||||
|
||||
constructor(testClass: Class<*>): this(testClass, null)
|
||||
|
||||
val SERVER_LOG = org.apache.log4j.Logger.getLogger("#com.intellij.testGuiFramework.framework.GuiTestLocalRunner")!!
|
||||
val criticalError = Ref<Boolean>(false)
|
||||
@@ -67,8 +69,10 @@ constructor(testClass: Class<*>) : BlockJUnit4ClassRunner(testClass) {
|
||||
val server = JUnitServerHolder.getServer()
|
||||
|
||||
try {
|
||||
if (!server.isConnected())
|
||||
runIdeLocally(port = server.getPort(), ide = getIdeFromAnnotation(this@GuiTestLocalRunner.testClass.javaClass))
|
||||
if (!server.isConnected()) {
|
||||
val localIde = ide ?: getIdeFromAnnotation(this@GuiTestLocalRunner.testClass.javaClass)
|
||||
runIdeLocally(port = server.getPort(), ide = localIde)
|
||||
}
|
||||
val jUnitTestContainer = JUnitTestContainer(method.declaringClass, method.name)
|
||||
server.send(TransportMessage(MessageType.RUN_TEST, jUnitTestContainer))
|
||||
}
|
||||
@@ -147,7 +151,5 @@ constructor(testClass: Class<*>) : BlockJUnit4ClassRunner(testClass) {
|
||||
return Ide(ideType, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -40,9 +40,7 @@ class GuiTestSuite(suiteClass: Class<*>, val builder: RunnerBuilder) : Suite(sui
|
||||
//let's start IDE to complete installation, import configs and etc before running tests
|
||||
if (myFirstStart) firstStart()
|
||||
val testClass = runner.description.testClass
|
||||
//check that ide types are equal
|
||||
check(GuiTestLocalRunner.getIdeFromAnnotation(testClass).ideType.javaClass == myIde.ideType.javaClass)
|
||||
val guiTestLocalRunner = GuiTestLocalRunner(testClass)
|
||||
val guiTestLocalRunner = GuiTestLocalRunner(testClass, myIde)
|
||||
super.runChild(guiTestLocalRunner, notifier)
|
||||
}
|
||||
catch (e: Exception) {
|
||||
@@ -59,5 +57,4 @@ class GuiTestSuite(suiteClass: Class<*>, val builder: RunnerBuilder) : Suite(sui
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -122,7 +122,6 @@ open class GuiTestCase : GuiTestBase() {
|
||||
val screenshotTaker = ScreenshotTaker()
|
||||
var pathToSaveScreenshots = getTestScreenshotDirPath()
|
||||
|
||||
|
||||
val settingsTitle: String = if (isMac()) "Preferences" else "Settings"
|
||||
val defaultSettingsTitle: String = if (isMac()) "Default Preferences" else "Default Settings"
|
||||
val slash: String = File.separator
|
||||
@@ -137,6 +136,7 @@ open class GuiTestCase : GuiTestBase() {
|
||||
|
||||
@Throws(InvocationTargetException::class, InterruptedException::class)
|
||||
override fun tearDown() {
|
||||
closeAllProjects()
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
@@ -713,10 +713,10 @@ open class GuiTestCase : GuiTestBase() {
|
||||
return "@${uiScaleVal}x"
|
||||
}
|
||||
|
||||
protected fun <ComponentType : Component> waitUntilFound(container: Container?,
|
||||
componentClass: Class<ComponentType>,
|
||||
timeout: Long,
|
||||
matcher: (ComponentType) -> Boolean): ComponentType {
|
||||
fun <ComponentType : Component> waitUntilFound(container: Container?,
|
||||
componentClass: Class<ComponentType>,
|
||||
timeout: Long,
|
||||
matcher: (ComponentType) -> Boolean): ComponentType {
|
||||
return GuiTestUtil.waitUntilFound(myRobot, container, typeMatcher(componentClass) { matcher(it) }, timeout.toFestTimeout())
|
||||
}
|
||||
|
||||
@@ -745,5 +745,4 @@ open class GuiTestCase : GuiTestBase() {
|
||||
return flagCheckFunction()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -266,6 +266,19 @@ object GuiTestUtilKt {
|
||||
return result?.first
|
||||
}
|
||||
|
||||
fun ensureCreateHasDone(guiTestCase: GuiTestCase) {
|
||||
try {
|
||||
com.intellij.testGuiFramework.impl.GuiTestUtilKt.waitUntilGone(robot = guiTestCase.myRobot,
|
||||
matcher = com.intellij.testGuiFramework.impl.GuiTestUtilKt.typeMatcher(
|
||||
com.intellij.openapi.wm.impl.welcomeScreen.FlatWelcomeFrame::class.java) { it.isShowing })
|
||||
}
|
||||
catch (timeoutError: WaitTimedOutError) {
|
||||
with(guiTestCase) {
|
||||
welcomeFrame { button("Create").clickWhenEnabled() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
@@ -231,6 +231,7 @@ public class UsageViewImpl implements UsageView {
|
||||
return expandingAll ? EmptyEnumeration.getInstance() : super.getExpandedDescendants(parent);
|
||||
}
|
||||
};
|
||||
myTree.setName("UsageViewTree");
|
||||
|
||||
myRootPanel = new MyPanel(myTree);
|
||||
Disposer.register(this, myRootPanel);
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
@@ -370,9 +371,14 @@ public class JBZipEntry implements Cloneable {
|
||||
}
|
||||
|
||||
private InputStream getInputStream() throws IOException {
|
||||
myFile.ensureFlushed(getHeaderOffset() + JBZipFile.LFH_OFFSET_FOR_FILENAME_LENGTH + JBZipFile.WORD);
|
||||
long start = calcDataOffset();
|
||||
|
||||
BoundedInputStream bis = new BoundedInputStream(start, getCompressedSize());
|
||||
long size = getCompressedSize();
|
||||
myFile.ensureFlushed(start + size);
|
||||
if (myFile.archive.length() < start + size) {
|
||||
throw new EOFException();
|
||||
}
|
||||
BoundedInputStream bis = new BoundedInputStream(start, size);
|
||||
switch (getMethod()) {
|
||||
case ZipEntry.STORED:
|
||||
return bis;
|
||||
|
||||
@@ -187,7 +187,7 @@ public class JBZipFile {
|
||||
}
|
||||
|
||||
myOutputStream.finish();
|
||||
archive.setLength(myOutputStream.written);
|
||||
archive.setLength(myOutputStream.getWritten());
|
||||
}
|
||||
archive.close();
|
||||
}
|
||||
@@ -454,4 +454,8 @@ public class JBZipFile {
|
||||
}
|
||||
return myOutputStream;
|
||||
}
|
||||
|
||||
void ensureFlushed(long end) throws IOException {
|
||||
if (myOutputStream != null) myOutputStream.ensureFlushed(end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class JBZipOutputStream {
|
||||
|
||||
private final CRC32 crc = new CRC32();
|
||||
|
||||
long written = 0;
|
||||
private long writtenOnDisk = 0;
|
||||
|
||||
/**
|
||||
* The encoding to use for filenames and the file comment.
|
||||
@@ -93,8 +93,7 @@ class JBZipOutputStream {
|
||||
public JBZipOutputStream(JBZipFile file, long currentCDOffset) throws IOException {
|
||||
myFile = file;
|
||||
raf = myFile.archive;
|
||||
written = currentCDOffset;
|
||||
raf.seek(currentCDOffset);
|
||||
writtenOnDisk = currentCDOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,12 +128,12 @@ class JBZipOutputStream {
|
||||
* @since 1.1
|
||||
*/
|
||||
public void finish() throws IOException {
|
||||
long cdOffset = written;
|
||||
long cdOffset = getWritten();
|
||||
final List<JBZipEntry> entries = myFile.getEntries();
|
||||
for (int i = 0, entriesSize = entries.size(); i < entriesSize; i++) {
|
||||
writeCentralFileHeader(entries.get(i));
|
||||
}
|
||||
long cdLength = written - cdOffset;
|
||||
long cdLength = getWritten() - cdOffset;
|
||||
writeCentralDirectoryEnd(cdLength, cdOffset);
|
||||
flushBuffer();
|
||||
def.end();
|
||||
@@ -209,7 +208,7 @@ class JBZipOutputStream {
|
||||
* @since 1.1
|
||||
*/
|
||||
protected void writeLocalFileHeader(JBZipEntry ze) throws IOException {
|
||||
ze.setHeaderOffset(written);
|
||||
ze.setHeaderOffset(getWritten());
|
||||
|
||||
writeOut(LFH_SIG);
|
||||
|
||||
@@ -376,11 +375,16 @@ class JBZipOutputStream {
|
||||
if (myBuffer.size() > 8192) {
|
||||
flushBuffer();
|
||||
}
|
||||
written += length;
|
||||
}
|
||||
|
||||
void ensureFlushed(long end) throws IOException {
|
||||
if (end > writtenOnDisk) flushBuffer();
|
||||
}
|
||||
|
||||
private void flushBuffer() throws IOException {
|
||||
raf.seek(writtenOnDisk);
|
||||
raf.write(myBuffer.getInternalBuffer(), 0, myBuffer.size());
|
||||
writtenOnDisk += myBuffer.size();
|
||||
myBuffer.reset();
|
||||
}
|
||||
|
||||
@@ -423,4 +427,8 @@ class JBZipOutputStream {
|
||||
writeLocalFileHeader(entry);
|
||||
writeOut(outputBytes, 0, outputBytesLength);
|
||||
}
|
||||
|
||||
long getWritten() {
|
||||
return writtenOnDisk + myBuffer.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.intellij.util.io.zip;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.*;
|
||||
@@ -108,6 +109,64 @@ public class UpdateableZipTest extends TestCase {
|
||||
utilZip.close();
|
||||
}
|
||||
|
||||
public void testReadWrite1() throws Exception {
|
||||
JBZipFile jbZip = new JBZipFile(zipFile);
|
||||
try {
|
||||
assertEntryWithContentExists(jbZip, "/first", "first");
|
||||
assertEntryWithContentExists(jbZip, "/second", "second");
|
||||
|
||||
createOrReplaceEntryData(jbZip, "/third", "third");
|
||||
|
||||
assertEntryWithContentExists(jbZip, "/third", "third");
|
||||
}
|
||||
finally {
|
||||
jbZip.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testReadWrite2() throws Exception {
|
||||
JBZipFile jbZip = new JBZipFile(zipFile);
|
||||
try {
|
||||
assertEntryWithContentExists(jbZip, "/first", "first");
|
||||
assertEntryWithContentExists(jbZip, "/second", "second");
|
||||
|
||||
createOrReplaceEntryData(jbZip, "/first", "first_new");
|
||||
|
||||
assertEntryWithContentExists(jbZip, "/first", "first_new");
|
||||
}
|
||||
finally {
|
||||
jbZip.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testMissingSeeks() throws Exception {
|
||||
JBZipFile jbZip = new JBZipFile(zipFile);
|
||||
try {
|
||||
assertEntryWithContentExists(jbZip, "/first", "first");
|
||||
assertEntryWithContentExists(jbZip, "/second", "second");
|
||||
|
||||
//seek end
|
||||
createOrReplaceEntryData(jbZip, "/third", "third");
|
||||
//seek somewhere
|
||||
assertEntryWithContentExists(jbZip, "/first", "first");
|
||||
//write somewhere :)
|
||||
createOrReplaceEntryData(jbZip, "/forth", "forth");
|
||||
|
||||
assertEntryWithContentExists(jbZip, "/first", "first");
|
||||
assertEntryWithContentExists(jbZip, "/second", "second");
|
||||
assertEntryWithContentExists(jbZip, "/third", "third");
|
||||
assertEntryWithContentExists(jbZip, "/forth", "forth");
|
||||
}
|
||||
finally {
|
||||
jbZip.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void createOrReplaceEntryData(JBZipFile jbZip, String name, String data) throws IOException {
|
||||
JBZipEntry newEntry = jbZip.getOrCreateEntry(name);
|
||||
newEntry.setData(data.getBytes(CharsetToolkit.UTF8_CHARSET));
|
||||
}
|
||||
|
||||
/*
|
||||
public void testAppendToIdeaJar() throws Exception {
|
||||
//ProfilingUtil.startCPUProfiling();
|
||||
|
||||
@@ -335,9 +335,11 @@ public class XDebuggerManagerImpl extends XDebuggerManager
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(final XDebuggerState state) {
|
||||
myBreakpointManager.loadState(state.myBreakpointManagerState);
|
||||
myWatchesManager.loadState(state.myWatchesManagerState);
|
||||
public void loadState(@NotNull XDebuggerState state) {
|
||||
XBreakpointManagerImpl.BreakpointManagerState breakpointManagerState = state.myBreakpointManagerState;
|
||||
myBreakpointManager.loadState(breakpointManagerState == null ? new XBreakpointManagerImpl.BreakpointManagerState() : breakpointManagerState);
|
||||
XDebuggerWatchesManager.WatchesManagerState managerState = state.myWatchesManagerState;
|
||||
myWatchesManager.loadState(managerState == null ? new XDebuggerWatchesManager.WatchesManagerState() : managerState);
|
||||
}
|
||||
|
||||
public void showExecutionPosition() {
|
||||
@@ -346,32 +348,36 @@ public class XDebuggerManagerImpl extends XDebuggerManager
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static class XDebuggerState {
|
||||
@Nullable
|
||||
private XBreakpointManagerImpl.BreakpointManagerState myBreakpointManagerState;
|
||||
@Nullable
|
||||
private XDebuggerWatchesManager.WatchesManagerState myWatchesManagerState;
|
||||
|
||||
public XDebuggerState() {
|
||||
}
|
||||
|
||||
public XDebuggerState(final XBreakpointManagerImpl.BreakpointManagerState breakpointManagerState, XDebuggerWatchesManager.WatchesManagerState watchesManagerState) {
|
||||
public XDebuggerState(@Nullable XBreakpointManagerImpl.BreakpointManagerState breakpointManagerState, @Nullable XDebuggerWatchesManager.WatchesManagerState watchesManagerState) {
|
||||
myBreakpointManagerState = breakpointManagerState;
|
||||
myWatchesManagerState = watchesManagerState;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Property(surroundWithTag = false)
|
||||
public XBreakpointManagerImpl.BreakpointManagerState getBreakpointManagerState() {
|
||||
return myBreakpointManagerState;
|
||||
}
|
||||
|
||||
public void setBreakpointManagerState(final XBreakpointManagerImpl.BreakpointManagerState breakpointManagerState) {
|
||||
public void setBreakpointManagerState(@Nullable final XBreakpointManagerImpl.BreakpointManagerState breakpointManagerState) {
|
||||
myBreakpointManagerState = breakpointManagerState;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Property(surroundWithTag = false)
|
||||
public XDebuggerWatchesManager.WatchesManagerState getWatchesManagerState() {
|
||||
return myWatchesManagerState;
|
||||
}
|
||||
|
||||
public void setWatchesManagerState(XDebuggerWatchesManager.WatchesManagerState watchesManagerState) {
|
||||
public void setWatchesManagerState(@Nullable XDebuggerWatchesManager.WatchesManagerState watchesManagerState) {
|
||||
myWatchesManagerState = watchesManagerState;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -387,7 +387,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(final BreakpointManagerState state) {
|
||||
public void loadState(@NotNull BreakpointManagerState state) {
|
||||
myBreakpointsDialogSettings = state.getBreakpointsDialogProperties();
|
||||
|
||||
myAllBreakpoints.clear();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
@@ -50,7 +51,7 @@ public class AntBeforeRunTask extends BeforeRunTask<AntBeforeRunTask>{
|
||||
myTargetName = targetName;
|
||||
}
|
||||
|
||||
public void writeExternal(Element element) {
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
super.writeExternal(element);
|
||||
if (myAntFileUrl != null && myTargetName != null) {
|
||||
element.setAttribute("antfile", myAntFileUrl);
|
||||
@@ -58,7 +59,7 @@ public class AntBeforeRunTask extends BeforeRunTask<AntBeforeRunTask>{
|
||||
}
|
||||
}
|
||||
|
||||
public void readExternal(Element element) {
|
||||
public void readExternal(@NotNull Element element) {
|
||||
super.readExternal(element);
|
||||
final String url = element.getAttributeValue("antfile");
|
||||
final String targetName = element.getAttributeValue("target");
|
||||
|
||||
@@ -74,7 +74,7 @@ public class AntBeforeRunTaskProvider extends BeforeRunTaskProvider<AntBeforeRun
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean configureTask(RunConfiguration runConfiguration, AntBeforeRunTask task) {
|
||||
public boolean configureTask(@NotNull RunConfiguration runConfiguration, @NotNull AntBeforeRunTask task) {
|
||||
AntBuildTarget buildTarget = findTargetToExecute(task);
|
||||
final TargetChooserDialog dlg = new TargetChooserDialog(myProject, buildTarget);
|
||||
if (dlg.showAndGet()) {
|
||||
@@ -98,11 +98,11 @@ public class AntBeforeRunTaskProvider extends BeforeRunTaskProvider<AntBeforeRun
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteTask(RunConfiguration configuration, AntBeforeRunTask task) {
|
||||
public boolean canExecuteTask(@NotNull RunConfiguration configuration, @NotNull AntBeforeRunTask task) {
|
||||
return findTargetToExecute(task) != null;
|
||||
}
|
||||
|
||||
public boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, AntBeforeRunTask task) {
|
||||
public boolean executeTask(DataContext context, @NotNull RunConfiguration configuration, @NotNull ExecutionEnvironment env, @NotNull AntBeforeRunTask task) {
|
||||
final AntBuildTarget target = findTargetToExecute(task);
|
||||
if (target != null) {
|
||||
return AntConfigurationImpl.executeTargetSynchronously(context, target);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package com.maddyhome.idea.copyright
|
||||
|
||||
import com.intellij.configurationStore.SerializableScheme
|
||||
import com.intellij.configurationStore.serializeInto
|
||||
import com.intellij.configurationStore.serializeObjectInto
|
||||
import com.intellij.openapi.components.BaseState
|
||||
import com.intellij.openapi.options.ExternalizableScheme
|
||||
import com.intellij.util.xmlb.annotations.OptionTag
|
||||
@@ -36,7 +36,7 @@ class CopyrightProfile @JvmOverloads constructor(profileName: String? = null) :
|
||||
// ugly name to preserve compatibility
|
||||
// must be not private because otherwise binding is not created for private accessor
|
||||
@get:OptionTag("myName")
|
||||
internal var profileName by string()
|
||||
private var profileName by string()
|
||||
|
||||
var notice by string(DEFAULT_COPYRIGHT_NOTICE)
|
||||
var keyword by string(EntityUtil.encode("Copyright"))
|
||||
@@ -61,7 +61,7 @@ class CopyrightProfile @JvmOverloads constructor(profileName: String? = null) :
|
||||
|
||||
override fun writeScheme(): Element {
|
||||
val element = Element("copyright")
|
||||
serializeInto(element)
|
||||
serializeObjectInto(this, element)
|
||||
return element
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ public class IdeaSpecificSettings extends AbstractIdeaSpecificSettings<Modifiabl
|
||||
LanguageLevelModuleExtensionImpl languageLevelModuleExtension = model.getModuleExtension(LanguageLevelModuleExtensionImpl.class);
|
||||
if (languageLevelModuleExtension.getLanguageLevel() != null) {
|
||||
//noinspection ConstantConditions
|
||||
XmlSerializer.serializeInto(languageLevelModuleExtension.getState(), root);
|
||||
XmlSerializer.serializeStateInto(languageLevelModuleExtension, root);
|
||||
isModified = true;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -18,6 +18,7 @@ package com.intellij.codeInspection.i18n;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.SuppressIntentionAction;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -76,8 +77,9 @@ class SuppressByCommentOutAction extends SuppressIntentionAction {
|
||||
}
|
||||
|
||||
private static PsiElement findJavaCodeUpThere(PsiElement element) {
|
||||
InjectedLanguageManager injectedManager = InjectedLanguageManager.getInstance(element.getProject());
|
||||
while (element != null) {
|
||||
if (element.getLanguage() == JavaLanguage.INSTANCE) return element;
|
||||
if (element.getLanguage() == JavaLanguage.INSTANCE && !injectedManager.isInjectedFragment(element.getContainingFile())) return element;
|
||||
element = element.getContext();
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.idea.maven.tasks;
|
||||
import com.intellij.execution.BeforeRunTask;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
|
||||
public class MavenBeforeRunTask extends BeforeRunTask<MavenBeforeRunTask> {
|
||||
@@ -50,14 +51,14 @@ public class MavenBeforeRunTask extends BeforeRunTask<MavenBeforeRunTask> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) {
|
||||
public void writeExternal(@NotNull Element element) {
|
||||
super.writeExternal(element);
|
||||
if (myProjectPath != null) element.setAttribute("file", myProjectPath);
|
||||
if (myGoal != null) element.setAttribute("goal", myGoal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) {
|
||||
public void readExternal(@NotNull Element element) {
|
||||
super.readExternal(element);
|
||||
myProjectPath = element.getAttributeValue("file");
|
||||
myGoal = element.getAttributeValue("goal");
|
||||
|
||||
+5
-5
@@ -105,7 +105,7 @@ public class MavenBeforeRunTasksProvider extends BeforeRunTaskProvider<MavenBefo
|
||||
return new MavenBeforeRunTask();
|
||||
}
|
||||
|
||||
public boolean configureTask(RunConfiguration runConfiguration, MavenBeforeRunTask task) {
|
||||
public boolean configureTask(@NotNull RunConfiguration runConfiguration, @NotNull MavenBeforeRunTask task) {
|
||||
MavenEditGoalDialog dialog = new MavenEditGoalDialog(myProject);
|
||||
|
||||
dialog.setTitle(TasksBundle.message("maven.tasks.select.goal.title"));
|
||||
@@ -142,14 +142,14 @@ public class MavenBeforeRunTasksProvider extends BeforeRunTaskProvider<MavenBefo
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteTask(RunConfiguration configuration, MavenBeforeRunTask task) {
|
||||
public boolean canExecuteTask(@NotNull RunConfiguration configuration, @NotNull MavenBeforeRunTask task) {
|
||||
return task.getGoal() != null && task.getProjectPath() != null;
|
||||
}
|
||||
|
||||
public boolean executeTask(final DataContext context,
|
||||
RunConfiguration configuration,
|
||||
ExecutionEnvironment env,
|
||||
final MavenBeforeRunTask task) {
|
||||
@NotNull RunConfiguration configuration,
|
||||
@NotNull ExecutionEnvironment env,
|
||||
@NotNull final MavenBeforeRunTask task) {
|
||||
final Semaphore targetDone = new Semaphore();
|
||||
final boolean[] result = new boolean[]{true};
|
||||
try {
|
||||
|
||||
+35
-22
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -23,6 +23,9 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.reference.SoftLazyValue;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.SmartList;
|
||||
@@ -98,32 +101,42 @@ public class PropertiesUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static String getDefaultBaseName(@NotNull final VirtualFile file) {
|
||||
final String name = file.getName();
|
||||
static String getDefaultBaseName(@NotNull final PsiFile file) {
|
||||
return CachedValuesManager.getCachedValue(file, new CachedValueProvider<String>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Result<String> compute() {
|
||||
return Result.create(computeBaseName(), file);
|
||||
}
|
||||
|
||||
if (!StringUtil.containsChar(name, '_')) {
|
||||
return FileUtil.getNameWithoutExtension(name);
|
||||
}
|
||||
private String computeBaseName() {
|
||||
final String name = file.getName();
|
||||
|
||||
final Matcher matcher = LOCALE_PATTERN.matcher(name);
|
||||
final String baseNameWithExtension;
|
||||
|
||||
int matchIndex = 0;
|
||||
while (matcher.find(matchIndex)) {
|
||||
final MatchResult matchResult = matcher.toMatchResult();
|
||||
final String[] splitted = matchResult.group(1).split("_");
|
||||
if (splitted.length > 1) {
|
||||
final String langCode = splitted[1];
|
||||
if (!LOCALES_LANGUAGE_CODES.getValue().contains(langCode)) {
|
||||
matchIndex = matchResult.start(1) + 1;
|
||||
continue;
|
||||
if (!StringUtil.containsChar(name, '_')) {
|
||||
return FileUtil.getNameWithoutExtension(name);
|
||||
}
|
||||
baseNameWithExtension = name.substring(0, matchResult.start(1)) + name.substring(matchResult.end(1));
|
||||
|
||||
final Matcher matcher = LOCALE_PATTERN.matcher(name);
|
||||
final String baseNameWithExtension;
|
||||
|
||||
int matchIndex = 0;
|
||||
while (matcher.find(matchIndex)) {
|
||||
final MatchResult matchResult = matcher.toMatchResult();
|
||||
final String[] splitted = matchResult.group(1).split("_");
|
||||
if (splitted.length > 1) {
|
||||
final String langCode = splitted[1];
|
||||
if (!LOCALES_LANGUAGE_CODES.getValue().contains(langCode)) {
|
||||
matchIndex = matchResult.start(1) + 1;
|
||||
continue;
|
||||
}
|
||||
baseNameWithExtension = name.substring(0, matchResult.start(1)) + name.substring(matchResult.end(1));
|
||||
return FileUtil.getNameWithoutExtension(baseNameWithExtension);
|
||||
}
|
||||
}
|
||||
baseNameWithExtension = name;
|
||||
return FileUtil.getNameWithoutExtension(baseNameWithExtension);
|
||||
}
|
||||
}
|
||||
baseNameWithExtension = name;
|
||||
return FileUtil.getNameWithoutExtension(baseNameWithExtension);
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+5
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -197,17 +197,13 @@ public class ResourceBundleManager implements PersistentStateComponent<ResourceB
|
||||
|
||||
@NotNull
|
||||
public String getBaseName(@NotNull final PsiFile file) {
|
||||
return getBaseName(file.getVirtualFile());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getBaseName(@NotNull final VirtualFile file) {
|
||||
final CustomResourceBundleState customResourceBundle = getCustomResourceBundleState(file);
|
||||
final VirtualFile vFile = file.getVirtualFile();
|
||||
final CustomResourceBundleState customResourceBundle = getCustomResourceBundleState(vFile);
|
||||
if (customResourceBundle != null) {
|
||||
return customResourceBundle.getBaseName();
|
||||
}
|
||||
if (isDefaultDissociated(file)) {
|
||||
return file.getNameWithoutExtension();
|
||||
if (isDefaultDissociated(vFile)) {
|
||||
return vFile.getNameWithoutExtension();
|
||||
}
|
||||
return PropertiesUtil.getDefaultBaseName(file);
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ public class GenerationNode extends UserDataHolderBase {
|
||||
String attributeName = defaultAttribute.getName();
|
||||
if (attributeName.length() > 1) {
|
||||
if (isImpliedAttribute(attributeName)) {
|
||||
defaultAttribute.setName(attributeName.substring(1));
|
||||
defaultAttribute = (XmlAttribute)defaultAttribute.setName(attributeName.substring(1));
|
||||
}
|
||||
final String oldValue = defaultAttribute.getValue();
|
||||
if (oldValue != null && StringUtil.containsChar(oldValue, '|')) {
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.ide.browsers;
|
||||
|
||||
import com.google.common.net.HostAndPort;
|
||||
@@ -50,7 +65,7 @@ public class BrowserStarter {
|
||||
}
|
||||
else {
|
||||
// we can't check page availability gracefully, so we just open it after some delay
|
||||
openPageLater(1000);
|
||||
openPageLater();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,8 +110,8 @@ public class BrowserStarter {
|
||||
return 2000;
|
||||
}
|
||||
|
||||
private void openPageLater(int millis) {
|
||||
JobScheduler.getScheduler().schedule(() -> openPageNow(), millis, TimeUnit.MILLISECONDS);
|
||||
private void openPageLater() {
|
||||
JobScheduler.getScheduler().schedule(() -> openPageNow(), 1000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private void openPageNow() {
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.ide.browsers
|
||||
|
||||
import com.intellij.execution.BeforeRunTask
|
||||
import com.intellij.execution.BeforeRunTaskProvider
|
||||
import com.intellij.execution.ExecutionListener
|
||||
import com.intellij.execution.ExecutionManager
|
||||
import com.intellij.execution.configurations.RunConfiguration
|
||||
import com.intellij.execution.process.ProcessHandler
|
||||
import com.intellij.execution.runners.ExecutionEnvironment
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.components.BaseState
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.ui.components.CheckBox
|
||||
import com.intellij.ui.components.dialog
|
||||
import com.intellij.ui.layout.*
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import com.intellij.util.xmlb.annotations.Attribute
|
||||
import com.intellij.xml.XmlBundle
|
||||
import javax.swing.Icon
|
||||
import javax.swing.border.EmptyBorder
|
||||
|
||||
internal class LaunchBrowserBeforeRunTaskProvider : BeforeRunTaskProvider<LaunchBrowserBeforeRunTask>() {
|
||||
companion object {
|
||||
val ID = Key.create<LaunchBrowserBeforeRunTask>("LaunchBrowser.Before.Run")
|
||||
}
|
||||
|
||||
override fun getName() = "Launch Web Browser"
|
||||
|
||||
override fun getId() = ID
|
||||
|
||||
override fun getIcon(): Icon = AllIcons.Nodes.PpWeb
|
||||
|
||||
override fun isConfigurable() = true
|
||||
|
||||
override fun createTask(runConfiguration: RunConfiguration) = LaunchBrowserBeforeRunTask()
|
||||
|
||||
override fun configureTask(runConfiguration: RunConfiguration, task: LaunchBrowserBeforeRunTask): Boolean {
|
||||
val state = task.state
|
||||
val modificationCount = state.modificationCount
|
||||
|
||||
val browserSelector = BrowserSelector()
|
||||
val browserComboBox = browserSelector.mainComponent
|
||||
if (UIUtil.isUnderAquaLookAndFeel()) {
|
||||
browserComboBox.border = EmptyBorder(3, 0, 0, 0)
|
||||
}
|
||||
state.browser?.let {
|
||||
browserSelector.selected = it
|
||||
}
|
||||
|
||||
val url = TextFieldWithBrowseButton()
|
||||
state.url?.let {
|
||||
url.text = it
|
||||
}
|
||||
|
||||
StartBrowserPanel.setupUrlField(url, runConfiguration.project)
|
||||
|
||||
val startJavaScriptDebuggerCheckBox = if (JavaScriptDebuggerStarter.Util.hasStarters()) CheckBox(XmlBundle.message("start.browser.with.js.debugger"), state.withDebugger) else null
|
||||
|
||||
val panel = panel {
|
||||
row("Browser:") {
|
||||
browserComboBox()
|
||||
startJavaScriptDebuggerCheckBox?.invoke()
|
||||
}
|
||||
row("Url:") {
|
||||
url(growPolicy = GrowPolicy.MEDIUM_TEXT)
|
||||
}
|
||||
}
|
||||
dialog("Launch Web Browser", panel = panel, resizable = true, focusedComponent = url)
|
||||
.show()
|
||||
|
||||
state.browser = browserSelector.selected
|
||||
state.url = url.text
|
||||
if (startJavaScriptDebuggerCheckBox != null) {
|
||||
state.withDebugger = startJavaScriptDebuggerCheckBox.isSelected
|
||||
}
|
||||
return modificationCount != state.modificationCount
|
||||
}
|
||||
|
||||
override fun executeTask(context: DataContext?, configuration: RunConfiguration, env: ExecutionEnvironment, task: LaunchBrowserBeforeRunTask): Boolean {
|
||||
val disposable = Disposer.newDisposable()
|
||||
Disposer.register(env.project, disposable)
|
||||
val executionId = env.executionId
|
||||
env.project.messageBus.connect(disposable).subscribe(ExecutionManager.EXECUTION_TOPIC, object: ExecutionListener {
|
||||
override fun processNotStarted(executorId: String, env: ExecutionEnvironment) {
|
||||
Disposer.dispose(disposable)
|
||||
}
|
||||
|
||||
override fun processStarted(executorId: String, env: ExecutionEnvironment, handler: ProcessHandler) {
|
||||
if (env.executionId != executionId) {
|
||||
return
|
||||
}
|
||||
|
||||
Disposer.dispose(disposable)
|
||||
|
||||
val settings = StartBrowserSettings()
|
||||
settings.browser = task.state.browser
|
||||
settings.isStartJavaScriptDebugger = task.state.withDebugger
|
||||
settings.url = task.state.url
|
||||
settings.isSelected = true
|
||||
BrowserStarter(configuration, settings, handler).start()
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
internal class LaunchBrowserBeforeRunTaskState : BaseState() {
|
||||
@get:Attribute(value = "browser", converter = WebBrowserReferenceConverter::class)
|
||||
var browser by storedProperty<WebBrowser>()
|
||||
@get:Attribute()
|
||||
var url by string()
|
||||
@get:Attribute()
|
||||
var withDebugger by storedProperty(false)
|
||||
}
|
||||
|
||||
internal class LaunchBrowserBeforeRunTask : BeforeRunTask<LaunchBrowserBeforeRunTask>(LaunchBrowserBeforeRunTaskProvider.ID), PersistentStateComponent<LaunchBrowserBeforeRunTaskState> {
|
||||
private var state = LaunchBrowserBeforeRunTaskState()
|
||||
|
||||
override fun loadState(state: LaunchBrowserBeforeRunTaskState) {
|
||||
state.resetModificationCount()
|
||||
this.state = state
|
||||
}
|
||||
|
||||
override fun getState() = state
|
||||
}
|
||||
@@ -16,7 +16,9 @@
|
||||
package com.intellij.psi.impl.source.xml;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.html.HTMLLanguage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.pom.PomManager;
|
||||
import com.intellij.pom.PomModel;
|
||||
@@ -34,6 +36,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.xml.*;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.xml.XmlAttributeDescriptor;
|
||||
import com.intellij.xml.XmlElementDescriptor;
|
||||
import com.intellij.xml.util.XmlUtil;
|
||||
@@ -310,11 +313,12 @@ public class XmlAttributeImpl extends XmlElementImpl implements XmlAttribute, Hi
|
||||
public PsiElement setName(@NotNull final String nameText) throws IncorrectOperationException {
|
||||
final ASTNode name = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(this);
|
||||
final String oldName = name.getText();
|
||||
final String oldValue = getValue();
|
||||
final String oldValue = ObjectUtils.notNull(getValue(), "");
|
||||
final PomModel model = PomManager.getModel(getProject());
|
||||
final XmlAttribute attribute = XmlElementFactory.getInstance(getProject()).createAttribute(nameText, oldValue, this);
|
||||
final ASTNode newName = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild((ASTNode)attribute);
|
||||
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
|
||||
final Ref<XmlAttribute> replaced = Ref.create(this);
|
||||
model.runTransaction(new PomTransactionBase(getParent(), aspect) {
|
||||
@Override
|
||||
public PomModelEvent runInner() {
|
||||
@@ -324,15 +328,17 @@ public class XmlAttributeImpl extends XmlElementImpl implements XmlAttribute, Hi
|
||||
xmlAspectChangeSet.add(new XmlAttributeSetImpl(getParent(), oldName, null));
|
||||
xmlAspectChangeSet.add(new XmlAttributeSetImpl(getParent(), nameText, oldValue));
|
||||
event.registerChangeSet(model.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
|
||||
if (oldValue.isEmpty()) {
|
||||
CodeEditUtil.replaceChild(XmlAttributeImpl.this, name, newName);
|
||||
} else {
|
||||
if (!oldValue.isEmpty() && getLanguage().isKindOf(HTMLLanguage.INSTANCE)) {
|
||||
CodeEditUtil.replaceChild(getTreeParent(), XmlAttributeImpl.this, attribute.getNode());
|
||||
replaced.set(attribute);
|
||||
}
|
||||
else {
|
||||
CodeEditUtil.replaceChild(XmlAttributeImpl.this, name, newName);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
});
|
||||
return this;
|
||||
return replaced.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user