AbstractHtmlReferenceProcessor.java

1
/*-
2
 * #%L
3
 * io.earcam.utilitarian.site.search.offline
4
 * %%
5
 * Copyright (C) 2017 earcam
6
 * %%
7
 * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT)
8
 * 
9
 * You <b>must</b> choose to accept, in full - any individual or combination of 
10
 * the following licenses:
11
 * <ul>
12
 * 	<li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li>
13
 * 	<li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li>
14
 * 	<li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li>
15
 * 	<li><a href="https://opensource.org/licenses/MIT">MIT</a></li>
16
 * </ul>
17
 * #L%
18
 */
19
package io.earcam.utilitarian.site.search.offline;
20
21
import java.io.File;
22
import java.nio.file.Path;
23
import java.util.function.Predicate;
24
25
abstract class AbstractHtmlReferenceProcessor extends AbstractHtmlProcessor {
26
27
	private final Path main;
28
	private final Path test;
29
	private final String titlePrefix;
30
31
32
	AbstractHtmlReferenceProcessor(Path main, Path test, String titlePrefix)
33
	{
34
		this.main = main;
35
		this.test = test;
36
		this.titlePrefix = titlePrefix;
37
	}
38
39
40
	@Override
41
	public void process(Document document)
42
	{
43 2 1. process : negated conditional → KILLED
2. process : negated conditional → KILLED
		if(isHtml(document) && !document.hasRaw()) {
44
			Path root = refDocsRoot(document);
45 1 1. process : negated conditional → KILLED
			if(root != null) {
46 1 1. process : negated conditional → KILLED
				if(skip(document)) {
47 1 1. process : removed call to io/earcam/utilitarian/site/search/offline/AbstractHtmlReferenceProcessor::nullContent → KILLED
					nullContent(document);
48
				} else {
49 1 1. process : removed call to io/earcam/utilitarian/site/search/offline/AbstractHtmlReferenceProcessor::proceed → KILLED
					proceed(document, root);
50
				}
51
			}
52
		}
53
	}
54
55
56
	private void nullContent(Document document)
57
	{
58 1 1. nullContent : removed call to io/earcam/utilitarian/site/search/offline/Document::field → KILLED
		document.field(Document.RAW_TEXT, "");
59
	}
60
61
62
	private void proceed(Document document, Path root)
63
	{
64
		String fqn = root.relativize(document.file()).toString();
65
		fqn = fqn.substring(0, fqn.lastIndexOf('.')).replace(File.separatorChar, '.');
66
67
		String simpleName = document.file().getFileName().toString();
68
		simpleName = simpleName.substring(0, simpleName.lastIndexOf('.'));
69
70 1 1. proceed : removed call to io/earcam/utilitarian/site/search/offline/Document::field → KILLED
		document.field(Document.RAW_TEXT, fqn + " " + simpleName);
71 1 1. proceed : removed call to io/earcam/utilitarian/site/search/offline/Document::field → KILLED
		document.field(Document.TITLE, titlePrefix + " " + simpleName);
72
		document.tokens().add(fqn);
73
		document.tokens().add(simpleName);
74
	}
75
76
77
	protected abstract boolean skip(Document document);
78
79
80
	private Path refDocsRoot(Document document)
81
	{
82 4 1. lambda$refDocsRoot$0 : negated conditional → KILLED
2. lambda$refDocsRoot$0 : negated conditional → KILLED
3. lambda$refDocsRoot$0 : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
4. refDocsRoot : mutated return of Object value for io/earcam/utilitarian/site/search/offline/AbstractHtmlReferenceProcessor::refDocsRoot to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return matchingParent(document, p -> p.endsWith(main) || p.endsWith(test));
83
	}
84
85
86
	protected final Path matchingParent(Document document, Predicate<Path> match)
87
	{
88
		Path path = document.file();
89
		do {
90 1 1. matchingParent : negated conditional → KILLED
			if(match.test(path)) {
91 1 1. matchingParent : mutated return of Object value for io/earcam/utilitarian/site/search/offline/AbstractHtmlReferenceProcessor::matchingParent to ( if (x != null) null else throw new RuntimeException ) → KILLED
				return path;
92
			}
93 1 1. matchingParent : negated conditional → KILLED
		} while((path = path.getParent()) != null);
94 1 1. matchingParent : mutated return of Object value for io/earcam/utilitarian/site/search/offline/AbstractHtmlReferenceProcessor::matchingParent to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return null;
95
	}
96
97
98
	protected final boolean hasMatchingParent(Document document, Predicate<Path> match)
99
	{
100 2 1. hasMatchingParent : negated conditional → KILLED
2. hasMatchingParent : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
		return matchingParent(document, match) != null;
101
	}
102
}

Mutations

43

1.1
Location : process
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
negated conditional → KILLED

2.2
Location : process
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
negated conditional → KILLED

45

1.1
Location : process
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
negated conditional → KILLED

46

1.1
Location : process
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
negated conditional → KILLED

47

1.1
Location : process
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.skipped()
removed call to io/earcam/utilitarian/site/search/offline/AbstractHtmlReferenceProcessor::nullContent → KILLED

49

1.1
Location : process
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
removed call to io/earcam/utilitarian/site/search/offline/AbstractHtmlReferenceProcessor::proceed → KILLED

58

1.1
Location : nullContent
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.skipped()
removed call to io/earcam/utilitarian/site/search/offline/Document::field → KILLED

70

1.1
Location : proceed
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
removed call to io/earcam/utilitarian/site/search/offline/Document::field → KILLED

71

1.1
Location : proceed
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
removed call to io/earcam/utilitarian/site/search/offline/Document::field → KILLED

82

1.1
Location : lambda$refDocsRoot$0
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
negated conditional → KILLED

2.2
Location : lambda$refDocsRoot$0
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
negated conditional → KILLED

3.3
Location : lambda$refDocsRoot$0
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

4.4
Location : refDocsRoot
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/AbstractHtmlReferenceProcessor::refDocsRoot to ( if (x != null) null else throw new RuntimeException ) → KILLED

90

1.1
Location : matchingParent
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
negated conditional → KILLED

91

1.1
Location : matchingParent
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/AbstractHtmlReferenceProcessor::matchingParent to ( if (x != null) null else throw new RuntimeException ) → KILLED

93

1.1
Location : matchingParent
Killed by : io.earcam.utilitarian.site.search.offline.XrefHtmlReferenceProcessorTest.processed()
negated conditional → KILLED

94

1.1
Location : matchingParent
Killed by : io.earcam.utilitarian.site.search.offline.ApiDocsHtmlReferenceProcessorTest.processed()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/AbstractHtmlReferenceProcessor::matchingParent to ( if (x != null) null else throw new RuntimeException ) → KILLED

100

1.1
Location : hasMatchingParent
Killed by : io.earcam.utilitarian.site.search.offline.ApiDocsHtmlReferenceProcessorTest.processed()
negated conditional → KILLED

2.2
Location : hasMatchingParent
Killed by : io.earcam.utilitarian.site.search.offline.ApiDocsHtmlReferenceProcessorTest.processed()
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

Active mutators

Tests examined


Report generated by PIT 1.4.3