Clean up constructions that exists only in the unexpanded code

@param drl
@return
4736
private String cleanupExpressions(String drl) {
        // execute cleanup
        for ( final DSLMappingEntry entry : this.cleanup ) {
            drl = entry.getKeyPattern().matcher( drl ).replaceAll( entry.getValuePattern() );
        }
        return drl;
    }
1227630
private static void removeDuplicateContracts(final Class<?> type, final Set<Class<?>> contracts) {
        if (contracts.isEmpty()) {
            return;
        }

        // remove interfaces already included in common type (e.g. Number and Serializable)
        Iterator<Class<?>> it = contracts.iterator();
        while (it.hasNext()) {
            if (it.next().isAssignableFrom(type)) {
                it.remove();
            }
        }

        // remove duplicate interfaces (e.g. List already include Collection and Iterable)
        it = contracts.iterator();
        while (it.hasNext()) {
            final Class<?> current = it.next();
            for (Class<?> iface : contracts) {
                if (!current.equals(iface) && current.isAssignableFrom(iface)) {
                    it.remove();
                    break;
                }
            }
        }
    }
243916
public static EncodingResult resultForCleaneLing(final FormulaFactory f, final CleaneLing cleaneLing) {
    return new EncodingResult(f, null, cleaneLing);
  }
670707
public static CleaneLing full(final FormulaFactory f, final CleaneLingConfig config) {
        return new CleaneLing(f, SolverStyle.FULL, config);
    }
22236
public RuleConditionElement build(final RuleBuildContext context,
                                      final BaseDescr descr,
                                      final Pattern prefixPattern) {
        boolean typesafe = context.isTypesafe();
        // it must be an EvalDescr
        final EvalDescr evalDescr = (EvalDescr) descr;

        try {
            MVELDialect dialect = (MVELDialect) context.getDialect( "mvel" );

            Map<String, Declaration> decls = context.getDeclarationResolver().getDeclarations(context.getRule());
            
            AnalysisResult analysis = context.getDialect().analyzeExpression( context,
                                                                              evalDescr,
                                                                              evalDescr.getContent(),
                                                                              new BoundIdentifiers( DeclarationScopeResolver.getDeclarationClasses( decls ),
                                                                                                    context ) );

            final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
            int i = usedIdentifiers.getDeclrClasses().keySet().size();
            Declaration[] previousDeclarations = new Declaration[i];
            i = 0;
            for ( String id :  usedIdentifiers.getDeclrClasses().keySet() ) {
                previousDeclarations[i++] = decls.get( id );
            }
            Arrays.sort( previousDeclarations, SortDeclarations.instance  ); 
            
            MVELCompilationUnit unit = dialect.getMVELCompilationUnit( (String) evalDescr.getContent(),
                                                                       analysis,
                                                                       previousDeclarations,
                                                                       null,
                                                                       null,
                                                                       context,
                                                                       "drools",
                                                                       KnowledgeHelper.class,
                                                                       false,
                                                                       MVELCompilationUnit.Scope.EXPRESSION );
            final EvalCondition eval = new EvalCondition( previousDeclarations );

            MVELEvalExpression expr = new MVELEvalExpression( unit,
                                                              dialect.getId() );
            eval.setEvalExpression( KiePolicyHelper.isPolicyEnabled() ? new SafeEvalExpression(expr) : expr );

            MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" );
            data.addCompileable( eval,
                                  expr );

            expr.compile( data, context.getRule() );
            return eval;
        } catch ( final Exception e ) {
            copyErrorLocation(e, evalDescr);
            context.addError( new DescrBuildError( context.getParentDescr(),
                                                          evalDescr,
                                                          e,
                                                          "Unable to build expression for 'eval':" + e.getMessage() + " '" + evalDescr.getContent() + "'" ) );
            return null;
        } finally {
            context.setTypesafe( typesafe );
        }
    }
730586
public static List<Method> findOverriddenMethods(MethodDeclaration md) {
        final List<Method> methods = new ArrayList<Method>();
        collectOverriddenMethods(md, methods);
        return methods.isEmpty() ? Collections.<Method>emptyList() : Collections.unmodifiableList(methods);
    }
652480
public URLNormalizer removeEmptyParameters() {
        // Does it have query parameters?
        if (!url.contains("?")) {
            return this;
        }
        // It does, so proceed
        List<String> keyValues = new ArrayList<>();
        String queryString = StringUtils.substringAfter(url, "?");
        String[] params = StringUtils.split(queryString, '&');
        for (String param : params) {
            if (param.contains("=")
                    && StringUtils.isNotBlank(
                    StringUtils.substringAfter(param, "="))
                    && StringUtils.isNotBlank(
                    StringUtils.substringBefore(param, "="))) {
                keyValues.add(param);
            }
        }
        String cleanQueryString = StringUtils.join(keyValues, '&');
        if (StringUtils.isNotBlank(cleanQueryString)) {
            url = StringUtils.substringBefore(
                    url, "?") + "?" + cleanQueryString;
        }
        return this;
    }
199869
public DSLSentence copy() {
        final DSLSentence copy = new DSLSentence();

        copy.drl = getDrl();
        copy.definition = getDefinition();
        copy.values = mapCopy(getValues());

        return copy;
    }
123477
public <T> T cleanupValue(T rawValue) {
        T cleanValue;
        if (rawValue instanceof String) {
            cleanValue = (T) cleanupValue((String) rawValue);
        } else {
            cleanValue = rawValue;
        }
        return cleanValue;
    }
