2
* Copyright (C) 2009-2011 Mathias Doenitz
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package org.parboiled.transform;
19
import org.parboiled.BaseParser;
20
import org.parboiled.Rule;
21
import org.parboiled.common.ImmutableList;
22
import org.testng.annotations.Test;
24
import java.util.List;
26
import static org.testng.Assert.assertEquals;
27
import static org.testng.Assert.fail;
29
@SuppressWarnings({"InstantiatingObjectToGetClassObject"})
30
public class ErrorDetectionTest extends TransformationTest {
32
private final List<RuleMethodProcessor> processors = ImmutableList.of(
33
new UnusedLabelsRemover(),
34
new ReturnInstructionUnifier(),
35
new InstructionGraphCreator(),
36
new ImplicitActionsConverter(),
37
new InstructionGroupCreator(),
38
new InstructionGroupPreparer(),
39
new ActionClassGenerator(true),
40
new RuleMethodRewriter()
44
public synchronized void testRuleWithActionAccessingPrivateField() throws Exception {
45
setup(new BaseParser<Object>() {
46
private int privateInt = 5;
48
public Rule RuleWithActionAccessingPrivateField() {
49
return Sequence('a', privateInt == 0);
54
processMethod("RuleWithActionAccessingPrivateField", processors);
56
} catch (Exception e) {
57
assertEquals(e.getMessage(),
58
"Rule method 'RuleWithActionAccessingPrivateField' contains an illegal access to private field 'privateInt'.\n" +
59
"Mark the field protected or package-private if you want to prevent public access!");
64
public synchronized void testRuleWithActionAccessingPrivateMethod() throws Exception {
65
setup(new BaseParser<Object>() {
66
public Rule RuleWithActionAccessingPrivateMethod() {
67
return Sequence('a', privateAction());
70
private boolean privateAction() {
76
processMethod("RuleWithActionAccessingPrivateMethod", processors);
78
} catch (Exception e) {
79
assertEquals(e.getMessage(),
80
"Rule method 'RuleWithActionAccessingPrivateMethod' contains an illegal call to private method 'privateAction'.\n" +
81
"Mark 'privateAction' protected or package-private if you want to prevent public access!");