Browse Source
+ Pruned a number of attributes from the @Bean and @Configuration annotations git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@744 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
16 changed files with 264 additions and 510 deletions
@ -1,75 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2002-2008 the original author or authors. |
|
||||||
* |
|
||||||
* 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 org.springframework.config.java; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.Arrays; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* TODO: rename to UsageException / move outside .internal? |
|
||||||
* |
|
||||||
* @author Chris Beams |
|
||||||
*/ |
|
||||||
@SuppressWarnings("serial") |
|
||||||
public class MalformedConfigurationException extends RuntimeException { |
|
||||||
|
|
||||||
private final List<? extends UsageError> errors; |
|
||||||
|
|
||||||
public MalformedConfigurationException(String message) { |
|
||||||
super(message); |
|
||||||
this.errors = new ArrayList<UsageError>(); |
|
||||||
} |
|
||||||
|
|
||||||
public MalformedConfigurationException(UsageError... errors) { |
|
||||||
super(toString(errors)); |
|
||||||
this.errors = Arrays.asList(errors); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean containsError(Class<? extends UsageError> errorType) { |
|
||||||
for (UsageError error : errors) |
|
||||||
if (error.getClass().isAssignableFrom(errorType)) |
|
||||||
return true; |
|
||||||
|
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Render a list of syntax errors as output suitable for diagnosis via System.err. |
|
||||||
*/ |
|
||||||
private static String toString(UsageError... errors) { |
|
||||||
StringBuilder sb = new StringBuilder(); |
|
||||||
|
|
||||||
sb.append("\n"); |
|
||||||
|
|
||||||
if (errors.length == 1) |
|
||||||
sb.append("A usage error has "); |
|
||||||
else |
|
||||||
sb.append(errors.length + " usage errors have "); |
|
||||||
|
|
||||||
sb.append("been detected:\n"); |
|
||||||
|
|
||||||
for (int i = 0; i < errors.length; i++) { |
|
||||||
sb.append(errors[i].toString()); |
|
||||||
if ((i + 1) < errors.length) |
|
||||||
sb.append('\n'); |
|
||||||
} |
|
||||||
|
|
||||||
return sb.toString(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,73 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2002-2008 the original author or authors. |
|
||||||
* |
|
||||||
* 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 org.springframework.config.java; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Represents an invalid usage of JavaConfig constructs, e.g. a {@link Configuration} that |
|
||||||
* declares no {@link Bean @Bean} methods, or declaring both {@link Bean @Bean} and |
|
||||||
* {@link ExternalBean @ExternalBean} on a single method. Explore the type hierarchy to |
|
||||||
* discover all possible usage errors. |
|
||||||
* |
|
||||||
* @author Chris Beams |
|
||||||
* @see MalformedConfigurationException |
|
||||||
*/ |
|
||||||
public abstract class UsageError { |
|
||||||
|
|
||||||
private final ModelClass clazz; |
|
||||||
private final int lineNumber; |
|
||||||
|
|
||||||
/** |
|
||||||
* Create a new usage error, providing information about where the error was detected. |
|
||||||
* |
|
||||||
* @param modelClass class in which this error was detected. Null value indicates that |
|
||||||
* the error was not local to a single class. |
|
||||||
* @param lineNumber line number on which this error was detected (useful for tooling |
|
||||||
* integration) |
|
||||||
* |
|
||||||
* @see ModelClass#getSource() |
|
||||||
*/ |
|
||||||
public UsageError(ModelClass modelClass, int lineNumber) { |
|
||||||
this.clazz = modelClass; |
|
||||||
this.lineNumber = lineNumber; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Human-readable description of this error suitable for console output or IDE tooling. |
|
||||||
*/ |
|
||||||
public abstract String getDescription(); |
|
||||||
|
|
||||||
/** |
|
||||||
* Same as {@link #getDescription()} but attributed with class and line number |
|
||||||
* information. If modelClass constructor parameter was null, class and line number |
|
||||||
* information will be omitted. |
|
||||||
*/ |
|
||||||
public final String getAttributedDescription() { |
|
||||||
if (clazz == null) |
|
||||||
return getDescription(); |
|
||||||
|
|
||||||
return String.format("%s:%d: %s", clazz.getSource(), lineNumber, getDescription()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Delegates directly to {@link #getAttributedDescription()}. |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
return getAttributedDescription(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,18 +0,0 @@ |
|||||||
package org.springframework.config.java; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Indicates a type is able to be validated for errors. |
|
||||||
* |
|
||||||
* @author Chris Beams |
|
||||||
*/ |
|
||||||
interface Validatable { |
|
||||||
|
|
||||||
/** |
|
||||||
* Validates this object, adding any errors to the supplied list of <var>errors</var>. |
|
||||||
*/ |
|
||||||
public void validate(List<UsageError> errors); |
|
||||||
|
|
||||||
} |
|
||||||
Loading…
Reference in new issue