mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: fix multiple target check
This commit is contained in:
+2
-2
@@ -210,8 +210,8 @@ class JavaPredefinedConfigurations {
|
||||
"@interface 'Interface {}", METADATA_TYPE),
|
||||
|
||||
// J2EE templates
|
||||
createSearchTemplateInfoSimple(SSRBundle.message("predefined.configuration.struts.1.1.actions"),"public class 'StrutsActionClass extends '_ParentClass*:Action {\n" +
|
||||
" public ActionForward 'AnActionMethod:*execute (ActionMapping '_action,\n" +
|
||||
createSearchTemplateInfoSimple(SSRBundle.message("predefined.configuration.struts.1.1.actions"),"public class '_StrutsActionClass extends '_ParentClass*:Action {\n" +
|
||||
" public ActionForward '_AnActionMethod:*execute (ActionMapping '_action,\n" +
|
||||
" ActionForm '_form,\n" +
|
||||
" HttpServletRequest '_request,\n" +
|
||||
" HttpServletResponse '_response);\n" +
|
||||
|
||||
+6
-6
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.structuralsearch.impl.matcher.compiler;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -56,10 +56,10 @@ public class StringToConstraintsTransformer {
|
||||
while (endIndex < length && Character.isJavaIdentifierPart(criteria.charAt(endIndex))) endIndex++;
|
||||
if (endIndex == index) throw new MalformedPatternException(SSRBundle.message("error.expected.character"));
|
||||
|
||||
boolean anonymous = false;
|
||||
boolean target = true;
|
||||
final String typedVar;
|
||||
if (criteria.charAt(index)=='_') {
|
||||
anonymous = true;
|
||||
target = false;
|
||||
|
||||
if(endIndex == index + 1) {
|
||||
// anonymous var, make it unique for the case of constraints
|
||||
@@ -143,11 +143,11 @@ public class StringToConstraintsTransformer {
|
||||
constraint.setMinCount(minOccurs);
|
||||
constraint.setMaxCount(maxOccurs);
|
||||
constraint.setGreedy(greedy);
|
||||
constraint.setPartOfSearchResults(!anonymous);
|
||||
if (targetFound && !anonymous) {
|
||||
constraint.setPartOfSearchResults(target);
|
||||
if (targetFound && target) {
|
||||
throw new MalformedPatternException(SSRBundle.message("error.only.one.target.allowed"));
|
||||
}
|
||||
targetFound = !anonymous;
|
||||
targetFound |= target;
|
||||
}
|
||||
else if (savedIndex != index) {
|
||||
throw new MalformedPatternException(SSRBundle.message("error.condition.only.on.first.variable.reference"));
|
||||
|
||||
+3
-3
@@ -196,7 +196,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase {
|
||||
assertEquals("Expression replacement", expectedResult3, replacer.testReplace(expectedResult1,str5,str6,options));
|
||||
|
||||
String str7 = "try { a.doSomething(); b.doSomething(); } catch(IOException ex) { ex.printStackTrace(); throw new RuntimeException(ex); }";
|
||||
String str8 = "try { 'Statements+; } catch('_ '_) { 'HandlerStatements+; }";
|
||||
String str8 = "try { '_Statements+; } catch('_ '_) { '_HandlerStatements+; }";
|
||||
String str9 = "$Statements$;";
|
||||
String expectedResult4 = "a.doSomething(); b.doSomething();";
|
||||
|
||||
@@ -1056,9 +1056,9 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase {
|
||||
"\n" +
|
||||
"}";
|
||||
|
||||
String s35 = "public interface 'MessageInterface {\n" +
|
||||
String s35 = "public interface '_MessageInterface {\n" +
|
||||
" public static final String '_X = '_VALUE;\n" +
|
||||
" 'blah*" +
|
||||
" '_blah*" +
|
||||
"}";
|
||||
String s36 = "public interface $MessageInterface$ {\n" +
|
||||
" public static final String HEADER = $VALUE$;\n" +
|
||||
|
||||
+11
-15
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.structuralsearch.impl.matcher.compiler;
|
||||
|
||||
import com.intellij.structuralsearch.MalformedPatternException;
|
||||
@@ -266,6 +252,16 @@ public class StringToConstraintsTransformerTest {
|
||||
assertEquals("a", constraint.getRegExp());
|
||||
}
|
||||
|
||||
@Test(expected = MalformedPatternException.class)
|
||||
public void testMultipleTargets() {
|
||||
test("try { 'Statements+; } catch('_ '_) { 'HandlerStatements+; }");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameTargetMultipleTimes() {
|
||||
test("'a = 'a;");
|
||||
}
|
||||
|
||||
private void test(String criteria) {
|
||||
StringToConstraintsTransformer.transformCriteria(criteria, myOptions);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user