diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt index fa74354040d..16e5f0d7779 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/attributeCallReplacements/AttributeCallReplacementIntention.kt @@ -30,10 +30,9 @@ import org.jetbrains.jet.lang.psi.ValueArgument import org.jetbrains.jet.plugin.JetBundle import org.jetbrains.jet.lang.resolve.calls.model.DefaultValueArgument import org.jetbrains.jet.lang.resolve.calls.model.VarargValueArgument - -abstract class Maybe -public class Value(public val value: V) : Maybe() -public class Error(public val error: E) : Maybe() +import org.jetbrains.jet.plugin.util.Maybe +import org.jetbrains.jet.plugin.util.MaybeError +import org.jetbrains.jet.plugin.util.MaybeValue // Internal because you shouldn't construct this manually. You can end up with an inconsistant CallDescription. public class CallDescription internal ( @@ -56,13 +55,13 @@ public class CallDescription internal ( public fun getPositionalArguments(): Maybe, String> { val resolvedValueArguments = resolved.getValueArgumentsByIndex() - ?: return Error("duplicate.or.missing.arguments") + ?: return MaybeError("duplicate.or.missing.arguments") // Check for mixed default and passed arguments and return the passed parameters (or fail) val indexOfFirstDefaultArgument = resolvedValueArguments.indexOf(DefaultValueArgument.DEFAULT) val valueArgumentGroups = if (indexOfFirstDefaultArgument >= 0) { if (resolvedValueArguments.listIterator(indexOfFirstDefaultArgument).any { it != DefaultValueArgument.DEFAULT }) { - return Error("skipped.defaults") + return MaybeError("skipped.defaults") } resolvedValueArguments.subList(0, indexOfFirstDefaultArgument) } else { @@ -73,17 +72,17 @@ public class CallDescription internal ( if (valueArgumentGroups.size > 0) { val vararg = valueArgumentGroups.find { it is VarargValueArgument } if (vararg != null && vararg != valueArgumentGroups.last) { - return Error("vararg.not.last") + return MaybeError("vararg.not.last") } } val valueArguments = valueArgumentGroups.flatMap { it.getArguments() } if (valueArguments.size < argumentCount) { // Only happens if invalid arguments were thrown away. - return Error("invalid.arguments") + return MaybeError("invalid.arguments") } - return Value(valueArguments) + return MaybeValue(valueArguments) } } @@ -129,8 +128,8 @@ public abstract class AttributeCallReplacementIntention(name: String) : JetSelfT protected fun handleErrors(editor: Editor, maybeValue: Maybe): V? { return when (maybeValue) { - is Value -> maybeValue.value - is Error -> { + is MaybeValue -> maybeValue.value + is MaybeError -> { intentionFailed(editor, maybeValue.error) null } diff --git a/idea/src/org/jetbrains/jet/plugin/util/Maybe.kt b/idea/src/org/jetbrains/jet/plugin/util/Maybe.kt new file mode 100644 index 00000000000..bca829533bb --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/util/Maybe.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2014 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 org.jetbrains.jet.plugin.util + +abstract class Maybe +public class MaybeValue(public val value: V) : Maybe() +public class MaybeError(public val error: E) : Maybe() +