From b92f53240056d8558607d4f10e68de50c8ed0375 Mon Sep 17 00:00:00 2001 From: Oleg Shpynov Date: Tue, 26 Jan 2010 20:26:41 +0300 Subject: [PATCH] First step of extract method: CodeFragment --- .../CannotCreateCodeFragmentException.java | 10 ++++++ .../codeInsight/codeFragment/CodeFragment.java | 30 +++++++++++++++++ .../codeInsight/codeFragment/CodeFragmentUtil.java | 39 ++++++++++++++++++++++ .../codeInsight/codeFragment/Position.java | 25 ++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CannotCreateCodeFragmentException.java create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CodeFragment.java create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CodeFragmentUtil.java create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/codeFragment/Position.java diff --git a/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CannotCreateCodeFragmentException.java b/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CannotCreateCodeFragmentException.java new file mode 100644 index 0000000000..706e71c3cc --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CannotCreateCodeFragmentException.java @@ -0,0 +1,10 @@ +package com.intellij.codeInsight.codeFragment; + +/** +* @author oleg +*/ +public class CannotCreateCodeFragmentException extends RuntimeException { + public CannotCreateCodeFragmentException(final String reason) { + super(reason); + } + } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CodeFragment.java b/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CodeFragment.java new file mode 100644 index 0000000000..3d394c8fed --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CodeFragment.java @@ -0,0 +1,30 @@ +package com.intellij.codeInsight.codeFragment; + +import java.util.Set; + +/** + * @author oleg + */ +public class CodeFragment { + private final Set inputVariables; + private final Set outputVariables; + private final boolean returnInstructonInside; + + public CodeFragment(final Set input, final Set output, final boolean returnInside) { + inputVariables = input; + outputVariables = output; + returnInstructonInside = returnInside; + } + + public Set getInputVariables() { + return inputVariables; + } + + public Set getOutputVariables() { + return outputVariables; + } + + public boolean isReturnInstructonInside() { + return returnInstructonInside; + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CodeFragmentUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CodeFragmentUtil.java new file mode 100644 index 0000000000..f6ac9466ef --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/CodeFragmentUtil.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2010 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.codeInsight.codeFragment; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; + +/** + * @author oleg + */ +public class CodeFragmentUtil { + public static Position getPosition(@NotNull final PsiElement element, final int startOffset, final int endOffset) { + final int offset = element.getTextOffset(); + if (offset < startOffset) { + return Position.BEFORE; + } + if (element.getTextOffset() < endOffset) { + return Position.INSIDE; + } + return Position.AFTER; + } + + public static boolean elementFit(final PsiElement element, final int start, final int end) { + return element != null && start <= element.getTextOffset() && element.getTextOffset() + element.getTextLength() <= end; + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/Position.java b/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/Position.java new file mode 100644 index 0000000000..28435de102 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/codeFragment/Position.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2010 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.codeInsight.codeFragment; + +/** + * @author oleg + */ +public enum Position { + BEFORE, + INSIDE, + AFTER +} -- 2.11.4.GIT