Projects >> xtext >>d0e077de2dacdf4fe97a77c57d4bac360604af1b

Chunk
Conflicting content
import org.eclipse.xtext.generator.parser.antlr.postProcessing.SuppressWarningsProcessor;
import org.eclipse.xtext.generator.parser.packrat.PackratParserFragment;
import org.eclipse.xtext.util.Strings;
<<<<<<< HEAD
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.AntlrCodeQualityHelper;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.AntlrLexerSplitter;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.AntlrParserSplitter;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.BacktrackingGuardForUnorderedGroupsRemover;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.PartialClassExtractor;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.SyntacticPredicateFixup;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.UnorderedGroupsSplitter;
=======
import org.eclipse.xtext.xtext.generator.normalization.FlattenedGrammarAccess;
import org.eclipse.xtext.xtext.generator.normalization.RuleFilter;
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
Solution content
import org.eclipse.xtext.generator.parser.antlr.postProcessing.SuppressWarningsProcessor;
import org.eclipse.xtext.generator.parser.packrat.PackratParserFragment;
import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.AntlrCodeQualityHelper;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.AntlrLexerSplitter;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.AntlrParserSplitter;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.BacktrackingGuardForUnorderedGroupsRemover;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.PartialClassExtractor;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.SyntacticPredicateFixup;
import org.eclipse.xtext.xtext.generator.parser.antlr.splitting.UnorderedGroupsSplitter;
import org.eclipse.xtext.xtext.generator.normalization.FlattenedGrammarAccess;
import org.eclipse.xtext.xtext.generator.normalization.RuleFilter;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
File
AbstractAntlrGeneratorFragment.java
Developer's decision
Concatenation
Kind of conflict
Import
Chunk
Conflicting content
			String absoluteParserGrammarFileName, final Charset encoding) {
		String lexerJavaFile = absoluteLexerGrammarFileName.replaceAll("\\.g$", getLexerFileNameSuffix());
		String parserJavaFile = absoluteParserGrammarFileName.replaceAll("\\.g$", getParserFileNameSuffix());
<<<<<<< HEAD
		improveCodeQuality(lexerJavaFile, parserJavaFile, encoding);
=======
		if (codeQualityHelper != null) {
			codeQualityHelper.stripUnnecessaryComments(lexerJavaFile, parserJavaFile, encoding);
			codeQualityHelper.removeDuplicateBitsets(parserJavaFile, encoding);
			codeQualityHelper.removeDuplicateDFAs(parserJavaFile, encoding);
		}
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
		if (getOptions().isClassSplitting()) {
			try {
				splitLexerClassFile(lexerJavaFile, encoding);
Solution content
			String absoluteParserGrammarFileName, final Charset encoding) {
		String lexerJavaFile = absoluteLexerGrammarFileName.replaceAll("\\.g$", getLexerFileNameSuffix());
		String parserJavaFile = absoluteParserGrammarFileName.replaceAll("\\.g$", getParserFileNameSuffix());
		improveCodeQuality(lexerJavaFile, parserJavaFile, encoding);
		if (getOptions().isClassSplitting()) {
			try {
				splitLexerClassFile(lexerJavaFile, encoding);
File
AbstractAntlrGeneratorFragment.java
Developer's decision
Version 1
Kind of conflict
If statement
Method invocation
Chunk
Conflicting content
import org.eclipse.xtext.Group;
import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.RuleCall;
<<<<<<< HEAD
=======
import org.eclipse.xtext.RuleNames;
import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.util.XtextSwitch;
import org.eclipse.xtext.xbase.lib.Functions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xtext.generator.normalization.OriginalElement;
import org.eclipse.xtext.xtext.generator.normalization.OriginalGrammar;
import org.eclipse.xtext.xtext.generator.normalization.RuleWithParameterValues;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70

/**
 * @author Sebastian Zarnekow - Initial contribution and API
Solution content
/**
import org.eclipse.xtext.Group;
import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.RuleCall;

 * @author Sebastian Zarnekow - Initial contribution and API
File
AntlrGrammarGenUtil.java
Developer's decision
Version 1
Kind of conflict
Import
Chunk
Conflicting content
	 * @since 2.9
	 */
	public static String getRuleName(AbstractRule rule) {
<<<<<<< HEAD
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getRuleName(rule);
=======
		RuleWithParameterValues parameterValues = RuleWithParameterValues.findInEmfObject(rule);
		if (parameterValues != null) {
			return rule.getName();
		}
		RuleNames ruleNames = RuleNames.getRuleNames(rule);
		return ruleNames.getAntlrRuleName(rule);
	}
	
	/**
	 * @since 2.9
	 */
	public static String getEntryRuleName(ParserRule rule) {
		RuleWithParameterValues parameterValues = RuleWithParameterValues.findInEmfObject(rule);
		if (parameterValues != null) {
			if (parameterValues.getParamValues().isEmpty()) {
				AbstractRule original = parameterValues.getOriginal();
				RuleNames ruleNames = RuleNames.getRuleNames(original);
				return "entry" + Strings.toFirstUpper(ruleNames.getAntlrRuleName(original));
			}
			return null;
		} else {
			RuleNames ruleNames = RuleNames.getRuleNames(rule);
			return "entry" + Strings.toFirstUpper(ruleNames.getAntlrRuleName(rule));
		}
	}
	
	/**
	 * @since 2.9
	 */
	public static boolean isValidEntryRule(ParserRule rule) {
		if (rule.isFragment()) {
			return false;
		}
		RuleWithParameterValues parameterValues = RuleWithParameterValues.findInEmfObject(rule);
		if (parameterValues.getParamValues().isEmpty()) {
			return true;
		}
		return false;
	}
	
	/**
	 * @since 2.9
	 */
	@SuppressWarnings("unchecked")
	public static  T getOriginalElement(T obj) {
		if (obj instanceof AbstractRule) {
			AbstractRule result = RuleWithParameterValues.tryGetOriginalRule((AbstractRule) obj);
			if (result != null)
				return (T) result;
			return obj;
		}
		if (obj instanceof Grammar) {
			OriginalGrammar originalGrammar = OriginalGrammar.findInEmfObject(obj);
			return (T) originalGrammar.getOriginal();
		}
		if (obj instanceof AbstractElement) {
			OriginalElement original = OriginalElement.findInEmfObject(obj);
			return (T) original.getOriginal();
		}
		throw new IllegalArgumentException(String.valueOf(obj));
	}
	
	/**
	 * @since 2.9
	 */
	public static int getParameterConfig(ParserRule rule) {
		return RuleWithParameterValues.getParamConfig(rule);
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
	}
	
	/**
Solution content
	 * @since 2.9
	 */
	public static String getRuleName(AbstractRule rule) {
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getRuleName(rule);
	}
	
	/**
	 * @since 2.9
	 */
	public static String getEntryRuleName(ParserRule rule) {
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getEntryRuleName(rule);
	}
	
	/**
	 * @since 2.9
	 */
	public static boolean isValidEntryRule(ParserRule rule) {
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.isValidEntryRule(rule);
	}
	/**
	 * @since 2.9
	 */
	@SuppressWarnings("unchecked")
	public static  T getOriginalElement(T obj) {
		return (T) org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getOriginalElement(obj);
	}

	/**
	 * @since 2.9
	 */
	public static int getParameterConfig(ParserRule rule) {
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getParameterConfig(rule);
	}
	
	/**
File
AntlrGrammarGenUtil.java
Developer's decision
Manual
Kind of conflict
Annotation
Comment
If statement
Method declaration
Method invocation
Method signature
Return statement
Variable
Chunk
Conflicting content
	 * @since 2.9
	 */
	public static String getParameterList(ParserRule rule, Boolean skipCurrent) {
<<<<<<< HEAD
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getParameterList(rule, skipCurrent);
=======
		boolean currentAsParam = rule.isFragment() && !GrammarUtil.isDatatypeRule(getOriginalElement(rule));
		if ((skipCurrent || !currentAsParam) && rule.getParameters().isEmpty()) {
			return "";
		}
		StringBuilder result = new StringBuilder();
		result.append("[");
		if (!skipCurrent) {
			if (currentAsParam) {
				result.append("EObject in_current");
				if (!rule.getParameters().isEmpty()) {
					result.append(", ");
				}
			}
		}
		Joiner.on(", ").appendTo(result, Iterables.transform(rule.getParameters(), new Function() {
			@Override
			public String apply(Parameter input) {
				return "boolean p_" + input.getName();
			}
		}));
		result.append("] ");
		return result.toString();
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
	}
	
	/**
Solution content
	 * @since 2.9
	 */
	public static String getParameterList(ParserRule rule, Boolean skipCurrent) {
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getParameterList(rule, skipCurrent);
	}
	
	/**
File
AntlrGrammarGenUtil.java
Developer's decision
Version 1
Kind of conflict
If statement
Method invocation
Return statement
Variable
Chunk
Conflicting content
	 * @since 2.9
	 */
	public static String getArgumentList(final RuleCall ruleCall, final Boolean skipCurrent) {
<<<<<<< HEAD
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getArgumentList(ruleCall, skipCurrent);
=======
		final List arguments = ruleCall.getArguments();
		AbstractRule abstractRule = ruleCall.getRule();
		boolean needsCurrent = !skipCurrent && GrammarUtil.isEObjectFragmentRule(abstractRule) && !GrammarUtil.isDatatypeRule(getOriginalElement(abstractRule));
		if (arguments.isEmpty()) {
			if (needsCurrent) {
				return "[$current]";
			}
			return "";
		}
		ParserRule rule = (ParserRule) abstractRule;
		StringBuilder result = new StringBuilder();
		result.append("[");
		if (needsCurrent) {
			result.append("$current, ");
		}
		Joiner.on(", ").appendTo(result, Iterables.transform(rule.getParameters(), new Function() {
			@Override
			public String apply(Parameter input) {
				for(NamedArgument argument: arguments) {
					if (argument.getParameter() == input) {
						return conditionToAntlr(argument.getValue(), true);
					}
				}
				throw new IllegalStateException("Cannot find argument for parameter: " + input.getName());
			}
		}));
		result.append("]");
		return result.toString();
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
	}
	
	/**
Solution content
	 * @since 2.9
	 */
	public static String getArgumentList(final RuleCall ruleCall, final Boolean skipCurrent) {
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getArgumentList(ruleCall, skipCurrent);
	}
	
	/**
File
AntlrGrammarGenUtil.java
Developer's decision
Version 1
Kind of conflict
Cast expression
If statement
Method invocation
Return statement
Variable
Chunk
Conflicting content
	 * @since 2.9
	 */
	public static String getQualifiedNameAsString(RuleCall ruleCall) {
<<<<<<< HEAD
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getQualifiedNameAsString(ruleCall);
=======
		AbstractRule rule = getOriginalElement(ruleCall).getRule();
		String result = RuleNames.getRuleNames(rule).getQualifiedName(rule);
		return '"' + result + '"';
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
	}

	public static String toAntlrString(String string) {
Solution content
	 * @since 2.9
	 */
	public static String getQualifiedNameAsString(RuleCall ruleCall) {
		return org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.getQualifiedNameAsString(ruleCall);
	}
	
	public static String toAntlrString(String string) {
File
AntlrGrammarGenUtil.java
Developer's decision
Version 1
Kind of conflict
Method invocation
Return statement
Variable
Chunk
Conflicting content
package org.eclipse.xtext.generator.parser.antlr;

public class AntlrOptions {
<<<<<<< HEAD

	org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions delegate = new org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions();
=======
	private boolean backtrack = false;
	private boolean backtrackLexer = false;
	private boolean memoize = false;
	private int k = -1;
	private boolean ignoreCase = false;
	private boolean classSplitting = false;
	private int fieldsPerClass = AntlrParserSplitter.FIELDS_PER_CLASS;
	private int methodsPerClass = PartialClassExtractor.METHODS_PER_CLASS;
	private boolean skipUnusedRules = false;
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70

	public boolean isBacktrack() {
		return delegate.isBacktrack();
Solution content
package org.eclipse.xtext.generator.parser.antlr;

public class AntlrOptions {
	org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions delegate = new org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions();

	public boolean isBacktrack() {
		return delegate.isBacktrack();
File
AntlrOptions.java
Developer's decision
Version 1
Kind of conflict
Attribute
Method invocation
Chunk
Conflicting content
import com.google.common.collect.Sets;

public class AntlrCodeQualityHelper {
<<<<<<< HEAD
=======

	private String keepBitsets;
	private String keptName;
	private boolean stripAllComments = false;
	private boolean enabled = true;
	
	/**
	 * Optionally set a pattern for bitset names that should not be replaced by a simple variant.
	 */
	public void setKeepBitsets(String keepBitsets) {
		this.keepBitsets = keepBitsets;
	}
	
	/**
	 * Optionally set a replacement string for the kept bitset names.
	 */
	public void setKeptName(String keptName) {
		this.keptName = keptName;
	}
	
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
	
	/**
	 * Remove all unnecessary comments from the java code that was produced by Antlr
Solution content
	/**
import com.google.common.collect.Sets;

public class AntlrCodeQualityHelper {

	protected String stripUnnecessaryComments(String fileContent) {
		fileContent = fileContent.replaceAll(
				"(?m)^(\\s+)// .*/(\\w+\\.g:.*)$",
				"$1// $2");
		fileContent = fileContent.replaceAll(
				"(public String getGrammarFileName\\(\\) \\{ return \").*/(\\w+\\.g)(\"; \\})",
				"$1$2$3");
		return fileContent;
	}


	protected String stripAllComments(String fileContent) {
		fileContent = fileContent.replaceAll("(?m)^\\s+//.*$\\R", "");
		return fileContent;
	}

	/**
	 * Remove all unnecessary comments from a lexer or parser file
	 */
	public String stripUnnecessaryComments(String javaContent, AntlrOptions options) {
		if (!options.isOptimizeCodeQuality()) {
			return javaContent;
		}
		if (options.isStripAllComments()) {
			return stripAllComments(javaContent);
		} else {
			return stripUnnecessaryComments(javaContent);
		}
	}

	// public static final BitSet FOLLOW_Symbol_in_synpred90_InternalMyDslParser17129 = new BitSet(new
	// long[]{0x0000000000000002L});
	// ...........................1- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2-
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	public static final Pattern followsetPattern = Pattern.compile(
			"\\s+public static final BitSet (FOLLOW_\\w+) = (.*);$", Pattern.MULTILINE);

	public static final Pattern dfaStringPattern = Pattern.compile(
			"\\s+static final String\\[?]? (DFA\\d+_\\w+) =\\s+([^;]*);$", Pattern.MULTILINE | Pattern.DOTALL);

	public static final Pattern dfaUnpackPattern = Pattern.compile(
			"\\s+static final (?:short|char)\\[?]?\\[?]? (DFA\\d+_\\w+) = (\\w+(\\.\\w+)?\\(dfa_\\d+s\\));$", Pattern.MULTILINE | Pattern.DOTALL);
	 * Remove duplicate bitset declarations to reduce the size of the static initializer but keep the bitsets
	 * that match the given pattern with a normalized name.
	 */
	public String removeDuplicateBitsets(String javaContent, AntlrOptions options) {
		if (!options.isOptimizeCodeQuality()) {
			return javaContent;
		}

		return removeDuplicateFields(javaContent, followsetPattern, 1, 2, "\\bFOLLOW_\\w+\\b", "FOLLOW_%d", options.getKeptBitSetsPattern(), options.getKeptBitSetName());
	}

	/**
	 *
	 * @param content
	 * @param lookupPattern the regular expression pattern that we try to find
	 * @param synName
	 * @param keepPattern
	 * @param keptName
	 * @return
	 */
	public static String removeDuplicateFields(String content, Pattern lookupPattern, int origNameGroup, int initGroup, String rawClientPattern, String synName, String keepPattern, String keptName) {
		Pattern fieldnamesToKeep = null;
		Set doNotReplace = Sets.newHashSet();
		if (keepPattern != null) {
			fieldnamesToKeep = Pattern.compile(keepPattern);
		}
		StringBuilder newContent = new StringBuilder(content.length());
		Matcher matcher = lookupPattern.matcher(content);
		int offset = 0;
		Map fields = Maps.newHashMap();
		Map namesToReplace = Maps.newHashMap();
		while (matcher.find(offset)) {
			String originalFieldName = matcher.group(origNameGroup);
			String synthesizedFieldName = String.format(synName, fields.size() + 1);
			String initializer = matcher.group(initGroup);
			String existing = putIfAbsent(fields, initializer, synthesizedFieldName);
			if (existing == null) {
				existing = synthesizedFieldName;
				newContent.append(content, offset, matcher.start(origNameGroup));
				newContent.append(synthesizedFieldName);
				newContent.append(" = ");
				newContent.append(initializer);
				newContent.append(content, matcher.end(initGroup), matcher.end());
			} else {
				newContent.append(content, offset, matcher.start());
			}
			namesToReplace.put(originalFieldName, existing);
			if (fieldnamesToKeep != null) {
				Matcher keepMatcher = fieldnamesToKeep.matcher(originalFieldName);
				if (keepMatcher.matches()) {
					newContent.append(content, offset, matcher.start(origNameGroup));
					String simpleName = keptName != null ? keepMatcher.replaceFirst(keptName) : originalFieldName;
					newContent.append(simpleName);
					doNotReplace.add(simpleName);
					newContent.append(" = ");
					newContent.append(existing);
				}
			}
			offset = matcher.end();
		}
		newContent.append(content, offset, content.length());
		content = newContent.toString();
		newContent = new StringBuilder(content.length());
		Pattern clientPattern = Pattern.compile(rawClientPattern);
		Matcher clientMatcher = clientPattern.matcher(content);
		doNotReplace.addAll(fields.values());
		offset = 0;
		while (clientMatcher.find(offset)) {
			String replaceMe = clientMatcher.group();
			String replaceBy = namesToReplace.get(replaceMe);
			if (replaceBy == null) {
				replaceBy = replaceMe;
			}
			newContent.append(content, offset, clientMatcher.start());
			newContent.append(replaceBy);
			offset = clientMatcher.end();
		}
		newContent.append(content, offset, content.length());
		return newContent.toString();
	}

	private static  V putIfAbsent(Map map, K key, V value) {
        V v = map.get(key);
        if (v == null) {
            v = map.put(key, value);
        }
        return v;
    }

	private static final Pattern dfaPattern = Pattern.compile(
			"static final short\\[]\\[] (DFA\\d+_transition);\\s+static \\{[^{]*\\{[^}]*\\}[^}]*\\}", Pattern.DOTALL);

	private static final String replacement= "static final short[][] $1 = unpackEncodedStringArray($1S);";

	/**
	 * Remove duplicate bitset declarations to reduce the size of the static initializer but keep the bitsets
	 * that match the given pattern with a normalized name.
	 */
	public String removeDuplicateDFAs(String content, AntlrOptions options) {
		if (!options.isOptimizeCodeQuality()) {
			return content;
		}
		String newContent = dfaPattern.matcher(content).replaceAll(replacement);
		newContent = removeDuplicateFields(
				newContent, dfaStringPattern, 1, 2, "\\bDFA\\d+_\\w+\\b", "dfa_%ds", null, null);
		newContent = removeDuplicateFields(
				newContent, dfaUnpackPattern, 1, 2, "\\bDFA\\d+_\\w+\\b", "dfa_%d", null, null);
		return newContent;
	}

}
File
AntlrCodeQualityHelper.java
Developer's decision
Manual
Kind of conflict
Attribute
Comment
Method declaration
Chunk
Conflicting content
	 */
		javaFileContent = javaFileContent.replaceAll(
				"(public String getGrammarFileName\\(\\) \\{ return \").*/(\\w+\\.g)(\"; \\})",
				"$1$2$3");
<<<<<<< HEAD
		return javaFileContent;
=======
		return fileContent;
	}

	protected void stripAllComments(IXtextGeneratorFileSystemAccess fsa, String javaFile) {
		String content = fsa.readTextFile(javaFile).toString();
		content = stripAllComments(content);
		fsa.generateFile(javaFile, content);
	}
	
	protected String stripAllComments(String fileContent) {
		fileContent = fileContent.replaceAll("(?m)^\\s+//.*$\\R", "");
		return fileContent;
	}
	
	/**
	 * Remove all unnecessary comments from the lexer and the parser
	public void stripUnnecessaryComments(IXtextGeneratorFileSystemAccess fsa, String lexer, String parser) {
		if (!enabled) {
			return;
		}
		stripUnnecessaryComments(fsa, lexer);
		stripUnnecessaryComments(fsa, parser);
		if (stripAllComments) {
			stripAllComments(fsa, parser);
			stripAllComments(fsa, lexer);
		}
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
	}

	// public static final BitSet FOLLOW_Symbol_in_synpred90_InternalMyDslParser17129 = new BitSet(new
Solution content
				"(public String getGrammarFileName\\(\\) \\{ return \").*/(\\w+\\.g)(\"; \\})",
				"$1$2$3");
		return fileContent;
	}


	protected String stripAllComments(String fileContent) {
		fileContent = fileContent.replaceAll("(?m)^\\s+//.*$\\R", "");
		return fileContent;
	}

	/**
	 * Remove all unnecessary comments from a lexer or parser file
	 */
	public String stripUnnecessaryComments(String javaContent, AntlrOptions options) {
		if (!options.isOptimizeCodeQuality()) {
			return javaContent;
		}
		if (options.isStripAllComments()) {
			return stripAllComments(javaContent);
		} else {
			return stripUnnecessaryComments(javaContent);
		}
	}

	// public static final BitSet FOLLOW_Symbol_in_synpred90_InternalMyDslParser17129 = new BitSet(new
File
AntlrCodeQualityHelper.java
Developer's decision
Manual
Kind of conflict
Comment
If statement
Method declaration
Method invocation
Method signature
Return statement
Variable
Chunk
Conflicting content
	// long[]{0x0000000000000002L});
	// ...........................1- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2-
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<<<<<<< HEAD
	private static final Pattern bitsetPattern = Pattern.compile("^\\s+public static final BitSet (FOLLOW_\\w+) = (.*);$", Pattern.MULTILINE);

=======
	public static final Pattern followsetPattern = Pattern.compile(
			"\\s+public static final BitSet (FOLLOW_\\w+) = (.*);$", Pattern.MULTILINE);
	
	public static final Pattern dfaStringPattern = Pattern.compile(
			"\\s+static final String\\[?]? (DFA\\d+_\\w+) =\\s+([^;]*);$", Pattern.MULTILINE | Pattern.DOTALL);
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
	
	public static final Pattern dfaUnpackPattern = Pattern.compile(
			"\\s+static final (?:short|char)\\[?]?\\[?]? (DFA\\d+_\\w+) = (\\w+(\\.\\w+)?\\(dfa_\\d+s\\));$", Pattern.MULTILINE | Pattern.DOTALL);
Solution content
	// long[]{0x0000000000000002L});
	// ...........................1- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2-
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	public static final Pattern followsetPattern = Pattern.compile(
			"\\s+public static final BitSet (FOLLOW_\\w+) = (.*);$", Pattern.MULTILINE);

	public static final Pattern dfaStringPattern = Pattern.compile(
			"\\s+static final String\\[?]? (DFA\\d+_\\w+) =\\s+([^;]*);$", Pattern.MULTILINE | Pattern.DOTALL);

	public static final Pattern dfaUnpackPattern = Pattern.compile(
			"\\s+static final (?:short|char)\\[?]?\\[?]? (DFA\\d+_\\w+) = (\\w+(\\.\\w+)?\\(dfa_\\d+s\\));$", Pattern.MULTILINE | Pattern.DOTALL);
File
AntlrCodeQualityHelper.java
Developer's decision
Version 2
Kind of conflict
Attribute
Method invocation
Chunk
Conflicting content
	public static CharSequence removeDuplicateFields(CharSequence content, Pattern lookupPattern, int origNameGroup, int initGroup, String rawClientPattern, String synName, String keepPattern, String keptName) {
		Pattern fieldnamesToKeep = null;
		Set doNotReplace = Sets.newHashSet();
<<<<<<< HEAD
		if (options.getKeptBitSetsPattern() != null) {
			bitsetsToKeep = Pattern.compile(options.getKeptBitSetsPattern());
		}
		StringBuilder newContent = new StringBuilder(javaFileContent.length());
		Matcher matcher = bitsetPattern.matcher(javaFileContent);
=======
		if (keepPattern != null) {
			fieldnamesToKeep = Pattern.compile(keepPattern);
		}
		StringBuilder newContent = new StringBuilder(content.length());
		Matcher matcher = lookupPattern.matcher(content);
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
		int offset = 0;
		Map fields = Maps.newHashMap();
		Map namesToReplace = Maps.newHashMap();
Solution content
		Pattern fieldnamesToKeep = null;
		Set doNotReplace = Sets.newHashSet();
		if (keepPattern != null) {
			fieldnamesToKeep = Pattern.compile(keepPattern);
		}
		StringBuilder newContent = new StringBuilder(content.length());
		Matcher matcher = lookupPattern.matcher(content);
		int offset = 0;
		Map fields = Maps.newHashMap();
		Map namesToReplace = Maps.newHashMap();
File
AntlrCodeQualityHelper.java
Developer's decision
Version 2
Kind of conflict
If statement
Method invocation
Variable
Chunk
Conflicting content
			String existing = putIfAbsent(fields, initializer, synthesizedFieldName);
			if (existing == null) {
				existing = synthesizedFieldName;
<<<<<<< HEAD
				newContent.append(javaFileContent, offset, matcher.start(1));
=======
				newContent.append(content, offset, matcher.start(origNameGroup));
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
				newContent.append(synthesizedFieldName);
				newContent.append(" = ");
				newContent.append(initializer);
Solution content
			String existing = putIfAbsent(fields, initializer, synthesizedFieldName);
			if (existing == null) {
				existing = synthesizedFieldName;
				newContent.append(content, offset, matcher.start(origNameGroup));
				newContent.append(synthesizedFieldName);
				newContent.append(" = ");
				newContent.append(initializer);
File
AntlrCodeQualityHelper.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Chunk
Conflicting content
			if (fieldnamesToKeep != null) {
				Matcher keepMatcher = fieldnamesToKeep.matcher(originalFieldName);
				if (keepMatcher.matches()) {
<<<<<<< HEAD
					newContent.append(javaFileContent, offset, matcher.start(1));
					String simpleName = options.getKeptBitSetName() != null ? keepMatcher.replaceFirst(options.getKeptBitSetName()) : originalFieldName;
=======
					newContent.append(content, offset, matcher.start(origNameGroup));
					String simpleName = keptName != null ? keepMatcher.replaceFirst(keptName) : originalFieldName;
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
					newContent.append(simpleName);
					doNotReplace.add(simpleName);
					newContent.append(" = ");
Solution content
			if (fieldnamesToKeep != null) {
				Matcher keepMatcher = fieldnamesToKeep.matcher(originalFieldName);
				if (keepMatcher.matches()) {
					newContent.append(content, offset, matcher.start(origNameGroup));
					String simpleName = keptName != null ? keepMatcher.replaceFirst(keptName) : originalFieldName;
					newContent.append(simpleName);
					doNotReplace.add(simpleName);
					newContent.append(" = ");
File
AntlrCodeQualityHelper.java
Developer's decision
Version 2
Kind of conflict
Attribute
Method invocation
Variable
Chunk
Conflicting content
			}
			offset = matcher.end();
		}
<<<<<<< HEAD
		newContent.append(javaFileContent, offset, javaFileContent.length());
		javaFileContent = newContent.toString();
		newContent = new StringBuilder(javaFileContent.length());
		String rawFollowPattern = "\\bFOLLOW_\\w+\\b";
		Pattern followPattern = Pattern.compile(rawFollowPattern);
		Matcher followMatcher = followPattern.matcher(javaFileContent);
		doNotReplace.addAll(bitsets.values());
=======
		newContent.append(content, offset, content.length());
		content = newContent.toString();
		newContent = new StringBuilder(content.length());
		Pattern clientPattern = Pattern.compile(rawClientPattern);
		Matcher clientMatcher = clientPattern.matcher(content);
		doNotReplace.addAll(fields.values());
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
		offset = 0;
		while (clientMatcher.find(offset)) {
			String replaceMe = clientMatcher.group();
Solution content
			String replaceMe = clientMatcher.group();
			}
			offset = matcher.end();
		}
		newContent.append(content, offset, content.length());
		content = newContent.toString();
		newContent = new StringBuilder(content.length());
		Pattern clientPattern = Pattern.compile(rawClientPattern);
		Matcher clientMatcher = clientPattern.matcher(content);
		doNotReplace.addAll(fields.values());
		offset = 0;
		while (clientMatcher.find(offset)) {
File
AntlrCodeQualityHelper.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Variable
Chunk
Conflicting content
			if (replaceBy == null) {
				replaceBy = replaceMe;
			}
<<<<<<< HEAD
			newContent.append(javaFileContent, offset, followMatcher.start());
=======
			newContent.append(content, offset, clientMatcher.start());
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
			newContent.append(replaceBy);
			offset = clientMatcher.end();
		}
Solution content
			if (replaceBy == null) {
				replaceBy = replaceMe;
			}
			newContent.append(content, offset, clientMatcher.start());
			newContent.append(replaceBy);
			offset = clientMatcher.end();
		}
File
AntlrCodeQualityHelper.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Chunk
Conflicting content
			newContent.append(replaceBy);
			offset = clientMatcher.end();
		}
<<<<<<< HEAD
		newContent.append(javaFileContent, offset, javaFileContent.length());
		return newContent.toString();
=======
		newContent.append(content, offset, content.length());
		return newContent;
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
	}
	
	private static  V putIfAbsent(Map map, K key, V value) {
Solution content
			newContent.append(replaceBy);
			offset = clientMatcher.end();
		}
		newContent.append(content, offset, content.length());
		return newContent.toString();
	}

	private static  V putIfAbsent(Map map, K key, V value) {
File
AntlrCodeQualityHelper.java
Developer's decision
Combination
Kind of conflict
Method invocation
Return statement
Variable
Chunk
Conflicting content
    final String lexerJavaFile = lexerGrammarFileName.replaceAll("\\.g$", _lexerFileNameSuffix);
    String _parserFileNameSuffix = this.getParserFileNameSuffix();
    final String parserJavaFile = parserGrammarFileName.replaceAll("\\.g$", _parserFileNameSuffix);
<<<<<<< HEAD
    this.improveCodeQuality(fsa, lexerJavaFile, parserJavaFile);
=======
    if ((this.codeQualityHelper != null)) {
      this.codeQualityHelper.stripUnnecessaryComments(fsa, lexerJavaFile, parserJavaFile);
      this.codeQualityHelper.removeDuplicateBitsets(fsa, parserJavaFile);
      this.codeQualityHelper.removeDuplicateDFAs(fsa, parserJavaFile);
    }
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
    AntlrOptions _options = this.getOptions();
    boolean _isClassSplitting = _options.isClassSplitting();
    if (_isClassSplitting) {
Solution content
    final String lexerJavaFile = lexerGrammarFileName.replaceAll("\\.g$", _lexerFileNameSuffix);
    String _parserFileNameSuffix = this.getParserFileNameSuffix();
    final String parserJavaFile = parserGrammarFileName.replaceAll("\\.g$", _parserFileNameSuffix);
    this.improveCodeQuality(fsa, lexerJavaFile, parserJavaFile);
    AntlrOptions _options = this.getOptions();
    boolean _isClassSplitting = _options.isClassSplitting();
    if (_isClassSplitting) {
File
AbstractAntlrGeneratorFragment2.java
Developer's decision
Version 1
Kind of conflict
If statement
Method invocation
Chunk
Conflicting content
  
  private int methodsPerClass = PartialClassExtractor.METHODS_PER_CLASS;
  
<<<<<<< HEAD
  private boolean optimizeCodeQuality = true;
  
  private String keptBitSetsPattern;
  
  private String keptBitSetName;
  
  public void setFieldsPerClass(final String fieldsPerClass) {
    int _parseInt = Integer.parseInt(fieldsPerClass);
    this.fieldsPerClass = _parseInt;
  }
  
  public void setMethodsPerClass(final String methodsPerClass) {
    int _parseInt = Integer.parseInt(methodsPerClass);
    this.methodsPerClass = _parseInt;
  }
  
  public void setKAsString(final String k) {
    int _parseInt = Integer.parseInt(k);
    this.k = _parseInt;
  }
=======
  private boolean skipUnusedRules = false;
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
  
  @Pure
  public boolean isBacktrack() {
Solution content
  
  private int methodsPerClass = PartialClassExtractor.METHODS_PER_CLASS;
  
  private boolean skipUnusedRules = false;
  
  private boolean optimizeCodeQuality = true;
  
  private boolean stripAllComments = false;
  
  private String keptBitSetsPattern;
  
  private String keptBitSetName;
  
  public void setFieldsPerClass(final String fieldsPerClass) {
    int _parseInt = Integer.parseInt(fieldsPerClass);
    this.fieldsPerClass = _parseInt;
  }
  
  public void setMethodsPerClass(final String methodsPerClass) {
    int _parseInt = Integer.parseInt(methodsPerClass);
    this.methodsPerClass = _parseInt;
  }
  
  public void setKAsString(final String k) {
    int _parseInt = Integer.parseInt(k);
    this.k = _parseInt;
  }
  
  @Pure
  public boolean isBacktrack() {
File
AntlrOptions.java
Developer's decision
Manual
Kind of conflict
Attribute
Method declaration
Chunk
Conflicting content
  }
  
  @Pure
<<<<<<< HEAD
  public boolean isOptimizeCodeQuality() {
    return this.optimizeCodeQuality;
  }
  
  public void setOptimizeCodeQuality(final boolean optimizeCodeQuality) {
    this.optimizeCodeQuality = optimizeCodeQuality;
  }
  
  @Pure
  public String getKeptBitSetsPattern() {
    return this.keptBitSetsPattern;
  }
  
  public void setKeptBitSetsPattern(final String keptBitSetsPattern) {
    this.keptBitSetsPattern = keptBitSetsPattern;
  }
  
  @Pure
  public String getKeptBitSetName() {
    return this.keptBitSetName;
  }
  
  public void setKeptBitSetName(final String keptBitSetName) {
    this.keptBitSetName = keptBitSetName;
=======
  public boolean isSkipUnusedRules() {
    return this.skipUnusedRules;
  }
  
  public void setSkipUnusedRules(final boolean skipUnusedRules) {
    this.skipUnusedRules = skipUnusedRules;
>>>>>>> d12e68fa9ec4813d41485441c40c2954d4794c70
  }
}
Solution content
  }
  }
  
  @Pure
  public boolean isSkipUnusedRules() {
    return this.skipUnusedRules;
  }
  
  public void setSkipUnusedRules(final boolean skipUnusedRules) {
    this.skipUnusedRules = skipUnusedRules;
  
  @Pure
  public boolean isOptimizeCodeQuality() {
    return this.optimizeCodeQuality;
  }
  
  public void setOptimizeCodeQuality(final boolean optimizeCodeQuality) {
    this.optimizeCodeQuality = optimizeCodeQuality;
  }
  
  @Pure
  public boolean isStripAllComments() {
    return this.stripAllComments;
  }
  
  public void setStripAllComments(final boolean stripAllComments) {
    this.stripAllComments = stripAllComments;
  }
  
  @Pure
  public String getKeptBitSetsPattern() {
    return this.keptBitSetsPattern;
  }
  
  public void setKeptBitSetsPattern(final String keptBitSetsPattern) {
    this.keptBitSetsPattern = keptBitSetsPattern;
  }
  
  @Pure
  public String getKeptBitSetName() {
    return this.keptBitSetName;
  }
  
  public void setKeptBitSetName(final String keptBitSetName) {
    this.keptBitSetName = keptBitSetName;
  }
}
File
AntlrOptions.java
Developer's decision
Manual
Kind of conflict
Annotation
Attribute
Method declaration
Method signature