<commit_before>package com.github.therapi.runtimejavadoc.internal.parser;

import com.github.therapi.runtimejavadoc.Link;
import com.github.therapi.runtimejavadoc.SeeAlsoJavadoc;
import com.github.therapi.runtimejavadoc.SeeAlsoJavadoc.HtmlLink;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.regex.Pattern.compile;

public class SeeAlsoParser {
	
	private static final Pattern stringLiteralPattern = compile("^\".*\"$");
	private static final Pattern htmlLink = compile("(?s)<a\\s*href=['\"](?<link>.+?)['\"]\\s*>(?<text>.+)<\\/a>");
	
	public static SeeAlsoJavadoc parseSeeAlso(String owningClass, String value) {
		SeeAlsoJavadoc seeAlsoJavadoc = parseAsStringLiteral(value);
		if (seeAlsoJavadoc == null) {
			seeAlsoJavadoc = parseAsHtmlLink(value);
		}
		if (seeAlsoJavadoc == null) {
			seeAlsoJavadoc = parseAsJavadocLink(owningClass, value);
		}
		if (seeAlsoJavadoc == null) {
			throw new AssertionError("SeeAlso not recognized as string literal, HTML link or Javadoc link");
		}
		
		return seeAlsoJavadoc;
	}
	
	private static SeeAlsoJavadoc parseAsStringLiteral(String value) {
		return stringLiteralPattern.matcher(value).matches() ? new SeeAlsoJavadoc(value) : null;
	}
	
	private static SeeAlsoJavadoc parseAsHtmlLink(String value) {
		Matcher matcher = htmlLink.matcher(value);
		if (matcher.matches()) {
			return new SeeAlsoJavadoc(new HtmlLink(matcher.group("text"), matcher.group("link")));<commit_msg>#32: Referenced POC for regex<commit_after>package com.github.therapi.runtimejavadoc.internal.parser;

import com.github.therapi.runtimejavadoc.Link;
import com.github.therapi.runtimejavadoc.SeeAlsoJavadoc;
import com.github.therapi.runtimejavadoc.SeeAlsoJavadoc.HtmlLink;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.regex.Pattern.compile;

public class SeeAlsoParser {
	
	private static final Pattern stringLiteralPattern = compile("^\".*\"$");
	// https://regex101.com/r/lZmCCx/1
	private static final Pattern htmlLink = compile("(?s)<a\\s*href=['\"](?<link>.+?)['\"]\\s*>(?<text>.+)<\\/a>");
	
	public static SeeAlsoJavadoc parseSeeAlso(String owningClass, String value) {
		SeeAlsoJavadoc seeAlsoJavadoc = parseAsStringLiteral(value);
		if (seeAlsoJavadoc == null) {
			seeAlsoJavadoc = parseAsHtmlLink(value);
		}
		if (seeAlsoJavadoc == null) {
			seeAlsoJavadoc = parseAsJavadocLink(owningClass, value);
		}
		if (seeAlsoJavadoc == null) {
			throw new AssertionError("SeeAlso not recognized as string literal, HTML link or Javadoc link");
		}
		
		return seeAlsoJavadoc;
	}
	
	private static SeeAlsoJavadoc parseAsStringLiteral(String value) {
		return stringLiteralPattern.matcher(value).matches() ? new SeeAlsoJavadoc(value) : null;
	}
	
	private static SeeAlsoJavadoc parseAsHtmlLink(String value) {
		Matcher matcher = htmlLink.matcher(value);
		if (matcher.matches()) {
			return new SeeAlsoJavadoc(new HtmlLink(matcher.group("text"), matcher.group("link")));
{'fraction_non_alphanumeric': 0.13036193029490617, 'fraction_numerical': 0.0020107238605898124, 'mean_word_length': 5.5174672489082965, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4236068', 'n_tokens_mistral': 1115, 'n_tokens_neox': 973, 'n_words': 192}