From 5880a85bb128dafa36907b87276914c84c36cb90 Mon Sep 17 00:00:00 2001 From: Matias Comercio Date: Thu, 27 Jul 2017 17:28:29 -0300 Subject: [PATCH] Autofix line ending issues These files didn't have the expected line ending according to the .gitattributes rule: `* text=auto`. Don't know why this could have happened, but all these files where created before the mentioned rule --- pmd-core/src/main/resources/pmd-nicerhtml.xsl | 546 ++--- .../services/net.sourceforge.pmd.cpd.Language | 2 +- .../net.sourceforge.pmd.lang.Language | 2 +- .../net/sourceforge/pmd/cpd/sample-matlab.m | 2128 ++++++++--------- .../lang/plsql/ast/InlinePragmaProcError.pls | 34 +- .../pmd/lang/plsql/ast/IsOfType.pls | 44 +- .../net/sourceforge/pmd/cpd/sample-python.py | 556 ++--- .../rulesets/pom/rulesets.properties | 10 +- .../rulesets/xml/rulesets.properties | 10 +- .../rulesets/xsl/rulesets.properties | 10 +- 10 files changed, 1671 insertions(+), 1671 deletions(-) diff --git a/pmd-core/src/main/resources/pmd-nicerhtml.xsl b/pmd-core/src/main/resources/pmd-nicerhtml.xsl index 1be9465e76..d398a1d497 100644 --- a/pmd-core/src/main/resources/pmd-nicerhtml.xsl +++ b/pmd-core/src/main/resources/pmd-nicerhtml.xsl @@ -1,275 +1,275 @@ - - - - - - - - - - - - - - - - - - - - - - - PMD <xsl:value-of select="//pmd/@version"/> Report - - - - - - - - - -
-

PMD Report. Generated on

-
- - - -
- - - -
- - - -
- - - - -
- - - - -
- - - - -

Rules

- - - - - - - - - - - - - - - - - - - - - - - -
RuleViolationsSeverity
- [] - - -
- -
-
-
- - - - -

Files

- - - - - - - - - - - - - - - - - - - - - - - - - - - -
File
5
4
3
2
1
- - -
-
- - - - - - -

File

- - - - - - - - - - - - - - - - -
ViolationError DescriptionLine
-
-
- [.] - - - - - - - - - - - -
- Back to top -
- - - - -

Summary

- - - - - - - - - - - - - - - - - - - - -
FilesTotal
Priority 1
Priority 2
Priority 3
Priority 4
Priority 5
-
- - - - - a - b - - -
- - + + + + + + + + + + + + + - + + + + + + + + + PMD <xsl:value-of select="//pmd/@version"/> Report + + + + + + + + + +
+

PMD Report. Generated on

+
+ + + +
+ + + +
+ + + +
+ + + + +
+ + + + +
+ + + + +

Rules

+ + + + + + + + + + + + + + + + + + + + + + + +
RuleViolationsSeverity
+ [] + + +
+ +
+
+
+ + + + +

Files

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
File
5
4
3
2
1
+ + +
+
+ + + + + + +

File

+ + + + + + + + + + + + + + + + +
ViolationError DescriptionLine
+
+
+ [.] + - + + + + + + + + - +
+ Back to top +
+ + + + +

Summary

