@Test public void can_collect_tokens() { DefaultInputFile inputFile = inputFile("cpd.yaml"); OpenApiVisitorContext visitorContext = TestOpenApiVisitorRunner.createContext(inputFile.path().toFile()); cpdAnalyzer.pushCpdTokens(inputFile, visitorContext); List<TokensLine> lines = context.cpdTokens("moduleKey:cpd.yaml"); assertThat(lines).hasSize(6); TokensLine line1 = lines.get(0); assertThat(line1.getStartLine()).isEqualTo(1); assertThat(line1.getEndLine()).isEqualTo(1); assertThat(line1.getStartUnit()).isEqualTo(1); assertThat(line1.getEndUnit()).isEqualTo(3); List<String> values = lines.stream().map(TokensLine::getValue).collect(Collectors.toList()); assertThat(values).containsExactly( "openapi:3.0.1", "info:", "version:1.0.0", "title:Swagger Petstore", "paths:", "/pets:{}"); }
public void pushCpdTokens(InputFile inputFile, OpenApiVisitorContext visitorContext) { AstNode root = visitorContext.rootTree(); if (root != null) { NewCpdTokens cpdTokens = context.newCpdTokens().onFile(inputFile); for (Token token : root.getTokens()) { if (!isIgnoredType(token.getType())) { IssueLocation.TokenLocation location = new IssueLocation.TokenLocation(token); if (location.startLine() < location.endLine() || location.startLineOffset() < location.endLineOffset()) { cpdTokens.addToken(location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset(), getImage(token)); } } } cpdTokens.save(); } }
OpenApiCpdAnalyzer { public void pushCpdTokens(InputFile inputFile, OpenApiVisitorContext visitorContext) { AstNode root = visitorContext.rootTree(); if (root != null) { NewCpdTokens cpdTokens = context.newCpdTokens().onFile(inputFile); for (Token token : root.getTokens()) { if (!isIgnoredType(token.getType())) { IssueLocation.TokenLocation location = new IssueLocation.TokenLocation(token); if (location.startLine() < location.endLine() || location.startLineOffset() < location.endLineOffset()) { cpdTokens.addToken(location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset(), getImage(token)); } } } cpdTokens.save(); } } }
OpenApiCpdAnalyzer { public void pushCpdTokens(InputFile inputFile, OpenApiVisitorContext visitorContext) { AstNode root = visitorContext.rootTree(); if (root != null) { NewCpdTokens cpdTokens = context.newCpdTokens().onFile(inputFile); for (Token token : root.getTokens()) { if (!isIgnoredType(token.getType())) { IssueLocation.TokenLocation location = new IssueLocation.TokenLocation(token); if (location.startLine() < location.endLine() || location.startLineOffset() < location.endLineOffset()) { cpdTokens.addToken(location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset(), getImage(token)); } } } cpdTokens.save(); } } OpenApiCpdAnalyzer(SensorContext context); }
OpenApiCpdAnalyzer { public void pushCpdTokens(InputFile inputFile, OpenApiVisitorContext visitorContext) { AstNode root = visitorContext.rootTree(); if (root != null) { NewCpdTokens cpdTokens = context.newCpdTokens().onFile(inputFile); for (Token token : root.getTokens()) { if (!isIgnoredType(token.getType())) { IssueLocation.TokenLocation location = new IssueLocation.TokenLocation(token); if (location.startLine() < location.endLine() || location.startLineOffset() < location.endLineOffset()) { cpdTokens.addToken(location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset(), getImage(token)); } } } cpdTokens.save(); } } OpenApiCpdAnalyzer(SensorContext context); void pushCpdTokens(InputFile inputFile, OpenApiVisitorContext visitorContext); }
OpenApiCpdAnalyzer { public void pushCpdTokens(InputFile inputFile, OpenApiVisitorContext visitorContext) { AstNode root = visitorContext.rootTree(); if (root != null) { NewCpdTokens cpdTokens = context.newCpdTokens().onFile(inputFile); for (Token token : root.getTokens()) { if (!isIgnoredType(token.getType())) { IssueLocation.TokenLocation location = new IssueLocation.TokenLocation(token); if (location.startLine() < location.endLine() || location.startLineOffset() < location.endLineOffset()) { cpdTokens.addToken(location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset(), getImage(token)); } } } cpdTokens.save(); } } OpenApiCpdAnalyzer(SensorContext context); void pushCpdTokens(InputFile inputFile, OpenApiVisitorContext visitorContext);  }