Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into report-viewer/upgr…
Browse files Browse the repository at this point in the history
…ade-eslint-config
  • Loading branch information
Kr0nox committed Dec 13, 2024
2 parents 0ec99b0 + 697c5d3 commit 1435c14
Show file tree
Hide file tree
Showing 30 changed files with 546 additions and 231 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
npm run build-demo
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.6.9
uses: JamesIves/github-pages-deploy-action@v4.7.2
with:
branch: gh-pages
folder: report-viewer/dist
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/report-viewer-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
npm run build-dev
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.6.9
uses: JamesIves/github-pages-deploy-action@v4.7.2
with:
branch: gh-pages
folder: report-viewer/dist
Expand Down
5 changes: 5 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
<artifactId>llvmir</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>multi-language</artifactId>
<version>${revision}</version>
</dependency>
<!-- CLI -->
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.ArrayList;

import de.jplag.LanguageLoader;

/**
* Helper class for picocli to find all available languages.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.jplag.cli.options;

import de.jplag.Language;
import de.jplag.LanguageLoader;

import picocli.CommandLine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import java.util.stream.Collectors;

import de.jplag.Language;
import de.jplag.LanguageLoader;
import de.jplag.cli.CliException;
import de.jplag.cli.options.CliOptions;
import de.jplag.cli.options.LanguageLoader;
import de.jplag.options.LanguageOption;
import de.jplag.options.LanguageOptions;

Expand Down
9 changes: 6 additions & 3 deletions cli/src/test/java/de/jplag/cli/LanguageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
import org.junit.jupiter.params.provider.MethodSource;

import de.jplag.Language;
import de.jplag.LanguageLoader;
import de.jplag.cli.options.CliOptions;
import de.jplag.cli.options.LanguageLoader;
import de.jplag.cli.test.CliArgument;
import de.jplag.cli.test.CliTest;
import de.jplag.exceptions.ExitException;
import de.jplag.multilang.MultiLanguage;
import de.jplag.options.JPlagOptions;

class LanguageTest extends CliTest {
private static final List<Class<? extends Language>> ignoredLanguages = List.of(MultiLanguage.class);

@Test
void testDefaultLanguage() throws ExitException, IOException {
Expand All @@ -38,7 +40,7 @@ void testInvalidLanguage() {
@Test
void testLoading() {
var languages = LanguageLoader.getAllAvailableLanguages();
assertEquals(19, languages.size(), "Loaded Languages: " + languages.keySet());
assertEquals(20, languages.size(), "Loaded Languages: " + languages.keySet());
}

@ParameterizedTest
Expand All @@ -58,6 +60,7 @@ void testCustomSuffixes() throws ExitException, IOException {
}

public static Collection<Language> getAllLanguages() {
return LanguageLoader.getAllAvailableLanguages().values();
return LanguageLoader.getAllAvailableLanguages().values().stream().filter(language -> !ignoredLanguages.contains(language.getClass()))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.IOException;

import de.jplag.Language;
import de.jplag.cli.options.LanguageLoader;
import de.jplag.LanguageLoader;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag.cli.options;
package de.jplag;

import java.util.Collections;
import java.util.Map;
Expand All @@ -11,8 +11,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.jplag.Language;

/**
* This class contains methods to load {@link Language Languages}.
* @author Dominik Fuchss
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DefaultLanguageOption<T> implements LanguageOption<T> {
this.hasValue = true;
}

DefaultLanguageOption(OptionType<T> type, String description, String name) {
DefaultLanguageOption(OptionType<T> type, String name, String description) {
this(type, name, description, null);
this.hasValue = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -247,7 +248,7 @@ final List<TokenPositionTestData> getTokenPositionTestData() {
@MethodSource("getAllTestData")
@DisplayName("Test that the tokens map to ascending line numbers")
final void testMonotoneTokenOrder(TestData data) throws ParsingException, IOException {
List<Token> tokens = parseTokens(data);
List<Token> tokens = parseTokens(data).stream().filter(it -> !getIgnoredTokensForMonotoneTokenOrder().contains(it.getType())).toList();

for (int i = 0; i < tokens.size() - 2; i++) {
Token first = tokens.get(i);
Expand Down Expand Up @@ -338,4 +339,8 @@ private <T, C extends Collection<T>> C ignoreEmptyTestType(C data) {
protected File getTestFileLocation() {
return new File(DEFAULT_TEST_CODE_PATH_BASE.toFile(), this.language.getIdentifier());
}

protected List<TokenType> getIgnoredTokensForMonotoneTokenOrder() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public Void visitClass(ClassTree node, Void unused) {
}
}

long start = positions.getStartPosition(ast, node);
long start = positions.getEndPosition(ast, node.getModifiers()) + 1;
long nameLength = node.getSimpleName().length();
long end = positions.getEndPosition(ast, node) - 1;
CodeSemantics semantics = CodeSemantics.createControl();
if (node.getKind() == Tree.Kind.ENUM) {
Expand All @@ -146,7 +147,9 @@ public Void visitClass(ClassTree node, Void unused) {
} else if (node.getKind() == Tree.Kind.RECORD) {
addToken(JavaTokenType.J_RECORD_BEGIN, start, 1, semantics);
} else if (node.getKind() == Tree.Kind.ANNOTATION_TYPE) {
addToken(JavaTokenType.J_ANNO_T_BEGIN, start, 10, semantics);
// The start position for the is calculated that way, because the @ is the final element in the modifier list for
// annotations
addToken(JavaTokenType.J_ANNO_T_BEGIN, start - 2, (start - 2) + 11 + nameLength, semantics);
} else if (node.getKind() == Tree.Kind.CLASS) {
addToken(JavaTokenType.J_CLASS_BEGIN, start, 5, semantics);
}
Expand Down Expand Up @@ -508,7 +511,8 @@ public Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
@Override
public Void visitAnnotation(AnnotationTree node, Void unused) {
long start = positions.getStartPosition(ast, node);
addToken(JavaTokenType.J_ANNO, start, 1, new CodeSemantics());
String annotationName = node.getAnnotationType().toString();
addToken(JavaTokenType.J_ANNO, start, annotationName.length() + 1, new CodeSemantics());
return super.visitAnnotation(node, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import static de.jplag.java.JavaTokenType.J_TRY_END;
import static de.jplag.java.JavaTokenType.J_VARDEF;

import java.util.List;

import de.jplag.TokenType;
import de.jplag.testutils.LanguageModuleTest;
import de.jplag.testutils.datacollector.TestDataCollector;
import de.jplag.testutils.datacollector.TestSourceIgnoredLinesCollector;
Expand Down Expand Up @@ -84,4 +87,9 @@ protected void configureIgnoredLines(TestSourceIgnoredLinesCollector collector)
collector.ignoreLinesByPrefix("})");
collector.ignoreByCondition(line -> line.contains("else") && !line.contains("if"));
}

@Override
protected List<TokenType> getIgnoredTokensForMonotoneTokenOrder() {
return List.of(JavaTokenType.J_ANNO);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
>@SuppressWarnings
$| J_ANNO 17
>class Anno {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
>@SuppressWarnings("SomeWarning")
$| J_ANNO 17
>class Anno {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
>class Anno {
> @Deprecated
$ | J_ANNO 11
> public void testFunction() {
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
>import javax.annotation.processing.Generated;
>
>class Anno {
> public void testMethod(@Generated String param) {
$ | J_ANNO 10
> }
>}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
>public @interface MyAnnotation {}
$ | J_ANNO_T_BEGIN 23
$ | J_ANNO_T_END 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
>public @interface MyAnnotation {
$ | J_ANNO_T_BEGIN 23
>}
$| J_ANNO_T_END 1
26 changes: 26 additions & 0 deletions languages/multi-language/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.jplag</groupId>
<artifactId>languages</artifactId>
<version>${revision}</version>
</parent>
<artifactId>multi-language</artifactId>

<dependencies>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>java</artifactId>
<version>${revision}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>cpp</artifactId>
<version>${revision}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package de.jplag.multilang;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.kohsuke.MetaInfServices;

import de.jplag.Language;
import de.jplag.LanguageLoader;
import de.jplag.ParsingException;
import de.jplag.Token;
import de.jplag.options.LanguageOptions;

@MetaInfServices(Language.class)
public class MultiLanguage implements Language {
private final MultiLanguageOptions options;

public MultiLanguage() {
this.options = new MultiLanguageOptions();
}

@Override
public String[] suffixes() {
return LanguageLoader.getAllAvailableLanguages().values().stream().filter(it -> it != this).flatMap(it -> Arrays.stream(it.suffixes()))
.toArray(String[]::new);
}

@Override
public String getName() {
return "multi-language";
}

@Override
public String getIdentifier() {
return "multi";
}

@Override
public int minimumTokenMatch() {
return this.options.getLanguages().stream().mapToInt(Language::minimumTokenMatch).min().orElse(9);
}

@Override
public List<Token> parse(Set<File> files, boolean normalize) throws ParsingException {
MultiLanguageParser parser = new MultiLanguageParser(this.options);
return parser.parseFiles(files, normalize);
}

@Override
public LanguageOptions getOptions() {
return this.options;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package de.jplag.multilang;

import java.util.Arrays;
import java.util.List;

import de.jplag.Language;
import de.jplag.LanguageLoader;
import de.jplag.options.LanguageOption;
import de.jplag.options.LanguageOptions;
import de.jplag.options.OptionType;

public class MultiLanguageOptions extends LanguageOptions {
private static final String ERROR_LANGUAGE_NOT_FOUND = "The selected language %s could not be found";
private static final String ERROR_NOT_ENOUGH_LANGUAGES = "To use multi language specify at least 1 language";
private static final String OPTION_DESCRIPTION_LANGUAGES = "The languages that should be used. This is a ',' separated list";

private final LanguageOption<String> languageNames = createOption(OptionType.string(), "languages", OPTION_DESCRIPTION_LANGUAGES);
private List<Language> languages = null;

public List<Language> getLanguages() {
if (this.languages == null) {
if (languageNames.getValue() == null) {
throw new IllegalArgumentException(ERROR_NOT_ENOUGH_LANGUAGES);
}

this.languages = Arrays.stream(languageNames.getValue().split(","))
.map(name -> LanguageLoader.getLanguage(name)
.orElseThrow(() -> new IllegalArgumentException(String.format(ERROR_LANGUAGE_NOT_FOUND, name))))
.filter(language -> !language.getClass().equals(MultiLanguage.class)).toList();

if (this.languages.isEmpty()) {
throw new IllegalArgumentException(ERROR_NOT_ENOUGH_LANGUAGES);
}
}

return this.languages;
}

public LanguageOption<String> getLanguageNames() {
return this.languageNames;
}
}
Loading

0 comments on commit 1435c14

Please sign in to comment.