mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
iterate over: correct offset to detect template applicability
This commit is contained in:
@@ -51,6 +51,14 @@ public class IterateOverIterableIntention implements IntentionAction {
|
||||
final int selEnd = editor.getSelectionModel().getSelectionEnd();
|
||||
startOffset = (offset == selStart) ? selEnd : selStart;
|
||||
}
|
||||
PsiElement element = file.findElementAt(startOffset);
|
||||
while (element instanceof PsiWhiteSpace) {
|
||||
element = element.getPrevSibling();
|
||||
}
|
||||
PsiStatement psiStatement = PsiTreeUtil.getParentOfType(element, PsiStatement.class, false);
|
||||
if (psiStatement != null) {
|
||||
startOffset = psiStatement.getTextRange().getStartOffset();
|
||||
}
|
||||
if (!template.isDeactivated() &&
|
||||
(TemplateManagerImpl.isApplicable(file, offset, template) ||
|
||||
(TemplateManagerImpl.isApplicable(file, startOffset, template)))) {
|
||||
@@ -97,6 +105,12 @@ public class IterateOverIterableIntention implements IntentionAction {
|
||||
}
|
||||
|
||||
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
while (element instanceof PsiWhiteSpace) {
|
||||
element = element.getPrevSibling();
|
||||
}
|
||||
if (element instanceof PsiExpressionStatement) {
|
||||
element = ((PsiExpressionStatement)element).getExpression().getLastChild();
|
||||
}
|
||||
while ((element = PsiTreeUtil.getParentOfType(element, PsiExpression.class, true)) != null) {
|
||||
if (element.getParent() instanceof PsiMethodCallExpression) continue;
|
||||
final PsiType type = ((PsiExpression)element).getType();
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
// "Iterate" "true"
|
||||
class Test {
|
||||
void foo() {
|
||||
for (Annotation annotation : getClass().getAnnotations()) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
// "Iterate" "true"
|
||||
class Test {
|
||||
void foo() {
|
||||
for (Annotation annotation : getClass().getAnnotations()) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Iterate" "true"
|
||||
class Test {
|
||||
void foo() {
|
||||
getClass().getAnnotatio<caret>ns()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Iterate" "true"
|
||||
class Test {
|
||||
void foo() {
|
||||
getClass().getAnnotations()<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
/*
|
||||
* Copyright 2000-2012 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.daemon.quickFix;
|
||||
|
||||
|
||||
|
||||
public class IterateOverTest extends LightQuickFix15TestCase {
|
||||
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/iterateOver";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user