Skip to content

Commit b8288a3

Browse files
committed
Fixing the declaration of a test case. Of course it was a failing test.
1 parent 99dfb95 commit b8288a3

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
lines changed

src/lang/java/refactoring/forloop/test/ProspectiveOperationTest.rsc

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public test bool innerIfAsNotTheLastStatementShouldBeAMap() {
141141
prospectiveOperations[4].operation == FOR_EACH;
142142
}
143143

144-
public void shouldThrowExceptionOnLoopWithInnerLoop() {
144+
public test bool shouldThrowExceptionOnLoopWithInnerLoop() {
145145
tuple [set[MethodVar] vars, EnhancedForStatement loop] loop = outerLoopWithInnerLoop();
146146

147147
try {

src/lang/java/refactoring/forloop/test/resources/ProspectiveOperationTestResources.rsc

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public tuple [set[MethodVar] vars, EnhancedForStatement loop] outerLoopWithInner
146146
methodBody = parse(#MethodBody, "{" + loopStr + "}");
147147

148148
localVars = findLocalVariables(methodHeader, methodBody);
149-
classLoc = |project://rascal-Java8//testes/forloop/Refactorer/ClassRefactorableInnerLoopButNotOuter|;
149+
classLoc = |project://rascal-Java8//testes/forloop/Refactorer/ServletComponentRegisteringPostProcessor.java|;
150150
classFields = findClassFields(parse(#CompilationUnit, classLoc));
151151
availableVars = localVars + classFields;
152152

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
for (BeanDefinition candidate : componentProvider
2+
.findCandidateComponents(packageToScan)) {
3+
if (candidate instanceof ScannedGenericBeanDefinition) {
4+
for (ServletComponentHandler handler : HANDLERS) {
5+
handler.handle(((ScannedGenericBeanDefinition) candidate),
6+
(BeanDefinitionRegistry) this.applicationContext);
7+
}
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
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
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
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.
15+
*/
16+
17+
package org.springframework.boot.web.servlet;
18+
19+
import java.util.ArrayList;
20+
import java.util.Collections;
21+
import java.util.List;
22+
import java.util.Set;
23+
24+
import org.springframework.beans.BeansException;
25+
import org.springframework.beans.factory.config.BeanDefinition;
26+
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
27+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
28+
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
29+
import org.springframework.context.ApplicationContext;
30+
import org.springframework.context.ApplicationContextAware;
31+
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
32+
import org.springframework.context.annotation.ScannedGenericBeanDefinition;
33+
import org.springframework.web.context.WebApplicationContext;
34+
35+
/**
36+
* {@link BeanFactoryPostProcessor} that registers beans for Servlet components found via
37+
* package scanning.
38+
*
39+
* @author Andy Wilkinson
40+
* @see ServletComponentScan
41+
* @see ServletComponentScanRegistrar
42+
*/
43+
class ServletComponentRegisteringPostProcessor
44+
implements BeanFactoryPostProcessor, ApplicationContextAware {
45+
46+
private static final List<ServletComponentHandler> HANDLERS;
47+
48+
static {
49+
List<ServletComponentHandler> handlers = new ArrayList<>();
50+
handlers.add(new WebServletHandler());
51+
handlers.add(new WebFilterHandler());
52+
handlers.add(new WebListenerHandler());
53+
HANDLERS = Collections.unmodifiableList(handlers);
54+
}
55+
56+
private final Set<String> packagesToScan;
57+
58+
private ApplicationContext applicationContext;
59+
60+
ServletComponentRegisteringPostProcessor(Set<String> packagesToScan) {
61+
this.packagesToScan = packagesToScan;
62+
}
63+
64+
@Override
65+
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
66+
throws BeansException {
67+
if (isRunningInEmbeddedWebServer()) {
68+
ClassPathScanningCandidateComponentProvider componentProvider = createComponentProvider();
69+
for (String packageToScan : this.packagesToScan) {
70+
scanPackage(componentProvider, packageToScan);
71+
}
72+
}
73+
}
74+
75+
private void scanPackage(
76+
ClassPathScanningCandidateComponentProvider componentProvider,
77+
String packageToScan) {
78+
for (BeanDefinition candidate : componentProvider
79+
.findCandidateComponents(packageToScan)) {
80+
if (candidate instanceof ScannedGenericBeanDefinition) {
81+
for (ServletComponentHandler handler : HANDLERS) {
82+
handler.handle(((ScannedGenericBeanDefinition) candidate),
83+
(BeanDefinitionRegistry) this.applicationContext);
84+
}
85+
}
86+
}
87+
}
88+
89+
private boolean isRunningInEmbeddedWebServer() {
90+
return this.applicationContext instanceof WebApplicationContext
91+
&& ((WebApplicationContext) this.applicationContext)
92+
.getServletContext() == null;
93+
}
94+
95+
private ClassPathScanningCandidateComponentProvider createComponentProvider() {
96+
ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(
97+
false);
98+
componentProvider.setEnvironment(this.applicationContext.getEnvironment());
99+
componentProvider.setResourceLoader(this.applicationContext);
100+
for (ServletComponentHandler handler : HANDLERS) {
101+
componentProvider.addIncludeFilter(handler.getTypeFilter());
102+
}
103+
return componentProvider;
104+
}
105+
106+
Set<String> getPackagesToScan() {
107+
return Collections.unmodifiableSet(this.packagesToScan);
108+
}
109+
110+
@Override
111+
public void setApplicationContext(ApplicationContext applicationContext)
112+
throws BeansException {
113+
this.applicationContext = applicationContext;
114+
}
115+
116+
}

0 commit comments

Comments
 (0)