1291893
@SuppressWarnings({"WeakerAccess", "unused"}) // For library users
    public Searcher removeNumericRefinement(@NonNull NumericRefinement refinement) {
        if (refinement.operator == NumericRefinement.OPERATOR_UNKNOWN) {
            numericRefinements.remove(refinement.attribute);
        } else {
            NumericRefinement.checkOperatorIsValid(refinement.operator);
            final SparseArray<NumericRefinement> attributeRefinements = numericRefinements.get(refinement.attribute);
            if (attributeRefinements != null) {
                attributeRefinements.remove(refinement.operator);
            }
        }
        rebuildQueryNumericFilters();
        EventBus.getDefault().post(new NumericRefinementEvent(this, Operation.REMOVE, refinement));
        return this;
    }
353066
private static SuggestedFix.Builder addPrivateConstructor(ClassTree classTree) {
    SuggestedFix.Builder fix = SuggestedFix.builder();
    String indent = "  ";
    for (Tree member : classTree.getMembers()) {
      if (member.getKind().equals(METHOD) && !isGeneratedConstructor((MethodTree) member)) {
        fix.prefixWith(
            member,
            indent + "private " + classTree.getSimpleName() + "() {} // no instances\n" + indent);
        break;
      }
      if (!member.getKind().equals(METHOD)) {
        indent = "";
      }
    }
    return fix;
  }
754311
public StrBuilder deleteAll(final String str) {
        final int len = (str == null ? 0 : str.length());
        if (len > 0) {
            int index = indexOf(str, 0);
            while (index >= 0) {
                deleteImpl(index, index + len, len);
                index = indexOf(str, index);
            }
        }
        return this;
    }
917937
public final void synpred37_DRL5Expressions_fragment() throws RecognitionException {
		// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:653:9: ( DOT new_key )
		// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:653:10: DOT new_key
		{
		match(input,DOT,FOLLOW_DOT_in_synpred37_DRL5Expressions3821); if (state.failed) return;
		pushFollow(FOLLOW_new_key_in_synpred37_DRL5Expressions3823);
		new_key();
		state._fsp--;
		if (state.failed) return;
		}

	}
659434
public final void synpred11_DRL6Expressions_fragment() throws RecognitionException {
		// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:421:5: ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )
		// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:421:6: DOUBLE_AMPER ( fullAnnotation[null] )? operator
		{
		match(input,DOUBLE_AMPER,FOLLOW_DOUBLE_AMPER_in_synpred11_DRL6Expressions1972); if (state.failed) return;
		// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:421:19: ( fullAnnotation[null] )?
		int alt100=2;
		int LA100_0 = input.LA(1);
		if ( (LA100_0==AT) ) {
			alt100=1;
		}
		switch (alt100) {
			case 1 :
				// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:421:19: fullAnnotation[null]
				{
				pushFollow(FOLLOW_fullAnnotation_in_synpred11_DRL6Expressions1974);
				fullAnnotation(null);
				state._fsp--;
				if (state.failed) return;
				}
				break;

		}

		pushFollow(FOLLOW_operator_in_synpred11_DRL6Expressions1978);
		operator();
		state._fsp--;
		if (state.failed) return;
		}

	}
1112514
public final void synpred14_DRL6Expressions_fragment() throws RecognitionException {
		// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:472:11: ( PLUS | MINUS )
		// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:
		{
		if ( input.LA(1)==MINUS||input.LA(1)==PLUS ) {
			input.consume();
			state.errorRecovery=false;
			state.failed=false;
		}
		else {
			if (state.backtracking>0) {state.failed=true; return;}
			MismatchedSetException mse = new MismatchedSetException(null,input);
			throw mse;
		}
		}

	}
351601
public org.inferred.freebuilder.processor.property.Property.Builder clearAccessorAnnotations() {
    if (accessorAnnotations instanceof ImmutableList) {
      accessorAnnotations = ImmutableList.of();
    } else {
      accessorAnnotations.clear();
    }
    return (org.inferred.freebuilder.processor.property.Property.Builder) this;
  }
730966
public RuleModel getSimpleRuleModel(final String drl) {
        final RuleModel rm = new RuleModel();
        rm.setPackageName(PackageNameParser.parsePackageName(drl));
        rm.setImports(ImportsParser.parseImports(drl));

        final Pattern rulePattern = Pattern.compile(".*\\s?rule\\s+(.+?)\\s+.*",
                                                    Pattern.DOTALL);
        final Pattern lhsPattern = Pattern.compile(".*\\s+when\\s+(.+?)\\s+then.*",
                                                   Pattern.DOTALL);
        final Pattern rhsPattern = Pattern.compile(".*\\s+then\\s+(.+?)\\s+end.*",
                                                   Pattern.DOTALL);

        final Matcher ruleMatcher = rulePattern.matcher(drl);
        if (ruleMatcher.matches()) {
            String name = ruleMatcher.group(1);
            if (name.startsWith("\"")) {
                name = name.substring(1);
            }
            if (name.endsWith("\"")) {
                name = name.substring(0,
                                      name.length() - 1);
            }
            rm.name = name;
        }

        final Matcher lhsMatcher = lhsPattern.matcher(drl);
        if (lhsMatcher.matches()) {
            final FreeFormLine lhs = new FreeFormLine();
            lhs.setText(lhsMatcher.group(1) == null ? "" : lhsMatcher.group(1).trim());
            rm.addLhsItem(lhs);
        }

        final Matcher rhsMatcher = rhsPattern.matcher(drl);
        if (rhsMatcher.matches()) {
            final FreeFormLine rhs = new FreeFormLine();
            rhs.setText(rhsMatcher.group(1) == null ? "" : rhsMatcher.group(1).trim());
            rm.addRhsItem(rhs);
        }

        return rm;
    }