+ + + + + + + + + + + + + + + + + + + + +
FilesTotal
Priority 1
Priority 2
Priority 3
Priority 4
Priority 5
+
+ + + + + a + b + + +
+ + diff --git a/pmd-matlab/src/main/resources/META-INF/services/net.sourceforge.pmd.cpd.Language b/pmd-matlab/src/main/resources/META-INF/services/net.sourceforge.pmd.cpd.Language index 0db55583f2..cbda640f65 100644 --- a/pmd-matlab/src/main/resources/META-INF/services/net.sourceforge.pmd.cpd.Language +++ b/pmd-matlab/src/main/resources/META-INF/services/net.sourceforge.pmd.cpd.Language @@ -1 +1 @@ -net.sourceforge.pmd.cpd.MatlabLanguage +net.sourceforge.pmd.cpd.MatlabLanguage diff --git a/pmd-matlab/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language b/pmd-matlab/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language index 9e379335bd..1e88740675 100644 --- a/pmd-matlab/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language +++ b/pmd-matlab/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language @@ -1 +1 @@ -net.sourceforge.pmd.lang.matlab.MatlabLanguageModule +net.sourceforge.pmd.lang.matlab.MatlabLanguageModule diff --git a/pmd-matlab/src/test/resources/net/sourceforge/pmd/cpd/sample-matlab.m b/pmd-matlab/src/test/resources/net/sourceforge/pmd/cpd/sample-matlab.m index 54abfa4118..915d135159 100644 --- a/pmd-matlab/src/test/resources/net/sourceforge/pmd/cpd/sample-matlab.m +++ b/pmd-matlab/src/test/resources/net/sourceforge/pmd/cpd/sample-matlab.m @@ -1,1065 +1,1065 @@ -% Example source code copied from the Chebfun project on GitHub: -% https://github.com/chebfun/chebfun/blob/development/@chebfun/chebfun.m - -classdef chebfun -%CHEBFUN CHEBFUN class for representing functions on [a,b]. -% -% Class for approximating functions defined on finite, semi-infinite, or -% doubly-infinite intervals [a,b]. Functions may be smooth, piecewise smooth, -% weakly singular, or blow up on the interval. -% -% CHEBFUN(F) constructs a CHEBFUN object representing the function F on the -% interval [-1,1]. F may be a string, e.g., 'sin(x)', a function handle, e.g., -% @(x) x.^2 + 2*x + 1, or a vector of numbers. In the first two instances, F -% should be "vectorized" in the sense that it may be evaluated at a column -% vector of points x(:) in [-1,1] and return an output of size NxM where N = -% length(x(:)). If this is not possible then the flag CHEBFUN(F, 'vectorize') -% should be passed. CHEBFUN(F, 'vectorcheck', 'off') disables the automatic -% checking for vector input. Additionally, F may be a CHEBFUN, in which case -% CHEBFUN(F) is equivalent to CHEBFUN(@(X) FEVAL(F, X)). CHEBFUN() returns an -% empty CHEBFUN object. -% -% CHEBFUN(F, [A, B]) specifies an interval [A,B] on which the CHEBFUN is -% defined, where A and/or B may be infinite. CHEBFUN(F, ENDS), where ENDS is a -% 1x(K+1) vector of unique ascending values, specifies a piecewise smooth -% CHEBFUN defined on the interval [ENDS(1), ENDS(K+1)] with additional interior -% breaks at ENDS(2), ..., ENDS(K). Specifying these breaks can be particularly -% useful if F is known to have discontinuities. For example, -% CHEBFUN(@(x) abs(x), [-1, 0, 1]). -% If a domain is passed to the constructor, it should always be the 2nd input. -% -% CHEBFUN(A) or CHEBFUN(A, 'chebkind', 2), where A is an Nx1 matrix, constructs -% a CHEBFUN object which interpolates the data in A on an N-point Chebyshev grid -% of the second kind (see >> help chebpts). CHEBFUN(A, 'chebkind', 1) and -% CHEBFUN(A, 'equi') are similar, but here the data is assumed to come from a -% 1st-kind Chebyshev or equispaced grid linspace(-1, 1, N), respectively. (In -% the latter case, a smooth interpolant is constructed using an adaptive -% Floater-Hormann scheme [Numer. Math. 107, 315-331 (2007)].). CHEBFUN(F, N) or -% CHEBFUN(F, N, 'chebkind', 2) is equivalent to CHEBFUN(feval(F, chebpts(N)). -% -% CHEBFUN(C, 'coeffs'), where C is an Nx1 matrix, constructs a CHEBFUN object -% representing the polynomial C(1) T_0(x) + ... + C(N) T_(N-1)(x), -% where T_K(x) denotes the K-th Chebyshev polynomial. This is equivalent to -% CHEBFUN({{[], C}}). C may also be an NxM matrix, as described below. -% -% CHEBFUN(F, ...), where F is an NxM matrix or an array-valued function handle, -% returns an "array-valued" CHEBFUN. For example, -% CHEBFUN(rand(14, 2)) -% or -% CHEBFUN(@(x) [sin(x), cos(x)]) -% Note that each column in an array-valued CHEBFUN object is discretized in the -% same way (i.e., the same breakpoint locations and the same underlying -% representation). For more details see ">> help quasimatrix". Note the -% difference between -% CHEBFUN(@(x) [sin(x), cos(x)], [-1, 0, 1]) -% and -% CHEBFUN({@(x) sin(x), @(x) cos(x)}, [-1, 0, 1]). -% The former constructs an array-valued CHEBFUN with both columns defined on the -% domain [-1, 0, 1]. The latter defines a single column CHEBFUN which represents -% sin(x) in the interval [-1, 0) and cos(x) on the interval (0, 1]. -% -% CHEBFUN({F1,...,Fk}, ENDS) constructs a piecewise smooth CHEBFUN which -% represents Fj on the interval [ENDS(j), END(j+1)]. Each entry Fj may be a -% string, function handle, or vector of doubles. For example -% CHEBFUN({@(x) sin(x), @(x) cos(x)}, [-1, 0, 1]) -% -% CHEBFUN(F, PREF) or CHEBFUN(F, [A, B], PREF) constructs a CHEBFUN object from -% F with the options determined by the CHEBFUNPREF object PREF. Construction -% time options may also be passed directly to the constructor in the form -% CHEBFUN(F, [A, B], PROP1, VAL1, PROP2, VAL2, ...). (See CHEBFUNPREF for -% details of the various preference options and their defaults.). In -% particular, CHEBFUN(F, 'splitting', 'on') allows the constructor to -% adaptively determine breakpoints to better represent piecewise smooth -% functions F. For example, -% CHEBFUN(@(x) sign(x - .3), [-1, 1], 'splitting', 'on') -% CHEBFUN(F, 'extrapolate', 'on') prevents the constructor from evaluating the -% function F at the endpoints of the domain. -% -% If PROP/VAL and PREF inputs are mixed in a single constructor call, the -% preferences determined by the PROP/VAL inputs take priority over those -% determined by PREF. At most one PREF input may be supplied to the -% constructor at any time. -% -% CHEBFUN(F, 'trunc', N) returns a smooth N-point CHEBFUN constructed by -% computing the first N Chebyshev coefficients from their integral form, rather -% than by interpolation at Chebyshev points. -% -% CHEBFUN(F, 'trig') constructs a CHEBFUN object representing a smooth and -% periodic function F on the interval [-1,1]. The resulting CHEBFUN is -% represented using a Fourier series. All operations done on F should preserve -% smoothness and periodicity, otherwise results are casted into chebfuns -% represented by Chebyshev rather than Fourier series. Similar options -% as discussed above may be combined with the 'trig' flag, with exception to -% the 'chebkind' and 'splitting' flags. -% -% CHEBFUN(F, 'periodic') is the same as CHEBFUN(F, 'trig'). -% -% CHEBFUN --UPDATE can be used to update to the latest stable release of CHEBFUN -% (obviously an internet connection is required!). CHEBFUN --UPDATE-DEVEL will -% update to the latest development release, but we recommend instead that you -% checkout from the Github repo https://github.com/chebfun/chebfun/. See -% CHEBFUN.UPDATE() for further details. -% -% See also CHEBFUNPREF, CHEBPTS. - -% Copyright 2014 by The University of Oxford and The Chebfun Developers. -% See http://www.chebfun.org/ for Chebfun information. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% CHEBFUN Class Description: -% -% The CHEBFUN class is for representations of piecewise functions on the -% interval [a,b]. -% -% The CHEBFUN class is the main user interface. We do not expect users to -% directly invoke any objects below this level. -% -% A CHEBFUN object consists of a collection of FUN objects. There are two main -% tasks for the CHEBFUN constructor: (1) parse the user input, and (2) correctly -% piece together FUN objects to form a global approximation. If the input -% function is globally smooth then the resulting CHEBFUN contains a single FUN -% object. If the input is not smooth, or breakpoints are passed to the -% constructor, CHEBFUN must determine appropriate breakpoints and return a -% piecewise smooth CHEBFUN with multiple FUN objects. -% -% This is a user-level class, and all input arguments should be thoroughly -% sanity checked. -% -% Class diagram: [ADchebfun] <>-- [CHEBFUN] <>-- [<>] -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %% CLASS PROPERTIES: - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - properties (Access = public) - % DOMAIN of definition of a CHEBFUN object. If K = length(F.DOMAIN) is - % greater than 1 then the CHEBFUN is referred to as a "piecewise". - % CHEBFUN. The first and last values of this vector define the left and - % right endpoints of the domain, respectively. The other values give the - % locations of the interior breakpoints that define the domains of the - % individual FUN objects comprising the CHEBFUN. The entries in this - % vector should be strictly increasing. - domain % (1x(K+1) double) - - % FUNS is a cell array containing the FUN objects that comprise a - % piecewise CHEBFUN. The kth entry in this cell is the FUN defining - % the representation used by the CHEBFUN object on the open interval - % (F.DOMAIN(k), F.DOMAIN(k+1)). If M = size(f.funs, 2) is greater than - % 1, then the CHEBFUN object is referred to as "array valued". - funs % (Kx1 cell array of FUN objects) - - % POINTVALUES Values of the function at the break points. - pointValues = []; % (1 x (K+1) double) - - % ISTRANSPOSED determines whether a (possibly array-valued) CHEBFUN F - % should be interpreted as a collection of "column" CHEBFUN objects (if - % F.ISTRANSPOSED == 0, the default), which are considered (infxM) - % arrays, or "row" CHEBFUN objects (if F.ISTRANSPOSED == 1), which are - % (Mxinf) arrays. This difference is only behavioral; the other - % properties described above are _NOT_ stored differently if this flag - % is set.) - isTransposed = 0; % (logical) - end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %% CLASS CONSTRUCTOR: - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - methods ( Access = public, Static = false ) - - function f = chebfun(varargin) - % The main CHEBFUN constructor! - - % Return an empty CHEBFUN: - if ( (nargin == 0) || isempty(varargin{1}) ) - return - end - - if ( iscell(varargin{1}) && ... - all(cellfun(@(x) isa(x, 'fun'), varargin{1})) ) - % Construct a CHEBFUN from a cell array of FUN objects. - % Note, this is not affected by the input parser (see error - % message below) and must be _fast_ as it is done often. - if ( nargin > 1 ) - error('CHEBFUN:CHEBFUN:chebfun:nargin', ... - 'Only one input is allowed when passing an array of FUNs.') - end - % Assign the cell to the .FUNS property: - f.funs = varargin{1}; - % Collect the domains together: - dom = cellfun(@(fun) get(fun, 'domain'), f.funs, ... - 'uniformOutput', false); - f.domain = unique([dom{:}]); - % Update values at breakpoints (first row of f.pointValues): - f.pointValues = chebfun.getValuesAtBreakpoints(f.funs, f.domain); - return - end - - % Parse inputs: - [op, dom, data, pref] = parseInputs(varargin{:}); - - if ( strcmp(op, 'done') ) - % An update was performed. Exit gracefully: - throwAsCaller(MException('', '')) - end - - % Deal with 'trunc' option: - doTrunc = false; - truncLength = NaN; - for k = 1:length(varargin) - if ( strcmpi(varargin{k}, 'trunc') ) - doTrunc = true; - truncLength = varargin{k+1}; - break - end - end - - if ( isa(op, 'chebfun') && doTrunc ) - % Deal with the particular case when we're asked to truncate a - % CHEBFUN: - f = op; - - else - % Construct from function_handle, numeric, or string input: - - % Call the main constructor: - [f.funs, f.domain] = chebfun.constructor(op, dom, data, pref); - - % Update values at breakpoints (first row of f.pointValues): - f.pointValues = chebfun.getValuesAtBreakpoints(f.funs, ... - f.domain, op); - - % Remove unnecessary breaks (but not those that were given): - [ignored, index] = setdiff(f.domain, dom); - f = merge(f, index(:).', pref); - - end - - if ( doTrunc ) - % Truncate the CHEBFUN to the required length: - if ( isa( pref.tech(),'chebtech' ) ) - c = chebcoeffs(f, truncLength); - else - c = trigcoeffs(f, truncLength); - end - f = chebfun(c, f.domain([1,end]), 'coeffs', pref); - end - - end - - end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %% CLASS METHODS: - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - methods ( Access = public, Static = false ) - - % Absolute value of a CHEBFUN. - f = abs(f, pref) - - % True if any element of a CHEBFUN is a nonzero number, ignoring NaN. - a = any(f, dim) - - % Compute the length of the arc defined by a CHEBFUN. - out = arcLength(f, a, b) - - % Solve boundary value problems for ODEs by collocation. - [y, t] = bvp4c(fun1, fun2, y0, varargin); - - % Solve boundary value problems for ODEs by collocation. - [y, t] = bvp5c(fun1, fun2, y0, varargin); - - % Round a CHEBFUN towards plus infinity. - g = ceil(f) - - % Plot information regarding the representation of a CHEBFUN object: - h = plotcoeffs(f, varargin); - - % Construct complex CHEBFUN from real and imaginary parts. - C = complex(A, B) - - % Compose CHEBFUN objects with another function. - h = compose(f, op, g, pref) - - % Complex conjugate of a CHEBFUN. - f = conj(f) - - % Complex transpose of a CHEBFUN. - f = ctranspose(f) - - % Display a CHEBFUN object. - display(f); - - % Accuracy estimate of a CHEBFUN object. - out = epslevel(f, flag); - - % Evaluate a CHEBFUN. - y = feval(f, x, varargin) - - % Round a CHEBFUN towards zero. - g = fix(f); - - % Round a CHEBFUN towards minus infinity. - g = floor(f); - - % Get properties of a CHEBFUN object. - out = get(f, prop, simpLevel); - - % Horizontal scale of a CHEBFUN object. - out = hscale(f); - - % Imaginary part of a CHEBFUN. - f = imag(f) - - % True for an empty CHEBFUN. - out = isempty(f) - - % Test if CHEBFUN objects are equal. - out = isequal(f, g) - - % Test if a CHEBFUN is bounded. - out = isfinite(f) - - % Test if a CHEBFUN is unbounded. - out = isinf(f) - - % Test if a CHEBFUN has any NaN values. - out = isnan(f) - - % True for real CHEBFUN. - out = isreal(f); - - % Test if a CHEBFUN object is built upon DELTAFUN. - out = isdelta(f); - - % Test if a CHEBFUN object is built upon SINGFUN. - out = issing(f) - - % Test if a CHEBFUN object is built upon a basis of periodic - % functions, i.e., a periodic TECH. - out = isPeriodicTech(f) - - % True for zero CHEBFUN objects. - out = iszero(f) - - % Kronecker product of two CHEBFUN object. - out = kron(f, g) - - % Length of a CHEBFUN. - [out, out2] = length(f); - - % Return Legendre coefficients of a CHEBFUN. - c_leg = legpoly(f, n) - - % Plot a CHEBFUN object on a loglog scale: - h = loglog(f, varargin); - - % Subtraction of two CHEBFUN objects. - f = minus(f, g) - - % Multiplication of CHEBFUN objects. - f = mtimes(f, c) - - % Remove unnecessary breakpoints in from a CHEBFUN. - [f, mergedPts] = merge(f, index, pref) - - % Overlap the domain of two CHEBFUN objects. - [f, g] = overlap(f, g) - - % Plot a CHEBFUN object: - varargout = plot(f, varargin); - - % 3-D plot for CHEBFUN objects. - varargout = plot3(f, g, h, varargin) - - % Power of a CHEBFUN - f = power(f, b, pref); - - % Real part of a CHEBFUN. - f = real(f) - - % Restrict a CHEBFUN object to a subdomain. - f = restrict(f, newDomain); - - % The roots of the CHEBFUN F. - r = roots(f, varargin); - - % Round a CHEBFUN towards nearest integer. - g = round(f) - - % Plot a CHEBFUN object on a log-linear scale: - h = semilogx(f, varargin); - - % Plot a CHEBFUN object on a linear-log scale: - h = semilogy(f, varargin); - - % Signum of a CHEBFUN. - f = sign(f, pref) - - % Simplify the representation of a CHEBFUN object. - f = simplify(f, tol); - - % Size of a CHEBFUN object. - [s1, s2] = size(f, dim); - - % Square root of a CHEBFUN. - f = sqrt(f, pref) - - % Retrieve and modify preferences for this class. - varargout = subsref(f, index); - - % Retrieve and modify preferences for this class. - varargout = subsasgn(f, varargin); - - % CHEBFUN multiplication. - f = times(f, g, varargin) - - % Transpose a CHEBFUN. - f = transpose(f) - - % Unary minus of a CHEBFUN. - f = uminus(f) - - % Unary plus of a CHEBFUN. - f = uplus(f) - - % Vertical scale of a CHEBFUN object. - out = vscale(f, s); - end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %% HIDDEN METHODS: - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - methods ( Hidden = true, Static = false ) - - % Add breakpoints to the domain of a CHEBFUN. - f = addBreaks(f, breaks, tol) - - % Add breaks at appropriate roots of a CHEBFUN. - f = addBreaksAtRoots(f, tol) - - % Assign columns (or rows) of an array-valued CHEBFUN. - f = assignColumns(f, colIdx, g) - - % Convert a CHEBFUN to another TECH. - f = changeTech(f, newtech); - - % Deprecated function. - f = define(f,s,v); - - % Supply a new definition for a CHEBFUN on a subinterval. - f = defineInterval(f, subInt, g) - - % Supply new definition for a CHEBFUN at a point or set of points. - f = definePoint(f, s, v) - - % Multiplication operator. - M = diag(f) - - % Useful information for DISPLAY. - [name, data] = dispData(f) - - % Compare domains of two CHEBFUN objects. - pass = domainCheck(f, g); - - % Extract columns of an array-valued CHEBFUN object. - f = extractColumns(f, columnIndex); - - % Deprecated function. - varargin = fzero(varargout); - - % Get Delta functions within a CHEBFUN. - [deltaMag, deltLoc] = getDeltaFunctions(f); - - % Get roots of a CHEBFUN and polish for use as breakpoints. - [rBreaks, rAll] = getRootsForBreaks(f, tol) - - % Returns true if numel(f) > 1 - out = isQuasi(f) - - % Number of columns (or rows) of a CHEBFUN quasimatrix. - out = numColumns(f) - - % Obtain data used for plotting a CHEBFUN object: - data = plotData(f, g, h) - - % Deprecated function. - varargin = quad(varargout); - - % Set pointValues property: - f = setPointValues(f, j, k, vals) - - % Remove all-zero layers of higher-order impulses. - f = tidyImpulses(f) - - % Adjust nearby common break points in domains of CHEBFUN objects. - [f, g, newBreaksLocF, newBreaksLocG] = tweakDomain(f, g, tol, pos) - - end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %% PRIVATE METHODS: - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - methods ( Access = private, Static = false ) - % Set small breakpoint values to zero. - f = thresholdBreakpointValues(f); - end - - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %% STATIC METHODS: - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - methods ( Access = public, Static = true ) - - % Discrete cosine transform: - y = dct(u, kind); - - % Inverse discrete cosine transform: - u = idct(y, kind); - - % Discrete sine transform: - y = dst(u, kind); - - % Inverse discrete sine transform: - u = idst(y, kind); - - % Interpolate data: - f = interp1(x, y, method, dom); - - % Compute Lagrange basis functions for a given set of points. - f = lagrange(x, varargin); - - % ODE113 with CHEBFUN output. - [t, y] = ode113(varargin); - - % ODE15S with CHEBFUN output. - [t, y] = ode15s(varargin); - - % ODE45 with CHEBFUN output. - [t, y] = ode45(varargin); - - % Cubic Hermite interpolation: - f = pchip(x, y, method); - - % Cubic spline interpolant: - f = spline(x, y, d); - - % Update Chebfun source files: - update(varargin) - - end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %% HIDDEN STATIC METHODS: - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - methods ( Hidden = true, Static = true ) - - % Convert a cell array of CHEBFUN objects to a quasimatrix. - G = cell2quasi(F) - - % Determine values of CHEBFUN at breakpoints. - vals = getValuesAtBreakpoints(funs, ends, op); - - % Which interval is a point in? - out = whichInterval(dom, x, direction); - - end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %% PRIVATE STATIC METHODS: - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - methods ( Access = private, Static = true ) - - % Main constructor. - [funs, ends] = constructor(op, domain, data, pref); - - % Convert ODE solutions into CHEBFUN objects: - [y, t] = odesol(sol, dom, opt); - - % Parse inputs to PLOT. Extract 'lineWidth', etc. - [lineStyle, pointStyle, jumpStyle, deltaStyle, out] = ... - parsePlotStyle(varargin) - - end - -end - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Class-related functions: private utilities for this m-file. -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function op = str2op(op) - % Convert string inputs to either numeric format or function_handles. - sop = str2num(op); %#ok % STR2DOUBLE doesn't support str2double('pi') - if ( ~isempty(sop) ) - op = sop; - else - depVar = symvar(op); - if ( numel(depVar) ~= 1 ) - error('CHEBFUN:CHEBFUN:str2op:indepvars', ... - 'Incorrect number of independent variables in string input.'); - end - op = eval(['@(' depVar{:} ')', op]); - end -end - -function [op, dom, data, pref] = parseInputs(op, varargin) - - % TODO: Should we 'data' structure to be passed to the constructor? - % Currently, like in CHEBFUN/COMPOSE(), we don't have a use for this, but it - % might be useful in the future. - - % Deal with string input options. - if ( strncmp(op, '--', 2) ) - % An option has been passed to the constructor. - if ( strcmpi(op, '--update') ) - chebfun.update(); - elseif ( strcmpi(op, '--update-devel') ) - chebfun.update('development'); - elseif ( strcmpi(op, '--version') ) - installDir = chebfunroot(); - fid = fopen(fullfile(installDir, 'Contents.m'), 'r'); - fgetl(fid); - str = fgetl(fid); - disp(['Chebfun ', str(3:end)]); - fclose(fid); - else - error('CHEBFUN:parseInputs:unknown', ... - 'Unknow command %s.', op); - end - op = 'done'; - dom = []; - data = struct(); - pref = []; - return - end - - % Initialize data output. - data.hscale = []; - data.vscale = []; - data.exponents = []; - data.singType = []; - - args = varargin; - - % An op-only constructor call. - if ( nargin == 1 ) - pref = chebfunpref(); - end - - % Try to parse out the domain which, if passed, is the second argument. - domainWasPassed = false; - if ( ~isempty(args) ) - if ( isnumeric(args{1}) && ... - ((length(args{1}) >= 2) || isempty(args{1})) ) - dom = args{1}; - args(1) = []; - domainWasPassed = true; - elseif ( isa(args{1}, 'domain') ) - dom = double(args{1}); - args(1) = []; - domainWasPassed = true; - end - end - - % A struct to hold any preferences supplied by keyword (name-value pair). - keywordPrefs = struct(); - - % Parse the remaining arguments. - prefWasPassed = false; - isPeriodic = false; - vectorize = false; - doVectorCheck = true; - while ( ~isempty(args) ) - if ( isstruct(args{1}) || isa(args{1}, 'chebfunpref') ) - % Preference object input. (Struct inputs not tied to a keyword - % are interpreted as preference objects.) - if ( ~prefWasPassed ) - pref = chebfunpref(args{1}); - prefWasPassed = true; - args(1) = []; - else - error('CHEBFUN:CHEBFUN:parseInputs:twoPrefs', ... - 'Multiple preference inputs are not allowed.'); - end - elseif ( strcmpi(args{1}, 'equi') ) - % Enable FUNQUI when dealing with equispaced data. - keywordPrefs.tech = 'funqui'; - args(1) = []; - elseif ( strcmpi(args{1}, 'vectorize') || ... - strcmpi(args{1}, 'vectorise') ) - % Vectorize flag for function_handles. - vectorize = true; - args(1) = []; - elseif ( strcmpi(args{1}, 'novectorcheck') ) - % Vector check for function_handles. - doVectorCheck = false; - args(1) = []; - elseif ( strcmpi(args{1}, 'coeffs') && isnumeric(op) ) - % Hack to support construction from coefficients. - op = {{[], op}}; - args(1) = []; - elseif ( any(strcmpi(args{1}, {'periodic', 'trig'})) ) - isPeriodic = true; - args(1) = []; - elseif ( strcmpi(args{1}, 'coeffs') && iscell(op) ) - error('CHEBFUN:CHEBFUN:parseInputs:coeffcell', ... - 'Cannot construct CHEBFUN from a cell array of coefficients.'); - elseif ( strcmpi(args{1}, 'trunc') ) - % Pull out this preference, which is checked for later. - keywordPrefs.splitting = true; - args(1:2) = []; - elseif ( isnumeric(args{1}) && isscalar(args{1}) ) - % g = chebfun(@(x) f(x), N) - keywordPrefs.techPrefs.fixedLength = args{1}; - args(1) = []; - elseif ( strcmpi(args{1}, 'splitting') ) - keywordPrefs.splitting = strcmpi(args{2}, 'on'); - args(1:2) = []; - elseif ( strcmpi(args{1}, 'minsamples') ) - % Translate "minsamples" --> "techPrefs.minSamples". - keywordPrefs.techPrefs.minSamples = args{2}; - args(1:2) = []; - elseif ( strcmpi(args{1}, 'blowup') ) - if ( strcmpi(args{2}, 'off') ) - % If 'blowup' is 'off'. - keywordPrefs.blowup = 0; - else - % If 'blowup' is not 'off', set the singTypes. (NB: These - % cells really need to store a left and right singType for each - % domain subinterval, but we may not know the domain yet, so we - % store just one cell for now and replicate it later, after - % we've figured out the domain.) - if ( (isnumeric(args{2}) && args{2} == 1 ) || ... - strcmpi(args{2}, 'on') ) - % Translate "blowup" and flag "1" --> - % "blowup" and "poles only". - keywordPrefs.blowup = 1; - data.singType = {'pole'}; - elseif ( args{2} == 2 ) - % Translate "blowup" and flag "2" --> - % "blowup" and "fractional singularity". - keywordPrefs.blowup = 1; - data.singType = {'sing'}; - else - error('CHEBFUN:CHEBFUN:parseInputs:badBlowupOption', ... - 'Invalid value for ''blowup'' option.'); - end - end - args(1:2) = []; - elseif ( strcmpi(args{1}, 'vscale') ) - % Store vscale types. - data.vscale = args{2}; - args(1:2) = []; - elseif ( strcmpi(args{1}, 'hscale') ) - % Store vscale types. - data.vscale = args{2}; - args(1:2) = []; - elseif ( strcmpi(args{1}, 'singType') ) - % Store singularity types. - data.singType = args{2}; - args(1:2) = []; - elseif ( strcmpi(args{1}, 'exps') ) - % Store exponents. - data.exponents = args{2}; - args(1:2) = []; - elseif ( any(strcmpi(args{1}, 'chebkind')) ) - % Translate "chebkind" and "kind" --> "tech.@chebtech". - if ( (isnumeric(args{2}) && (args{2} == 1)) || ... - (ischar(args{2}) && strncmpi(args{2}, '1st', 1)) ) - keywordPrefs.tech = @chebtech1; - elseif ( (isnumeric(args{2}) && (args{2} == 2)) || ... - (ischar(args{2}) && strncmpi(args{2}, '2nd', 1)) ) - keywordPrefs.tech = @chebtech2; - else - error('CHEBFUN:CHEBFUN:parseInputs:badChebkind', ... - 'Invalid value for ''chebkind'' option.'); - end - args(1:2) = []; - elseif ( strcmpi(args{1}, 'resampling') ) - % Translate "resampling" --> "techPrefs.refinementFunction". - if ( strcmpi(args{2}, 'on') ) - keywordPrefs.techPrefs.refinementFunction = 'resampling'; - elseif ( strcmpi(args{2}, 'off') ) - keywordPrefs.techPrefs.refinementFunction = 'nested'; - end - args(1:2) = []; - elseif ( strcmpi(args{1}, 'maxdegree') ) - % Translate "maxdegree" --> "techPrefs.maxLength". - keywordPrefs.techPrefs.maxLength = args{2}; - args(1:2) = []; - elseif ( any(strcmpi(args{1}, {'splitLength', 'splitdegree'})) ) - % Translate "splitdegree" --> "splitPrefs.splitLength". - keywordPrefs.splitPrefs.splitLength = args{2}; - args(1:2) = []; - elseif ( strcmpi(args{1}, 'splitMaxLength') ) - % Translate "splitMaxLength" --> "splitPrefs.splitMaxLength". - keywordPrefs.splitPrefs.splitMaxLength = args{2}; - args(1:2) = []; - elseif ( ischar(args{1}) ) - % Update these preferences: - if ( length(args) < 2 ) - error('CHEBFUN:CHEBFUN:parseInputs:noPrefValue', ... - ['Value for ''' args{1} ''' preference was not supplied.']); - end - keywordPrefs.(args{1}) = args{2}; - args(1:2) = []; - else - if ( isnumeric(args{1}) ) - error('CHEBFUN:CHEBFUN:parseInputs:badInputNumeric', ... - ['Could not parse input argument sequence.\n' ... - '(Perhaps the construction domain is not the second ' ... - 'argument?)']); - else - error('CHEBFUN:CHEBFUN:parseInputs:badInput', ... - 'Could not parse input argument sequence.'); - end - end - end - - % Override preferences supplied via a preference object with those supplied - % via keyword. - if ( prefWasPassed ) - pref = chebfunpref(pref, keywordPrefs); - else - pref = chebfunpref(keywordPrefs); - end - - % Use the domain of the chebfun that was passed if none was supplied. - if ( ~domainWasPassed || isempty(dom) ) - if ( isa(op, 'chebfun') ) - dom = [ op.domain(1) op.domain(end) ]; - else - dom = pref.domain; - end - end - numIntervals = numel(dom) - 1; - - % Deal with the 'periodic' or 'trig' flag: - if ( isPeriodic ) - % Translate 'periodic' or 'trig'. - pref.tech = @trigtech; - pref.splitting = false; - if ( numel(dom) > 2 ) - error('CHEBFUN:parseInputs:periodic', ... - '''periodic'' or ''trig'' option is only supported for smooth domains.'); - end - end - - % Parse the OP (handle the vectorize flag, etc.). - if ( iscell(op) ) - for k = 1:numel(op) - op{k} = parseOp(op{k}); - end - else - op = parseOp(op); - end - - function op = parseOp(op) - % Convert string input to function_handle: - if ( ischar(op) ) - op = str2op(op); - end - if ( doVectorCheck && isa(op, 'function_handle') ) - op = vectorCheck(op, dom, vectorize); - end - if ( isa(op, 'chebfun') ) - op = @(x) feval(op, x); - end - if ( isa(op, 'function_handle') && strcmp(pref.tech, 'funqui') ) - if ( isfield(pref.techPrefs, 'fixedLength') && ... - ~isnan(pref.techPrefs.fixedLength) ) - x = linspace(dom(1), dom(end), pref.techPrefs.fixedLength).'; - op = feval(op, x); - pref.techPrefs.fixedLength = NaN; - end - end - end - - % Enable singularity detection if we have exponents or singTypes: - if ( any(data.exponents) || ~isempty(data.singType) ) - pref.blowup = true; - end - % Sort out the singularity types: - if ( numel(data.singType) == 1 ) - singType = data.singType{1}; - data.singType = cell(1, 2*numIntervals); - for j = 1:2*numIntervals - data.singType{j} = singType; - end - elseif ( ~isempty(data.singType) && ... - (numel(data.singType) ~= 2*numIntervals) ) - % If the number of exponents supplied by user isn't equal to twice the - % the number of the FUNs, throw an error message: - error('CHEBFUN:CHEBFUN:parseInputs:badExponents', ... - 'The number of the exponents is inappropriate.'); - end - % Sort out the exponents: - if ( ~isempty(data.exponents) ) - exps = data.exponents; - nExps = numel(exps); - if ( nExps == 1 ) - % If only one exponent is supplied, assume the exponent at other - % breakpoints are exactly same. - exps = exps*ones(1, 2*numIntervals); - elseif ( nExps == 2 ) - % If the exponents are only supplied at endpoints of the entire - % domain, then pad zeros at the interior breakpoints. - exps = [exps(1) zeros(1, 2*(numIntervals-1)) exps(2)]; - elseif ( nExps == numIntervals + 1 ) - % If only one exponent is supplied for each interior breakpoint, - % then we assume that the singularity take the same order on each - % side. - exps = exps(ceil(1:0.5:nExps - 0.5)); - elseif( nExps ~= 2*numIntervals ) - % The number of exponents supplied by user makes no sense. - error('CHEBFUN:CHEBFUN:chebfun:parseInputs', ... - 'Invalid length for vector of exponents.'); - end - data.exponents = exps; - end - - % Ensure DOM is a double (i.e., not a domain object). - dom = double(dom); - -end - -function op = vectorCheck(op, dom, vectorize) -%VECTORCHECK Try to determine whether op is vectorized. -% It's impossible to cover all eventualities without being too expensive. -% We do the best we can. "Do. Or do no. There is not try." - -% Make a slightly narrower domain to evaluate on. (Endpoints can be tricky). -y = dom([1 end]); - -if ( y(1) > 0 ) - y(1) = 1.01*y(1); -else - y(1) = .99*y(1); -end - -if ( y(end) > 0 ) - y(end) = .99*y(end); -else - y(end) = 1.01*y(end); -end - -y = y(:); - -if ( vectorize ) - op = vec(op, y(1)); -end - -try - % Evaluate a vector of (near the) endpoints - v = op(y); - - % Get the size of the output: - sv = size(v); - sy = size(y); - - % Check the sizes: - if ( sv(1) == sy(1) ) - % Here things seem OK! - - % However, we may possibly be fooled if we have an array-valued function - % whose number of columns equals the number of test points(i.e., 2). We - % choose one additional point as a final check: - if ( sv(2) == sy(1) ) - v = op(y(1)); - if ( size(v, 1) > 1 ) - op = @(x) op(x).'; - warning('CHEBFUN:CHEBFUN:vectorCheck:transpose',... - ['Chebfun input should return a COLUMN array.\n', ... - 'Attempting to transpose.']) - end - end - - elseif ( all( sv == 1 ) ) - % The operator always returns a scalar: - op = @(x) repmat(op(x), length(x), 1); - - elseif ( any(sv == sy(1)) ) - - if ( any(sv) == 1 ) - % We check to see if we have something like @(x) [1 1]. - v = op(y(1)); % Should evaluate to a scalar, unless array-valued. - if ( all(size(v) == sv) ) - % Scalar expand: - op = @(x) repmat(op(x), length(x), 1); - return - end - end - - % Try and transpose: - op = @(x) op(x).'; - warning('CHEBFUN:CHEBFUN:vectorCheck:transpose',... - ['Chebfun input should return a COLUMN array.\n', ... - 'Attempting to transpose.']) - - elseif ( any(sv == 1) ) - % The operator always returns a scalar: - op = @(x) repmat(op(x), length(x), 1); - - end - -catch ME - % The above didn't work. :( - - if ( vectorize ) - % We've already tried vectorizing, so we've failed. - rethrow(ME) - - else - % Try vectorizing. - op = vectorCheck(op, dom, 1); - warning('CHEBFUN:CHEBFUN:vectorcheck:vectorize',... - ['Function failed to evaluate on array inputs.\n',... - 'Vectorizing the function may speed up its evaluation\n',... - 'and avoid the need to loop over array elements.\n',... - 'Use ''vectorize'' flag in the CHEBFUN constructor call\n', ... - 'to avoid this warning message.']) - - end - -end - -end - -function g = vec(op, y) -%VEC Vectorize a function or string expression. -% VEC(OP, Y), if OP is a function handle or anonymous function, returns a -% function that returns vector outputs for vector inputs by wrapping F inside -% a loop. Y, serving as a testing point, is a point in the domain where OP is -% defined and is used to determine if OP is array-valued or not. - - % Check to see if OP is array-valued: - opy = op(y); - if ( any(size(opy) > 1) ) - % Use the array-valued wrapper: - g = @loopWrapperArray; - else - % It's not array-valued. Use the scalar wrapper: - g = @loopWrapperScalar; - end - - % Nested functions: - - % Scalar case: - function v = loopWrapperScalar(x) - v = zeros(size(x)); - for j = 1:numel(v) - v(j) = op(x(j)); - end - end - - % Array-valued case: - function v = loopWrapperArray(x) - numCol = size(op(x(1)), 2); - numRow = size(x, 1); - v = zeros(numRow, numCol); - for j = 1:numRow - v(j,:) = op(x(j)); - end - end - +% Example source code copied from the Chebfun project on GitHub: +% https://github.com/chebfun/chebfun/blob/development/@chebfun/chebfun.m + +classdef chebfun +%CHEBFUN CHEBFUN class for representing functions on [a,b]. +% +% Class for approximating functions defined on finite, semi-infinite, or +% doubly-infinite intervals [a,b]. Functions may be smooth, piecewise smooth, +% weakly singular, or blow up on the interval. +% +% CHEBFUN(F) constructs a CHEBFUN object representing the function F on the +% interval [-1,1]. F may be a string, e.g., 'sin(x)', a function handle, e.g., +% @(x) x.^2 + 2*x + 1, or a vector of numbers. In the first two instances, F +% should be "vectorized" in the sense that it may be evaluated at a column +% vector of points x(:) in [-1,1] and return an output of size NxM where N = +% length(x(:)). If this is not possible then the flag CHEBFUN(F, 'vectorize') +% should be passed. CHEBFUN(F, 'vectorcheck', 'off') disables the automatic +% checking for vector input. Additionally, F may be a CHEBFUN, in which case +% CHEBFUN(F) is equivalent to CHEBFUN(@(X) FEVAL(F, X)). CHEBFUN() returns an +% empty CHEBFUN object. +% +% CHEBFUN(F, [A, B]) specifies an interval [A,B] on which the CHEBFUN is +% defined, where A and/or B may be infinite. CHEBFUN(F, ENDS), where ENDS is a +% 1x(K+1) vector of unique ascending values, specifies a piecewise smooth +% CHEBFUN defined on the interval [ENDS(1), ENDS(K+1)] with additional interior +% breaks at ENDS(2), ..., ENDS(K). Specifying these breaks can be particularly +% useful if F is known to have discontinuities. For example, +% CHEBFUN(@(x) abs(x), [-1, 0, 1]). +% If a domain is passed to the constructor, it should always be the 2nd input. +% +% CHEBFUN(A) or CHEBFUN(A, 'chebkind', 2), where A is an Nx1 matrix, constructs +% a CHEBFUN object which interpolates the data in A on an N-point Chebyshev grid +% of the second kind (see >> help chebpts). CHEBFUN(A, 'chebkind', 1) and +% CHEBFUN(A, 'equi') are similar, but here the data is assumed to come from a +% 1st-kind Chebyshev or equispaced grid linspace(-1, 1, N), respectively. (In +% the latter case, a smooth interpolant is constructed using an adaptive +% Floater-Hormann scheme [Numer. Math. 107, 315-331 (2007)].). CHEBFUN(F, N) or +% CHEBFUN(F, N, 'chebkind', 2) is equivalent to CHEBFUN(feval(F, chebpts(N)). +% +% CHEBFUN(C, 'coeffs'), where C is an Nx1 matrix, constructs a CHEBFUN object +% representing the polynomial C(1) T_0(x) + ... + C(N) T_(N-1)(x), +% where T_K(x) denotes the K-th Chebyshev polynomial. This is equivalent to +% CHEBFUN({{[], C}}). C may also be an NxM matrix, as described below. +% +% CHEBFUN(F, ...), where F is an NxM matrix or an array-valued function handle, +% returns an "array-valued" CHEBFUN. For example, +% CHEBFUN(rand(14, 2)) +% or +% CHEBFUN(@(x) [sin(x), cos(x)]) +% Note that each column in an array-valued CHEBFUN object is discretized in the +% same way (i.e., the same breakpoint locations and the same underlying +% representation). For more details see ">> help quasimatrix". Note the +% difference between +% CHEBFUN(@(x) [sin(x), cos(x)], [-1, 0, 1]) +% and +% CHEBFUN({@(x) sin(x), @(x) cos(x)}, [-1, 0, 1]). +% The former constructs an array-valued CHEBFUN with both columns defined on the +% domain [-1, 0, 1]. The latter defines a single column CHEBFUN which represents +% sin(x) in the interval [-1, 0) and cos(x) on the interval (0, 1]. +% +% CHEBFUN({F1,...,Fk}, ENDS) constructs a piecewise smooth CHEBFUN which +% represents Fj on the interval [ENDS(j), END(j+1)]. Each entry Fj may be a +% string, function handle, or vector of doubles. For example +% CHEBFUN({@(x) sin(x), @(x) cos(x)}, [-1, 0, 1]) +% +% CHEBFUN(F, PREF) or CHEBFUN(F, [A, B], PREF) constructs a CHEBFUN object from +% F with the options determined by the CHEBFUNPREF object PREF. Construction +% time options may also be passed directly to the constructor in the form +% CHEBFUN(F, [A, B], PROP1, VAL1, PROP2, VAL2, ...). (See CHEBFUNPREF for +% details of the various preference options and their defaults.). In +% particular, CHEBFUN(F, 'splitting', 'on') allows the constructor to +% adaptively determine breakpoints to better represent piecewise smooth +% functions F. For example, +% CHEBFUN(@(x) sign(x - .3), [-1, 1], 'splitting', 'on') +% CHEBFUN(F, 'extrapolate', 'on') prevents the constructor from evaluating the +% function F at the endpoints of the domain. +% +% If PROP/VAL and PREF inputs are mixed in a single constructor call, the +% preferences determined by the PROP/VAL inputs take priority over those +% determined by PREF. At most one PREF input may be supplied to the +% constructor at any time. +% +% CHEBFUN(F, 'trunc', N) returns a smooth N-point CHEBFUN constructed by +% computing the first N Chebyshev coefficients from their integral form, rather +% than by interpolation at Chebyshev points. +% +% CHEBFUN(F, 'trig') constructs a CHEBFUN object representing a smooth and +% periodic function F on the interval [-1,1]. The resulting CHEBFUN is +% represented using a Fourier series. All operations done on F should preserve +% smoothness and periodicity, otherwise results are casted into chebfuns +% represented by Chebyshev rather than Fourier series. Similar options +% as discussed above may be combined with the 'trig' flag, with exception to +% the 'chebkind' and 'splitting' flags. +% +% CHEBFUN(F, 'periodic') is the same as CHEBFUN(F, 'trig'). +% +% CHEBFUN --UPDATE can be used to update to the latest stable release of CHEBFUN +% (obviously an internet connection is required!). CHEBFUN --UPDATE-DEVEL will +% update to the latest development release, but we recommend instead that you +% checkout from the Github repo https://github.com/chebfun/chebfun/. See +% CHEBFUN.UPDATE() for further details. +% +% See also CHEBFUNPREF, CHEBPTS. + +% Copyright 2014 by The University of Oxford and The Chebfun Developers. +% See http://www.chebfun.org/ for Chebfun information. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% CHEBFUN Class Description: +% +% The CHEBFUN class is for representations of piecewise functions on the +% interval [a,b]. +% +% The CHEBFUN class is the main user interface. We do not expect users to +% directly invoke any objects below this level. +% +% A CHEBFUN object consists of a collection of FUN objects. There are two main +% tasks for the CHEBFUN constructor: (1) parse the user input, and (2) correctly +% piece together FUN objects to form a global approximation. If the input +% function is globally smooth then the resulting CHEBFUN contains a single FUN +% object. If the input is not smooth, or breakpoints are passed to the +% constructor, CHEBFUN must determine appropriate breakpoints and return a +% piecewise smooth CHEBFUN with multiple FUN objects. +% +% This is a user-level class, and all input arguments should be thoroughly +% sanity checked. +% +% Class diagram: [ADchebfun] <>-- [CHEBFUN] <>-- [<>] +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %% CLASS PROPERTIES: + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + properties (Access = public) + % DOMAIN of definition of a CHEBFUN object. If K = length(F.DOMAIN) is + % greater than 1 then the CHEBFUN is referred to as a "piecewise". + % CHEBFUN. The first and last values of this vector define the left and + % right endpoints of the domain, respectively. The other values give the + % locations of the interior breakpoints that define the domains of the + % individual FUN objects comprising the CHEBFUN. The entries in this + % vector should be strictly increasing. + domain % (1x(K+1) double) + + % FUNS is a cell array containing the FUN objects that comprise a + % piecewise CHEBFUN. The kth entry in this cell is the FUN defining + % the representation used by the CHEBFUN object on the open interval + % (F.DOMAIN(k), F.DOMAIN(k+1)). If M = size(f.funs, 2) is greater than + % 1, then the CHEBFUN object is referred to as "array valued". + funs % (Kx1 cell array of FUN objects) + + % POINTVALUES Values of the function at the break points. + pointValues = []; % (1 x (K+1) double) + + % ISTRANSPOSED determines whether a (possibly array-valued) CHEBFUN F + % should be interpreted as a collection of "column" CHEBFUN objects (if + % F.ISTRANSPOSED == 0, the default), which are considered (infxM) + % arrays, or "row" CHEBFUN objects (if F.ISTRANSPOSED == 1), which are + % (Mxinf) arrays. This difference is only behavioral; the other + % properties described above are _NOT_ stored differently if this flag + % is set.) + isTransposed = 0; % (logical) + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %% CLASS CONSTRUCTOR: + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + methods ( Access = public, Static = false ) + + function f = chebfun(varargin) + % The main CHEBFUN constructor! + + % Return an empty CHEBFUN: + if ( (nargin == 0) || isempty(varargin{1}) ) + return + end + + if ( iscell(varargin{1}) && ... + all(cellfun(@(x) isa(x, 'fun'), varargin{1})) ) + % Construct a CHEBFUN from a cell array of FUN objects. + % Note, this is not affected by the input parser (see error + % message below) and must be _fast_ as it is done often. + if ( nargin > 1 ) + error('CHEBFUN:CHEBFUN:chebfun:nargin', ... + 'Only one input is allowed when passing an array of FUNs.') + end + % Assign the cell to the .FUNS property: + f.funs = varargin{1}; + % Collect the domains together: + dom = cellfun(@(fun) get(fun, 'domain'), f.funs, ... + 'uniformOutput', false); + f.domain = unique([dom{:}]); + % Update values at breakpoints (first row of f.pointValues): + f.pointValues = chebfun.getValuesAtBreakpoints(f.funs, f.domain); + return + end + + % Parse inputs: + [op, dom, data, pref] = parseInputs(varargin{:}); + + if ( strcmp(op, 'done') ) + % An update was performed. Exit gracefully: + throwAsCaller(MException('', '')) + end + + % Deal with 'trunc' option: + doTrunc = false; + truncLength = NaN; + for k = 1:length(varargin) + if ( strcmpi(varargin{k}, 'trunc') ) + doTrunc = true; + truncLength = varargin{k+1}; + break + end + end + + if ( isa(op, 'chebfun') && doTrunc ) + % Deal with the particular case when we're asked to truncate a + % CHEBFUN: + f = op; + + else + % Construct from function_handle, numeric, or string input: + + % Call the main constructor: + [f.funs, f.domain] = chebfun.constructor(op, dom, data, pref); + + % Update values at breakpoints (first row of f.pointValues): + f.pointValues = chebfun.getValuesAtBreakpoints(f.funs, ... + f.domain, op); + + % Remove unnecessary breaks (but not those that were given): + [ignored, index] = setdiff(f.domain, dom); + f = merge(f, index(:).', pref); + + end + + if ( doTrunc ) + % Truncate the CHEBFUN to the required length: + if ( isa( pref.tech(),'chebtech' ) ) + c = chebcoeffs(f, truncLength); + else + c = trigcoeffs(f, truncLength); + end + f = chebfun(c, f.domain([1,end]), 'coeffs', pref); + end + + end + + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %% CLASS METHODS: + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + methods ( Access = public, Static = false ) + + % Absolute value of a CHEBFUN. + f = abs(f, pref) + + % True if any element of a CHEBFUN is a nonzero number, ignoring NaN. + a = any(f, dim) + + % Compute the length of the arc defined by a CHEBFUN. + out = arcLength(f, a, b) + + % Solve boundary value problems for ODEs by collocation. + [y, t] = bvp4c(fun1, fun2, y0, varargin); + + % Solve boundary value problems for ODEs by collocation. + [y, t] = bvp5c(fun1, fun2, y0, varargin); + + % Round a CHEBFUN towards plus infinity. + g = ceil(f) + + % Plot information regarding the representation of a CHEBFUN object: + h = plotcoeffs(f, varargin); + + % Construct complex CHEBFUN from real and imaginary parts. + C = complex(A, B) + + % Compose CHEBFUN objects with another function. + h = compose(f, op, g, pref) + + % Complex conjugate of a CHEBFUN. + f = conj(f) + + % Complex transpose of a CHEBFUN. + f = ctranspose(f) + + % Display a CHEBFUN object. + display(f); + + % Accuracy estimate of a CHEBFUN object. + out = epslevel(f, flag); + + % Evaluate a CHEBFUN. + y = feval(f, x, varargin) + + % Round a CHEBFUN towards zero. + g = fix(f); + + % Round a CHEBFUN towards minus infinity. + g = floor(f); + + % Get properties of a CHEBFUN object. + out = get(f, prop, simpLevel); + + % Horizontal scale of a CHEBFUN object. + out = hscale(f); + + % Imaginary part of a CHEBFUN. + f = imag(f) + + % True for an empty CHEBFUN. + out = isempty(f) + + % Test if CHEBFUN objects are equal. + out = isequal(f, g) + + % Test if a CHEBFUN is bounded. + out = isfinite(f) + + % Test if a CHEBFUN is unbounded. + out = isinf(f) + + % Test if a CHEBFUN has any NaN values. + out = isnan(f) + + % True for real CHEBFUN. + out = isreal(f); + + % Test if a CHEBFUN object is built upon DELTAFUN. + out = isdelta(f); + + % Test if a CHEBFUN object is built upon SINGFUN. + out = issing(f) + + % Test if a CHEBFUN object is built upon a basis of periodic + % functions, i.e., a periodic TECH. + out = isPeriodicTech(f) + + % True for zero CHEBFUN objects. + out = iszero(f) + + % Kronecker product of two CHEBFUN object. + out = kron(f, g) + + % Length of a CHEBFUN. + [out, out2] = length(f); + + % Return Legendre coefficients of a CHEBFUN. + c_leg = legpoly(f, n) + + % Plot a CHEBFUN object on a loglog scale: + h = loglog(f, varargin); + + % Subtraction of two CHEBFUN objects. + f = minus(f, g) + + % Multiplication of CHEBFUN objects. + f = mtimes(f, c) + + % Remove unnecessary breakpoints in from a CHEBFUN. + [f, mergedPts] = merge(f, index, pref) + + % Overlap the domain of two CHEBFUN objects. + [f, g] = overlap(f, g) + + % Plot a CHEBFUN object: + varargout = plot(f, varargin); + + % 3-D plot for CHEBFUN objects. + varargout = plot3(f, g, h, varargin) + + % Power of a CHEBFUN + f = power(f, b, pref); + + % Real part of a CHEBFUN. + f = real(f) + + % Restrict a CHEBFUN object to a subdomain. + f = restrict(f, newDomain); + + % The roots of the CHEBFUN F. + r = roots(f, varargin); + + % Round a CHEBFUN towards nearest integer. + g = round(f) + + % Plot a CHEBFUN object on a log-linear scale: + h = semilogx(f, varargin); + + % Plot a CHEBFUN object on a linear-log scale: + h = semilogy(f, varargin); + + % Signum of a CHEBFUN. + f = sign(f, pref) + + % Simplify the representation of a CHEBFUN object. + f = simplify(f, tol); + + % Size of a CHEBFUN object. + [s1, s2] = size(f, dim); + + % Square root of a CHEBFUN. + f = sqrt(f, pref) + + % Retrieve and modify preferences for this class. + varargout = subsref(f, index); + + % Retrieve and modify preferences for this class. + varargout = subsasgn(f, varargin); + + % CHEBFUN multiplication. + f = times(f, g, varargin) + + % Transpose a CHEBFUN. + f = transpose(f) + + % Unary minus of a CHEBFUN. + f = uminus(f) + + % Unary plus of a CHEBFUN. + f = uplus(f) + + % Vertical scale of a CHEBFUN object. + out = vscale(f, s); + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %% HIDDEN METHODS: + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + methods ( Hidden = true, Static = false ) + + % Add breakpoints to the domain of a CHEBFUN. + f = addBreaks(f, breaks, tol) + + % Add breaks at appropriate roots of a CHEBFUN. + f = addBreaksAtRoots(f, tol) + + % Assign columns (or rows) of an array-valued CHEBFUN. + f = assignColumns(f, colIdx, g) + + % Convert a CHEBFUN to another TECH. + f = changeTech(f, newtech); + + % Deprecated function. + f = define(f,s,v); + + % Supply a new definition for a CHEBFUN on a subinterval. + f = defineInterval(f, subInt, g) + + % Supply new definition for a CHEBFUN at a point or set of points. + f = definePoint(f, s, v) + + % Multiplication operator. + M = diag(f) + + % Useful information for DISPLAY. + [name, data] = dispData(f) + + % Compare domains of two CHEBFUN objects. + pass = domainCheck(f, g); + + % Extract columns of an array-valued CHEBFUN object. + f = extractColumns(f, columnIndex); + + % Deprecated function. + varargin = fzero(varargout); + + % Get Delta functions within a CHEBFUN. + [deltaMag, deltLoc] = getDeltaFunctions(f); + + % Get roots of a CHEBFUN and polish for use as breakpoints. + [rBreaks, rAll] = getRootsForBreaks(f, tol) + + % Returns true if numel(f) > 1 + out = isQuasi(f) + + % Number of columns (or rows) of a CHEBFUN quasimatrix. + out = numColumns(f) + + % Obtain data used for plotting a CHEBFUN object: + data = plotData(f, g, h) + + % Deprecated function. + varargin = quad(varargout); + + % Set pointValues property: + f = setPointValues(f, j, k, vals) + + % Remove all-zero layers of higher-order impulses. + f = tidyImpulses(f) + + % Adjust nearby common break points in domains of CHEBFUN objects. + [f, g, newBreaksLocF, newBreaksLocG] = tweakDomain(f, g, tol, pos) + + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %% PRIVATE METHODS: + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + methods ( Access = private, Static = false ) + % Set small breakpoint values to zero. + f = thresholdBreakpointValues(f); + end + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %% STATIC METHODS: + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + methods ( Access = public, Static = true ) + + % Discrete cosine transform: + y = dct(u, kind); + + % Inverse discrete cosine transform: + u = idct(y, kind); + + % Discrete sine transform: + y = dst(u, kind); + + % Inverse discrete sine transform: + u = idst(y, kind); + + % Interpolate data: + f = interp1(x, y, method, dom); + + % Compute Lagrange basis functions for a given set of points. + f = lagrange(x, varargin); + + % ODE113 with CHEBFUN output. + [t, y] = ode113(varargin); + + % ODE15S with CHEBFUN output. + [t, y] = ode15s(varargin); + + % ODE45 with CHEBFUN output. + [t, y] = ode45(varargin); + + % Cubic Hermite interpolation: + f = pchip(x, y, method); + + % Cubic spline interpolant: + f = spline(x, y, d); + + % Update Chebfun source files: + update(varargin) + + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %% HIDDEN STATIC METHODS: + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + methods ( Hidden = true, Static = true ) + + % Convert a cell array of CHEBFUN objects to a quasimatrix. + G = cell2quasi(F) + + % Determine values of CHEBFUN at breakpoints. + vals = getValuesAtBreakpoints(funs, ends, op); + + % Which interval is a point in? + out = whichInterval(dom, x, direction); + + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %% PRIVATE STATIC METHODS: + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + methods ( Access = private, Static = true ) + + % Main constructor. + [funs, ends] = constructor(op, domain, data, pref); + + % Convert ODE solutions into CHEBFUN objects: + [y, t] = odesol(sol, dom, opt); + + % Parse inputs to PLOT. Extract 'lineWidth', etc. + [lineStyle, pointStyle, jumpStyle, deltaStyle, out] = ... + parsePlotStyle(varargin) + + end + +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Class-related functions: private utilities for this m-file. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function op = str2op(op) + % Convert string inputs to either numeric format or function_handles. + sop = str2num(op); %#ok % STR2DOUBLE doesn't support str2double('pi') + if ( ~isempty(sop) ) + op = sop; + else + depVar = symvar(op); + if ( numel(depVar) ~= 1 ) + error('CHEBFUN:CHEBFUN:str2op:indepvars', ... + 'Incorrect number of independent variables in string input.'); + end + op = eval(['@(' depVar{:} ')', op]); + end +end + +function [op, dom, data, pref] = parseInputs(op, varargin) + + % TODO: Should we 'data' structure to be passed to the constructor? + % Currently, like in CHEBFUN/COMPOSE(), we don't have a use for this, but it + % might be useful in the future. + + % Deal with string input options. + if ( strncmp(op, '--', 2) ) + % An option has been passed to the constructor. + if ( strcmpi(op, '--update') ) + chebfun.update(); + elseif ( strcmpi(op, '--update-devel') ) + chebfun.update('development'); + elseif ( strcmpi(op, '--version') ) + installDir = chebfunroot(); + fid = fopen(fullfile(installDir, 'Contents.m'), 'r'); + fgetl(fid); + str = fgetl(fid); + disp(['Chebfun ', str(3:end)]); + fclose(fid); + else + error('CHEBFUN:parseInputs:unknown', ... + 'Unknow command %s.', op); + end + op = 'done'; + dom = []; + data = struct(); + pref = []; + return + end + + % Initialize data output. + data.hscale = []; + data.vscale = []; + data.exponents = []; + data.singType = []; + + args = varargin; + + % An op-only constructor call. + if ( nargin == 1 ) + pref = chebfunpref(); + end + + % Try to parse out the domain which, if passed, is the second argument. + domainWasPassed = false; + if ( ~isempty(args) ) + if ( isnumeric(args{1}) && ... + ((length(args{1}) >= 2) || isempty(args{1})) ) + dom = args{1}; + args(1) = []; + domainWasPassed = true; + elseif ( isa(args{1}, 'domain') ) + dom = double(args{1}); + args(1) = []; + domainWasPassed = true; + end + end + + % A struct to hold any preferences supplied by keyword (name-value pair). + keywordPrefs = struct(); + + % Parse the remaining arguments. + prefWasPassed = false; + isPeriodic = false; + vectorize = false; + doVectorCheck = true; + while ( ~isempty(args) ) + if ( isstruct(args{1}) || isa(args{1}, 'chebfunpref') ) + % Preference object input. (Struct inputs not tied to a keyword + % are interpreted as preference objects.) + if ( ~prefWasPassed ) + pref = chebfunpref(args{1}); + prefWasPassed = true; + args(1) = []; + else + error('CHEBFUN:CHEBFUN:parseInputs:twoPrefs', ... + 'Multiple preference inputs are not allowed.'); + end + elseif ( strcmpi(args{1}, 'equi') ) + % Enable FUNQUI when dealing with equispaced data. + keywordPrefs.tech = 'funqui'; + args(1) = []; + elseif ( strcmpi(args{1}, 'vectorize') || ... + strcmpi(args{1}, 'vectorise') ) + % Vectorize flag for function_handles. + vectorize = true; + args(1) = []; + elseif ( strcmpi(args{1}, 'novectorcheck') ) + % Vector check for function_handles. + doVectorCheck = false; + args(1) = []; + elseif ( strcmpi(args{1}, 'coeffs') && isnumeric(op) ) + % Hack to support construction from coefficients. + op = {{[], op}}; + args(1) = []; + elseif ( any(strcmpi(args{1}, {'periodic', 'trig'})) ) + isPeriodic = true; + args(1) = []; + elseif ( strcmpi(args{1}, 'coeffs') && iscell(op) ) + error('CHEBFUN:CHEBFUN:parseInputs:coeffcell', ... + 'Cannot construct CHEBFUN from a cell array of coefficients.'); + elseif ( strcmpi(args{1}, 'trunc') ) + % Pull out this preference, which is checked for later. + keywordPrefs.splitting = true; + args(1:2) = []; + elseif ( isnumeric(args{1}) && isscalar(args{1}) ) + % g = chebfun(@(x) f(x), N) + keywordPrefs.techPrefs.fixedLength = args{1}; + args(1) = []; + elseif ( strcmpi(args{1}, 'splitting') ) + keywordPrefs.splitting = strcmpi(args{2}, 'on'); + args(1:2) = []; + elseif ( strcmpi(args{1}, 'minsamples') ) + % Translate "minsamples" --> "techPrefs.minSamples". + keywordPrefs.techPrefs.minSamples = args{2}; + args(1:2) = []; + elseif ( strcmpi(args{1}, 'blowup') ) + if ( strcmpi(args{2}, 'off') ) + % If 'blowup' is 'off'. + keywordPrefs.blowup = 0; + else + % If 'blowup' is not 'off', set the singTypes. (NB: These + % cells really need to store a left and right singType for each + % domain subinterval, but we may not know the domain yet, so we + % store just one cell for now and replicate it later, after + % we've figured out the domain.) + if ( (isnumeric(args{2}) && args{2} == 1 ) || ... + strcmpi(args{2}, 'on') ) + % Translate "blowup" and flag "1" --> + % "blowup" and "poles only". + keywordPrefs.blowup = 1; + data.singType = {'pole'}; + elseif ( args{2} == 2 ) + % Translate "blowup" and flag "2" --> + % "blowup" and "fractional singularity". + keywordPrefs.blowup = 1; + data.singType = {'sing'}; + else + error('CHEBFUN:CHEBFUN:parseInputs:badBlowupOption', ... + 'Invalid value for ''blowup'' option.'); + end + end + args(1:2) = []; + elseif ( strcmpi(args{1}, 'vscale') ) + % Store vscale types. + data.vscale = args{2}; + args(1:2) = []; + elseif ( strcmpi(args{1}, 'hscale') ) + % Store vscale types. + data.vscale = args{2}; + args(1:2) = []; + elseif ( strcmpi(args{1}, 'singType') ) + % Store singularity types. + data.singType = args{2}; + args(1:2) = []; + elseif ( strcmpi(args{1}, 'exps') ) + % Store exponents. + data.exponents = args{2}; + args(1:2) = []; + elseif ( any(strcmpi(args{1}, 'chebkind')) ) + % Translate "chebkind" and "kind" --> "tech.@chebtech". + if ( (isnumeric(args{2}) && (args{2} == 1)) || ... + (ischar(args{2}) && strncmpi(args{2}, '1st', 1)) ) + keywordPrefs.tech = @chebtech1; + elseif ( (isnumeric(args{2}) && (args{2} == 2)) || ... + (ischar(args{2}) && strncmpi(args{2}, '2nd', 1)) ) + keywordPrefs.tech = @chebtech2; + else + error('CHEBFUN:CHEBFUN:parseInputs:badChebkind', ... + 'Invalid value for ''chebkind'' option.'); + end + args(1:2) = []; + elseif ( strcmpi(args{1}, 'resampling') ) + % Translate "resampling" --> "techPrefs.refinementFunction". + if ( strcmpi(args{2}, 'on') ) + keywordPrefs.techPrefs.refinementFunction = 'resampling'; + elseif ( strcmpi(args{2}, 'off') ) + keywordPrefs.techPrefs.refinementFunction = 'nested'; + end + args(1:2) = []; + elseif ( strcmpi(args{1}, 'maxdegree') ) + % Translate "maxdegree" --> "techPrefs.maxLength". + keywordPrefs.techPrefs.maxLength = args{2}; + args(1:2) = []; + elseif ( any(strcmpi(args{1}, {'splitLength', 'splitdegree'})) ) + % Translate "splitdegree" --> "splitPrefs.splitLength". + keywordPrefs.splitPrefs.splitLength = args{2}; + args(1:2) = []; + elseif ( strcmpi(args{1}, 'splitMaxLength') ) + % Translate "splitMaxLength" --> "splitPrefs.splitMaxLength". + keywordPrefs.splitPrefs.splitMaxLength = args{2}; + args(1:2) = []; + elseif ( ischar(args{1}) ) + % Update these preferences: + if ( length(args) < 2 ) + error('CHEBFUN:CHEBFUN:parseInputs:noPrefValue', ... + ['Value for ''' args{1} ''' preference was not supplied.']); + end + keywordPrefs.(args{1}) = args{2}; + args(1:2) = []; + else + if ( isnumeric(args{1}) ) + error('CHEBFUN:CHEBFUN:parseInputs:badInputNumeric', ... + ['Could not parse input argument sequence.\n' ... + '(Perhaps the construction domain is not the second ' ... + 'argument?)']); + else + error('CHEBFUN:CHEBFUN:parseInputs:badInput', ... + 'Could not parse input argument sequence.'); + end + end + end + + % Override preferences supplied via a preference object with those supplied + % via keyword. + if ( prefWasPassed ) + pref = chebfunpref(pref, keywordPrefs); + else + pref = chebfunpref(keywordPrefs); + end + + % Use the domain of the chebfun that was passed if none was supplied. + if ( ~domainWasPassed || isempty(dom) ) + if ( isa(op, 'chebfun') ) + dom = [ op.domain(1) op.domain(end) ]; + else + dom = pref.domain; + end + end + numIntervals = numel(dom) - 1; + + % Deal with the 'periodic' or 'trig' flag: + if ( isPeriodic ) + % Translate 'periodic' or 'trig'. + pref.tech = @trigtech; + pref.splitting = false; + if ( numel(dom) > 2 ) + error('CHEBFUN:parseInputs:periodic', ... + '''periodic'' or ''trig'' option is only supported for smooth domains.'); + end + end + + % Parse the OP (handle the vectorize flag, etc.). + if ( iscell(op) ) + for k = 1:numel(op) + op{k} = parseOp(op{k}); + end + else + op = parseOp(op); + end + + function op = parseOp(op) + % Convert string input to function_handle: + if ( ischar(op) ) + op = str2op(op); + end + if ( doVectorCheck && isa(op, 'function_handle') ) + op = vectorCheck(op, dom, vectorize); + end + if ( isa(op, 'chebfun') ) + op = @(x) feval(op, x); + end + if ( isa(op, 'function_handle') && strcmp(pref.tech, 'funqui') ) + if ( isfield(pref.techPrefs, 'fixedLength') && ... + ~isnan(pref.techPrefs.fixedLength) ) + x = linspace(dom(1), dom(end), pref.techPrefs.fixedLength).'; + op = feval(op, x); + pref.techPrefs.fixedLength = NaN; + end + end + end + + % Enable singularity detection if we have exponents or singTypes: + if ( any(data.exponents) || ~isempty(data.singType) ) + pref.blowup = true; + end + % Sort out the singularity types: + if ( numel(data.singType) == 1 ) + singType = data.singType{1}; + data.singType = cell(1, 2*numIntervals); + for j = 1:2*numIntervals + data.singType{j} = singType; + end + elseif ( ~isempty(data.singType) && ... + (numel(data.singType) ~= 2*numIntervals) ) + % If the number of exponents supplied by user isn't equal to twice the + % the number of the FUNs, throw an error message: + error('CHEBFUN:CHEBFUN:parseInputs:badExponents', ... + 'The number of the exponents is inappropriate.'); + end + % Sort out the exponents: + if ( ~isempty(data.exponents) ) + exps = data.exponents; + nExps = numel(exps); + if ( nExps == 1 ) + % If only one exponent is supplied, assume the exponent at other + % breakpoints are exactly same. + exps = exps*ones(1, 2*numIntervals); + elseif ( nExps == 2 ) + % If the exponents are only supplied at endpoints of the entire + % domain, then pad zeros at the interior breakpoints. + exps = [exps(1) zeros(1, 2*(numIntervals-1)) exps(2)]; + elseif ( nExps == numIntervals + 1 ) + % If only one exponent is supplied for each interior breakpoint, + % then we assume that the singularity take the same order on each + % side. + exps = exps(ceil(1:0.5:nExps - 0.5)); + elseif( nExps ~= 2*numIntervals ) + % The number of exponents supplied by user makes no sense. + error('CHEBFUN:CHEBFUN:chebfun:parseInputs', ... + 'Invalid length for vector of exponents.'); + end + data.exponents = exps; + end + + % Ensure DOM is a double (i.e., not a domain object). + dom = double(dom); + +end + +function op = vectorCheck(op, dom, vectorize) +%VECTORCHECK Try to determine whether op is vectorized. +% It's impossible to cover all eventualities without being too expensive. +% We do the best we can. "Do. Or do no. There is not try." + +% Make a slightly narrower domain to evaluate on. (Endpoints can be tricky). +y = dom([1 end]); + +if ( y(1) > 0 ) + y(1) = 1.01*y(1); +else + y(1) = .99*y(1); +end + +if ( y(end) > 0 ) + y(end) = .99*y(end); +else + y(end) = 1.01*y(end); +end + +y = y(:); + +if ( vectorize ) + op = vec(op, y(1)); +end + +try + % Evaluate a vector of (near the) endpoints + v = op(y); + + % Get the size of the output: + sv = size(v); + sy = size(y); + + % Check the sizes: + if ( sv(1) == sy(1) ) + % Here things seem OK! + + % However, we may possibly be fooled if we have an array-valued function + % whose number of columns equals the number of test points(i.e., 2). We + % choose one additional point as a final check: + if ( sv(2) == sy(1) ) + v = op(y(1)); + if ( size(v, 1) > 1 ) + op = @(x) op(x).'; + warning('CHEBFUN:CHEBFUN:vectorCheck:transpose',... + ['Chebfun input should return a COLUMN array.\n', ... + 'Attempting to transpose.']) + end + end + + elseif ( all( sv == 1 ) ) + % The operator always returns a scalar: + op = @(x) repmat(op(x), length(x), 1); + + elseif ( any(sv == sy(1)) ) + + if ( any(sv) == 1 ) + % We check to see if we have something like @(x) [1 1]. + v = op(y(1)); % Should evaluate to a scalar, unless array-valued. + if ( all(size(v) == sv) ) + % Scalar expand: + op = @(x) repmat(op(x), length(x), 1); + return + end + end + + % Try and transpose: + op = @(x) op(x).'; + warning('CHEBFUN:CHEBFUN:vectorCheck:transpose',... + ['Chebfun input should return a COLUMN array.\n', ... + 'Attempting to transpose.']) + + elseif ( any(sv == 1) ) + % The operator always returns a scalar: + op = @(x) repmat(op(x), length(x), 1); + + end + +catch ME + % The above didn't work. :( + + if ( vectorize ) + % We've already tried vectorizing, so we've failed. + rethrow(ME) + + else + % Try vectorizing. + op = vectorCheck(op, dom, 1); + warning('CHEBFUN:CHEBFUN:vectorcheck:vectorize',... + ['Function failed to evaluate on array inputs.\n',... + 'Vectorizing the function may speed up its evaluation\n',... + 'and avoid the need to loop over array elements.\n',... + 'Use ''vectorize'' flag in the CHEBFUN constructor call\n', ... + 'to avoid this warning message.']) + + end + +end + +end + +function g = vec(op, y) +%VEC Vectorize a function or string expression. +% VEC(OP, Y), if OP is a function handle or anonymous function, returns a +% function that returns vector outputs for vector inputs by wrapping F inside +% a loop. Y, serving as a testing point, is a point in the domain where OP is +% defined and is used to determine if OP is array-valued or not. + + % Check to see if OP is array-valued: + opy = op(y); + if ( any(size(opy) > 1) ) + % Use the array-valued wrapper: + g = @loopWrapperArray; + else + % It's not array-valued. Use the scalar wrapper: + g = @loopWrapperScalar; + end + + % Nested functions: + + % Scalar case: + function v = loopWrapperScalar(x) + v = zeros(size(x)); + for j = 1:numel(v) + v(j) = op(x(j)); + end + end + + % Array-valued case: + function v = loopWrapperArray(x) + numCol = size(op(x(1)), 2); + numRow = size(x, 1); + v = zeros(numRow, numCol); + for j = 1:numRow + v(j,:) = op(x(j)); + end + end + end \ No newline at end of file diff --git a/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/InlinePragmaProcError.pls b/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/InlinePragmaProcError.pls index a362cfe50c..93985c6909 100644 --- a/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/InlinePragmaProcError.pls +++ b/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/InlinePragmaProcError.pls @@ -1,17 +1,17 @@ -create or replace package inline_praqma_error is - -end; -/ - -create or replace package body inline_praqma_error is - procedure do_transaction(p_input_token in varchar(200)) is - - begin - PRAGMA AUTONOMOUS_TRANSACTION; - bno74.log_hentglass_request(p_hentglass_request - ,v_logging_req_seq_no); - COMMIT; - end do_transaction; - -end inline_praqma_error; -/ +create or replace package inline_praqma_error is + +end; +/ + +create or replace package body inline_praqma_error is + procedure do_transaction(p_input_token in varchar(200)) is + + begin + PRAGMA AUTONOMOUS_TRANSACTION; + bno74.log_hentglass_request(p_hentglass_request + ,v_logging_req_seq_no); + COMMIT; + end do_transaction; + +end inline_praqma_error; +/ diff --git a/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/IsOfType.pls b/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/IsOfType.pls index c536a73f45..6806a04214 100644 --- a/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/IsOfType.pls +++ b/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/IsOfType.pls @@ -1,23 +1,23 @@ -PROCEDURE IsOfType ( -inChannelID IN number, -inOperID IN number, -inClientId IN number, -ioFPOobj IN FPO_OBJ, -inPackageIDout IN number, -inStatusId IN number) -is -loFPOGE_OBJ FPOGE_OBJ; -BEGIN - -IF ioFPOobj IS OF (FPOGE_OBJ) THEN -loFPOGE_OBJ:=treat(ioFPOobj AS FPOGE_OBJ); -end if; - -IF ioFPOobj IS NOT OF TYPE (ONLY FPOGE_OBJ) THEN -loFPOGE_OBJ:=treat(ioFPOobj AS FPOGE_OBJ); -end if; - -loFPOGE_OBJ:=SELECT A FROM persons p WHERE IS OF TYPE (employee_t); -loFPOGE_OBJ:=SELECT A FROM persons p WHERE IS NOT OF TYPE (ONLY employee_t, other_t); - +PROCEDURE IsOfType ( +inChannelID IN number, +inOperID IN number, +inClientId IN number, +ioFPOobj IN FPO_OBJ, +inPackageIDout IN number, +inStatusId IN number) +is +loFPOGE_OBJ FPOGE_OBJ; +BEGIN + +IF ioFPOobj IS OF (FPOGE_OBJ) THEN +loFPOGE_OBJ:=treat(ioFPOobj AS FPOGE_OBJ); +end if; + +IF ioFPOobj IS NOT OF TYPE (ONLY FPOGE_OBJ) THEN +loFPOGE_OBJ:=treat(ioFPOobj AS FPOGE_OBJ); +end if; + +loFPOGE_OBJ:=SELECT A FROM persons p WHERE IS OF TYPE (employee_t); +loFPOGE_OBJ:=SELECT A FROM persons p WHERE IS NOT OF TYPE (ONLY employee_t, other_t); + end; \ No newline at end of file diff --git a/pmd-python/src/test/resources/net/sourceforge/pmd/cpd/sample-python.py b/pmd-python/src/test/resources/net/sourceforge/pmd/cpd/sample-python.py index 0c7abea4a6..89e8c5d440 100644 --- a/pmd-python/src/test/resources/net/sourceforge/pmd/cpd/sample-python.py +++ b/pmd-python/src/test/resources/net/sourceforge/pmd/cpd/sample-python.py @@ -1,279 +1,279 @@ -# Example source code copied from the Django project on GitHub -# https://github.com/django/django/blob/master/django/core/handlers/base.py -from __future__ import unicode_literals - -import logging -import sys -import types - -from django import http -from django.conf import settings -from django.core import urlresolvers -from django.core import signals -from django.core.exceptions import MiddlewareNotUsed, PermissionDenied, SuspiciousOperation -from django.db import connections, transaction -from django.http.multipartparser import MultiPartParserError -from django.utils.encoding import force_text -from django.utils.module_loading import import_string -from django.utils import six -from django.views import debug - -logger = logging.getLogger('django.request') - - -class BaseHandler(object): - # Changes that are always applied to a response (in this order). - response_fixes = [ - http.fix_location_header, - http.conditional_content_removal, - ] - - def __init__(self): - self._request_middleware = None - self._view_middleware = None - self._template_response_middleware = None - self._response_middleware = None - self._exception_middleware = None - - def load_middleware(self): - """ - Populate middleware lists from settings.MIDDLEWARE_CLASSES. - - Must be called after the environment is fixed (see __call__ in subclasses). - """ - self._view_middleware = [] - self._template_response_middleware = [] - self._response_middleware = [] - self._exception_middleware = [] - - request_middleware = [] - for middleware_path in settings.MIDDLEWARE_CLASSES: - mw_class = import_string(middleware_path) - try: - mw_instance = mw_class() - except MiddlewareNotUsed as exc: - if settings.DEBUG: - if six.text_type(exc): - logger.debug('MiddlewareNotUsed(%r): %s', middleware_path, exc) - else: - logger.debug('MiddlewareNotUsed: %r', middleware_path) - continue - - if hasattr(mw_instance, 'process_request'): - request_middleware.append(mw_instance.process_request) - if hasattr(mw_instance, 'process_view'): - self._view_middleware.append(mw_instance.process_view) - if hasattr(mw_instance, 'process_template_response'): - self._template_response_middleware.insert(0, mw_instance.process_template_response) - if hasattr(mw_instance, 'process_response'): - self._response_middleware.insert(0, mw_instance.process_response) - if hasattr(mw_instance, 'process_exception'): - self._exception_middleware.insert(0, mw_instance.process_exception) - - # We only assign to this when initialization is complete as it is used - # as a flag for initialization being complete. - self._request_middleware = request_middleware - - def make_view_atomic(self, view): - non_atomic_requests = getattr(view, '_non_atomic_requests', set()) - for db in connections.all(): - if (db.settings_dict['ATOMIC_REQUESTS'] - and db.alias not in non_atomic_requests): - view = transaction.atomic(using=db.alias)(view) - return view - - def get_exception_response(self, request, resolver, status_code): - try: - callback, param_dict = resolver.resolve_error_handler(status_code) - response = callback(request, **param_dict) - except: - signals.got_request_exception.send(sender=self.__class__, request=request) - response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) - - return response - - def get_response(self, request): - "Returns an HttpResponse object for the given HttpRequest" - - # Setup default url resolver for this thread, this code is outside - # the try/except so we don't get a spurious "unbound local - # variable" exception in the event an exception is raised before - # resolver is set - urlconf = settings.ROOT_URLCONF - urlresolvers.set_urlconf(urlconf) - resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) - try: - response = None - # Apply request middleware - for middleware_method in self._request_middleware: - response = middleware_method(request) - if response: - break - - if response is None: - if hasattr(request, 'urlconf'): - # Reset url resolver with a custom urlconf. - urlconf = request.urlconf - urlresolvers.set_urlconf(urlconf) - resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) - - resolver_match = resolver.resolve(request.path_info) - callback, callback_args, callback_kwargs = resolver_match - request.resolver_match = resolver_match - - # Apply view middleware - for middleware_method in self._view_middleware: - response = middleware_method(request, callback, callback_args, callback_kwargs) - if response: - break - - if response is None: - wrapped_callback = self.make_view_atomic(callback) - try: - response = wrapped_callback(request, *callback_args, **callback_kwargs) - except Exception as e: - # If the view raised an exception, run it through exception - # middleware, and if the exception middleware returns a - # response, use that. Otherwise, reraise the exception. - for middleware_method in self._exception_middleware: - response = middleware_method(request, e) - if response: - break - if response is None: - raise - - # Complain if the view returned None (a common error). - if response is None: - if isinstance(callback, types.FunctionType): # FBV - view_name = callback.__name__ - else: # CBV - view_name = callback.__class__.__name__ + '.__call__' - raise ValueError("The view %s.%s didn't return an HttpResponse object. It returned None instead." - % (callback.__module__, view_name)) - - # If the response supports deferred rendering, apply template - # response middleware and then render the response - if hasattr(response, 'render') and callable(response.render): - for middleware_method in self._template_response_middleware: - response = middleware_method(request, response) - # Complain if the template response middleware returned None (a common error). - if response is None: - raise ValueError( - "%s.process_template_response didn't return an " - "HttpResponse object. It returned None instead." - % (middleware_method.__self__.__class__.__name__)) - response = response.render() - - except http.Http404 as e: - logger.warning('Not Found: %s', request.path, - extra={ - 'status_code': 404, - 'request': request - }) - if settings.DEBUG: - response = debug.technical_404_response(request, e) - else: - response = self.get_exception_response(request, resolver, 404) - - except PermissionDenied: - logger.warning( - 'Forbidden (Permission denied): %s', request.path, - extra={ - 'status_code': 403, - 'request': request - }) - response = self.get_exception_response(request, resolver, 403) - - except MultiPartParserError: - logger.warning( - 'Bad request (Unable to parse request body): %s', request.path, - extra={ - 'status_code': 400, - 'request': request - }) - response = self.get_exception_response(request, resolver, 400) - - except SuspiciousOperation as e: - # The request logger receives events for any problematic request - # The security logger receives events for all SuspiciousOperations - security_logger = logging.getLogger('django.security.%s' % - e.__class__.__name__) - security_logger.error( - force_text(e), - extra={ - 'status_code': 400, - 'request': request - }) - if settings.DEBUG: - return debug.technical_500_response(request, *sys.exc_info(), status_code=400) - - response = self.get_exception_response(request, resolver, 400) - - except SystemExit: - # Allow sys.exit() to actually exit. See tickets #1023 and #4701 - raise - - except: # Handle everything else. - # Get the exception info now, in case another exception is thrown later. - signals.got_request_exception.send(sender=self.__class__, request=request) - response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) - - try: - # Apply response middleware, regardless of the response - for middleware_method in self._response_middleware: - response = middleware_method(request, response) - # Complain if the response middleware returned None (a common error). - if response is None: - raise ValueError( - "%s.process_response didn't return an " - "HttpResponse object. It returned None instead." - % (middleware_method.__self__.__class__.__name__)) - response = self.apply_response_fixes(request, response) - except: # Any exception should be gathered and handled - signals.got_request_exception.send(sender=self.__class__, request=request) - response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) - - response._closable_objects.append(request) - - return response - - def handle_uncaught_exception(self, request, resolver, exc_info): - """ - Processing for any otherwise uncaught exceptions (those that will - generate HTTP 500 responses). Can be overridden by subclasses who want - customised 500 handling. - - Be *very* careful when overriding this because the error could be - caused by anything, so assuming something like the database is always - available would be an error. - """ - if settings.DEBUG_PROPAGATE_EXCEPTIONS: - raise - - logger.error('Internal Server Error: %s', request.path, - exc_info=exc_info, - extra={ - 'status_code': 500, - 'request': request - } - ) - - if settings.DEBUG: - return debug.technical_500_response(request, *exc_info) - - # If Http500 handler is not installed, re-raise last exception - if resolver.urlconf_module is None: - six.reraise(*exc_info) - # Return an HttpResponse that displays a friendly error message. - callback, param_dict = resolver.resolve_error_handler(500) - return callback(request, **param_dict) - - def apply_response_fixes(self, request, response): - """ - Applies each of the functions in self.response_fixes to the request and - response, modifying the response in the process. Returns the new - response. - """ - for func in self.response_fixes: - response = func(request, response) +# Example source code copied from the Django project on GitHub +# https://github.com/django/django/blob/master/django/core/handlers/base.py +from __future__ import unicode_literals + +import logging +import sys +import types + +from django import http +from django.conf import settings +from django.core import urlresolvers +from django.core import signals +from django.core.exceptions import MiddlewareNotUsed, PermissionDenied, SuspiciousOperation +from django.db import connections, transaction +from django.http.multipartparser import MultiPartParserError +from django.utils.encoding import force_text +from django.utils.module_loading import import_string +from django.utils import six +from django.views import debug + +logger = logging.getLogger('django.request') + + +class BaseHandler(object): + # Changes that are always applied to a response (in this order). + response_fixes = [ + http.fix_location_header, + http.conditional_content_removal, + ] + + def __init__(self): + self._request_middleware = None + self._view_middleware = None + self._template_response_middleware = None + self._response_middleware = None + self._exception_middleware = None + + def load_middleware(self): + """ + Populate middleware lists from settings.MIDDLEWARE_CLASSES. + + Must be called after the environment is fixed (see __call__ in subclasses). + """ + self._view_middleware = [] + self._template_response_middleware = [] + self._response_middleware = [] + self._exception_middleware = [] + + request_middleware = [] + for middleware_path in settings.MIDDLEWARE_CLASSES: + mw_class = import_string(middleware_path) + try: + mw_instance = mw_class() + except MiddlewareNotUsed as exc: + if settings.DEBUG: + if six.text_type(exc): + logger.debug('MiddlewareNotUsed(%r): %s', middleware_path, exc) + else: + logger.debug('MiddlewareNotUsed: %r', middleware_path) + continue + + if hasattr(mw_instance, 'process_request'): + request_middleware.append(mw_instance.process_request) + if hasattr(mw_instance, 'process_view'): + self._view_middleware.append(mw_instance.process_view) + if hasattr(mw_instance, 'process_template_response'): + self._template_response_middleware.insert(0, mw_instance.process_template_response) + if hasattr(mw_instance, 'process_response'): + self._response_middleware.insert(0, mw_instance.process_response) + if hasattr(mw_instance, 'process_exception'): + self._exception_middleware.insert(0, mw_instance.process_exception) + + # We only assign to this when initialization is complete as it is used + # as a flag for initialization being complete. + self._request_middleware = request_middleware + + def make_view_atomic(self, view): + non_atomic_requests = getattr(view, '_non_atomic_requests', set()) + for db in connections.all(): + if (db.settings_dict['ATOMIC_REQUESTS'] + and db.alias not in non_atomic_requests): + view = transaction.atomic(using=db.alias)(view) + return view + + def get_exception_response(self, request, resolver, status_code): + try: + callback, param_dict = resolver.resolve_error_handler(status_code) + response = callback(request, **param_dict) + except: + signals.got_request_exception.send(sender=self.__class__, request=request) + response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) + + return response + + def get_response(self, request): + "Returns an HttpResponse object for the given HttpRequest" + + # Setup default url resolver for this thread, this code is outside + # the try/except so we don't get a spurious "unbound local + # variable" exception in the event an exception is raised before + # resolver is set + urlconf = settings.ROOT_URLCONF + urlresolvers.set_urlconf(urlconf) + resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) + try: + response = None + # Apply request middleware + for middleware_method in self._request_middleware: + response = middleware_method(request) + if response: + break + + if response is None: + if hasattr(request, 'urlconf'): + # Reset url resolver with a custom urlconf. + urlconf = request.urlconf + urlresolvers.set_urlconf(urlconf) + resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) + + resolver_match = resolver.resolve(request.path_info) + callback, callback_args, callback_kwargs = resolver_match + request.resolver_match = resolver_match + + # Apply view middleware + for middleware_method in self._view_middleware: + response = middleware_method(request, callback, callback_args, callback_kwargs) + if response: + break + + if response is None: + wrapped_callback = self.make_view_atomic(callback) + try: + response = wrapped_callback(request, *callback_args, **callback_kwargs) + except Exception as e: + # If the view raised an exception, run it through exception + # middleware, and if the exception middleware returns a + # response, use that. Otherwise, reraise the exception. + for middleware_method in self._exception_middleware: + response = middleware_method(request, e) + if response: + break + if response is None: + raise + + # Complain if the view returned None (a common error). + if response is None: + if isinstance(callback, types.FunctionType): # FBV + view_name = callback.__name__ + else: # CBV + view_name = callback.__class__.__name__ + '.__call__' + raise ValueError("The view %s.%s didn't return an HttpResponse object. It returned None instead." + % (callback.__module__, view_name)) + + # If the response supports deferred rendering, apply template + # response middleware and then render the response + if hasattr(response, 'render') and callable(response.render): + for middleware_method in self._template_response_middleware: + response = middleware_method(request, response) + # Complain if the template response middleware returned None (a common error). + if response is None: + raise ValueError( + "%s.process_template_response didn't return an " + "HttpResponse object. It returned None instead." + % (middleware_method.__self__.__class__.__name__)) + response = response.render() + + except http.Http404 as e: + logger.warning('Not Found: %s', request.path, + extra={ + 'status_code': 404, + 'request': request + }) + if settings.DEBUG: + response = debug.technical_404_response(request, e) + else: + response = self.get_exception_response(request, resolver, 404) + + except PermissionDenied: + logger.warning( + 'Forbidden (Permission denied): %s', request.path, + extra={ + 'status_code': 403, + 'request': request + }) + response = self.get_exception_response(request, resolver, 403) + + except MultiPartParserError: + logger.warning( + 'Bad request (Unable to parse request body): %s', request.path, + extra={ + 'status_code': 400, + 'request': request + }) + response = self.get_exception_response(request, resolver, 400) + + except SuspiciousOperation as e: + # The request logger receives events for any problematic request + # The security logger receives events for all SuspiciousOperations + security_logger = logging.getLogger('django.security.%s' % + e.__class__.__name__) + security_logger.error( + force_text(e), + extra={ + 'status_code': 400, + 'request': request + }) + if settings.DEBUG: + return debug.technical_500_response(request, *sys.exc_info(), status_code=400) + + response = self.get_exception_response(request, resolver, 400) + + except SystemExit: + # Allow sys.exit() to actually exit. See tickets #1023 and #4701 + raise + + except: # Handle everything else. + # Get the exception info now, in case another exception is thrown later. + signals.got_request_exception.send(sender=self.__class__, request=request) + response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) + + try: + # Apply response middleware, regardless of the response + for middleware_method in self._response_middleware: + response = middleware_method(request, response) + # Complain if the response middleware returned None (a common error). + if response is None: + raise ValueError( + "%s.process_response didn't return an " + "HttpResponse object. It returned None instead." + % (middleware_method.__self__.__class__.__name__)) + response = self.apply_response_fixes(request, response) + except: # Any exception should be gathered and handled + signals.got_request_exception.send(sender=self.__class__, request=request) + response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) + + response._closable_objects.append(request) + + return response + + def handle_uncaught_exception(self, request, resolver, exc_info): + """ + Processing for any otherwise uncaught exceptions (those that will + generate HTTP 500 responses). Can be overridden by subclasses who want + customised 500 handling. + + Be *very* careful when overriding this because the error could be + caused by anything, so assuming something like the database is always + available would be an error. + """ + if settings.DEBUG_PROPAGATE_EXCEPTIONS: + raise + + logger.error('Internal Server Error: %s', request.path, + exc_info=exc_info, + extra={ + 'status_code': 500, + 'request': request + } + ) + + if settings.DEBUG: + return debug.technical_500_response(request, *exc_info) + + # If Http500 handler is not installed, re-raise last exception + if resolver.urlconf_module is None: + six.reraise(*exc_info) + # Return an HttpResponse that displays a friendly error message. + callback, param_dict = resolver.resolve_error_handler(500) + return callback(request, **param_dict) + + def apply_response_fixes(self, request, response): + """ + Applies each of the functions in self.response_fixes to the request and + response, modifying the response in the process. Returns the new + response. + """ + for func in self.response_fixes: + response = func(request, response) return response \ No newline at end of file diff --git a/pmd-xml/src/main/resources/rulesets/pom/rulesets.properties b/pmd-xml/src/main/resources/rulesets/pom/rulesets.properties index 44401548a4..c5f6f4b8a2 100644 --- a/pmd-xml/src/main/resources/rulesets/pom/rulesets.properties +++ b/pmd-xml/src/main/resources/rulesets/pom/rulesets.properties @@ -1,5 +1,5 @@ -# -# BSD-style license; for more info see http://pmd.sourceforge.net/license.html -# - -rulesets.filenames=rulesets/pom/basic.xml +# +# BSD-style license; for more info see http://pmd.sourceforge.net/license.html +# + +rulesets.filenames=rulesets/pom/basic.xml diff --git a/pmd-xml/src/main/resources/rulesets/xml/rulesets.properties b/pmd-xml/src/main/resources/rulesets/xml/rulesets.properties index b2a6598184..a19ec1e61e 100644 --- a/pmd-xml/src/main/resources/rulesets/xml/rulesets.properties +++ b/pmd-xml/src/main/resources/rulesets/xml/rulesets.properties @@ -1,5 +1,5 @@ -# -# BSD-style license; for more info see http://pmd.sourceforge.net/license.html -# - -rulesets.filenames=rulesets/xml/basic.xml +# +# BSD-style license; for more info see http://pmd.sourceforge.net/license.html +# + +rulesets.filenames=rulesets/xml/basic.xml diff --git a/pmd-xml/src/main/resources/rulesets/xsl/rulesets.properties b/pmd-xml/src/main/resources/rulesets/xsl/rulesets.properties index 4476c82615..89e311fb03 100644 --- a/pmd-xml/src/main/resources/rulesets/xsl/rulesets.properties +++ b/pmd-xml/src/main/resources/rulesets/xsl/rulesets.properties @@ -1,5 +1,5 @@ -# -# BSD-style license; for more info see http://pmd.sourceforge.net/license.html -# - -rulesets.filenames=rulesets/xsl/xpath.xml +# +# BSD-style license; for more info see http://pmd.sourceforge.net/license.html +# + +rulesets.filenames=rulesets/xsl/xpath.xml