This method transforms the list of instrument types into a
ByteMan rule script.

@param name The instrumentation rules name
@param types The instrument types
@param version The optional version
@return The rule script
519435
public String transform(String name, Instrumentation types, String version) {
        StringBuilder builder = new StringBuilder();

        builder.append(types.isCompile() ? "COMPILE\r\n" : "NOCOMPILE\r\n");

        for (int ruleno = 0; ruleno < types.getRules().size(); ruleno++) {
            InstrumentRule r = types.getRules().get(ruleno);

            if (r.getClass() == JVM.class) {
                JVM rule = (JVM) r;

                // Check version
                if (!rule.isVersionValid(version)) {
                    continue;
                }

                builder.append("\r\n");

                builder.append("RULE ");
                builder.append(name);
                builder.append('(');
                builder.append(ruleno + 1);
                builder.append(") ");
                builder.append(rule.getRuleName());
                builder.append("\r\n");

                if (rule.getClassName() != null) {
                    builder.append("CLASS ");
                    builder.append(rule.getClassName());
                    builder.append("\r\n");
                } else if (rule.getInterfaceName() != null) {
                    builder.append("INTERFACE ");
                    builder.append(rule.getInterfaceName());
                    builder.append("\r\n");
                }

                builder.append("METHOD ");
                builder.append(rule.getMethodName());

                // Check if single parameter is "*", representing 'any' parameters
                if (rule.getParameterTypes().size() != 1 || !rule.getParameterTypes().get(0).equals("*")) {
                    builder.append('(');

                    for (int i = 0; i < rule.getParameterTypes().size(); i++) {
                        if (i > 0) {
                            builder.append(',');
                        }
                        builder.append(rule.getParameterTypes().get(i));
                    }

                    builder.append(')');
                }

                builder.append("\r\n");

                builder.append("HELPER ");
                if (rule.getHelper() == null) {
                    builder.append(RuleHelper.class.getName());
                } else {
                    builder.append(rule.getHelper());
                }
                builder.append("\r\n");

                builder.append("AT ");
                builder.append(rule.getLocation());
                builder.append("\r\n");

                if (rule.isCompile() != types.isCompile()) {
                    builder.append(rule.isCompile() ? "COMPILE\r\n" : "NOCOMPILE\r\n");
                }

                if (!rule.getBinds().isEmpty()) {
                    builder.append("BIND ");

                    for (int i = 0; i < rule.getBinds().size(); i++) {
                        InstrumentBind bind = rule.getBinds().get(i);
                        if (i > 0) {
                            builder.append("     ");
                        }
                        builder.append(bind.getName());
                        builder.append(" : ");
                        builder.append(bind.getType());
                        builder.append(" = ");
                        builder.append(bind.getExpression());
                        builder.append(";\r\n");
                    }
                }

                builder.append("IF ");
                if (rule.getCondition() == null) {
                    builder.append("TRUE");
                } else {
                    builder.append(rule.getCondition());
                }
                builder.append("\r\n");

                builder.append("DO\r\n");

                for (int i = 0; i < rule.getActions().size(); i++) {
                    InstrumentAction action = rule.getActions().get(i);

                    builder.append("  ");
                    InstrumentActionTransformer transformer = transformers.get(action.getClass());

                    if (transformer != null) {
                        builder.append(transformer.convertToRuleAction(rule.getActions().get(i)));
                        if (i < rule.getActions().size() - 1) {
                            builder.append(";");
                        }
                        builder.append("\r\n");
                    } else {
                        System.err.println("Transformer for action '" + action.getClass() + "' not found");
                    }
                }

                builder.append("ENDRULE\r\n\r\n");
            }
        }

        return builder.toString();
    }
922827
def instrument(type, name, opts = {})
      txn     = ::HeimdallApm::TransactionManager.current
      segment = ::HeimdallApm::Segment.new(type, name)
      txn.start_segment(segment)

      # TODO: maybe yield the segment here to have the block pass additional
      # informations
      yield
    ensure
      txn.stop_segment
    end
1288258
@Requires("bytecode != null")
  @Ensures("result != null")
  public byte[] transformWithDebug(byte[] bytecode)
      throws IllegalClassFormatException {
    try {
      return instrumentWithDebug(bytecode);
    } catch (Throwable t) {
      /* If the class file contains errors, ASM will just crash. */
      IllegalClassFormatException e = new IllegalClassFormatException();
      e.initCause(t);
      throw e;
    }
  }
856244
public Script[] getScripts(Integer type) {
        ArrayList<Script> returnData = new ArrayList<>();
        PreparedStatement statement = null;
        ResultSet results = null;

        try (Connection sqlConnection = SQLService.getInstance().getConnection()) {

            statement = sqlConnection.prepareStatement("SELECT * FROM " + Constants.DB_TABLE_SCRIPT +
                                                           " ORDER BY " + Constants.GENERIC_ID);
            if (type != null) {
                statement = sqlConnection.prepareStatement("SELECT * FROM " + Constants.DB_TABLE_SCRIPT +
                                                               " WHERE " + Constants.SCRIPT_TYPE + "= ?" +
                                                               " ORDER BY " + Constants.GENERIC_ID);
                statement.setInt(1, type);
            }

            logger.info("Query: {}", statement);

            results = statement.executeQuery();
            while (results.next()) {
                returnData.add(scriptFromSQLResult(results));
            }
        } catch (Exception e) {

        } finally {
            try {
                if (results != null) {
                    results.close();
                }
            } catch (Exception e) {
            }
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }

        return returnData.toArray(new Script[0]);
    }
288953
public static void updateInstrumentation(CollectorConfiguration config) throws Exception {
        List<String> scripts = new ArrayList<String>();
        List<String> scriptNames = new ArrayList<String>();
        Map<String, Instrumentation> instrumentTypes=config.getInstrumentation();

        for (Map.Entry<String, Instrumentation> stringInstrumentationEntry : instrumentTypes.entrySet()) {
            Instrumentation types = stringInstrumentationEntry.getValue();
            String rules = ruleTransformer.transform(stringInstrumentationEntry.getKey(), types,
                            config.getProperty("version."+ stringInstrumentationEntry.getKey(), null));

            if (log.isLoggable(Level.FINER)) {
                log.finer("Update instrumentation script name=" + stringInstrumentationEntry.getKey() + " rules=" + rules);
            }

            if (rules != null) {
                scriptNames.add(stringInstrumentationEntry.getKey());
                scripts.add(rules);
            }
        }

        PrintWriter writer = new PrintWriter(new StringWriter());

        transformer.installScript(scripts, scriptNames, writer);

        writer.close();
    }
781808
public JMethod getMethod(String name, JClass []types)
  {
    JClassLoader jClassLoader = getClassLoader();
    
    return getMethod(_class, name, types, jClassLoader);
  }
815634
public AnnotationValueBuilder<T> member(String name, @Nullable Class<?>... types) {
        if (types != null) {
            AnnotationClassValue[] classValues = new AnnotationClassValue[types.length];
            for (int i = 0; i < types.length; i++) {
                Class<?> type = types[i];
                classValues[i] = new AnnotationClassValue<>(type);
            }
            values.put(name, classValues);
        }
        return this;
    }
610622
public static TypeDesc forClass(final String name) throws IllegalArgumentException {
        if (name.length() < 1) {
            throw invalidName(name);
        }

        // TODO: Support generics in name.

        TypeDesc type = cNamesToInstances.get(name);
        if (type != null) {
            return type;
        }

        int index1 = name.lastIndexOf('[');
        int index2 = name.lastIndexOf(']');
        if (index2 >= 0) {
            if (index2 + 1 != name.length() || index1 + 1 != index2) {
                throw invalidName(name);
            }
            try {
                type = forClass(name.substring(0, index1)).toArrayType();
            } catch (IllegalArgumentException e) {
                throw invalidName(name);
            }
        } else if (index1 >= 0) {
            throw invalidName(name);
        } else {
            setType: {
                switch (name.charAt(0)) {
                case 'v':
                    if (name.equals("void")) {
                        type = VOID;
                        break setType;
                    }
                    break;
                case 'b':
                    if (name.equals("boolean")) {
                        type = BOOLEAN;
                        break setType;
                    } else if (name.equals("byte")) {
                        type =  BYTE;
                        break setType;
                    }
                    break;
                case 'c':
                    if (name.equals("char")) {
                        type = CHAR;
                        break setType;
                    }
                    break;
                case 's':
                    if (name.equals("short")) {
                        type = SHORT;
                        break setType;
                    }
                    break;
                case 'i':
                    if (name.equals("int")) {
                        type = INT;
                        break setType;
                    }
                    break;
                case 'l':
                    if (name.equals("long")) {
                        type = LONG;
                        break setType;
                    }
                    break;
                case 'f':
                    if (name.equals("float")) {
                        type = FLOAT;
                        break setType;
                    }
                    break;
                case 'd':
                    if (name.equals("double")) {
                        type = DOUBLE;
                        break setType;
                    }
                    break;
                }

                String desc = generateDescriptor(name);
                if (name.indexOf('/') < 0) {
                    type = new ObjectType(desc, name);
                } else {
                    type = new ObjectType(desc, name.replace('/', '.'));
                }
                type = intern(type);
            }
        }

        cNamesToInstances.put(name, type);
        return type;
    }
663234
public static VariableDeclarationExpr createVariableDeclarationExpr(Type type, String name) {
        List<VariableDeclarator> vars = new ArrayList<VariableDeclarator>();
        vars.add(new VariableDeclarator(new VariableDeclaratorId(name)));
        return new VariableDeclarationExpr(type, vars);
    }
1179358
public ITypeParameterBuilder addTypeParameter(String name) {
		ITypeParameterBuilder builder = this.iTypeParameterBuilderProvider.get();
		final SarlClass object = getSarlClass();
		builder.eInit(object, name, getTypeResolutionContext());
		object.getTypeParameters().add(builder.getJvmTypeParameter());
		return builder;
	}
826425
public function Content($name, $type, $version = 'latest')
    {
        $type = strtolower($type);

        //Gets type for local file
        $local = false;
        if ('local' == $type) {
            $local = true;
            $type = strtolower(substr($name, strrpos($name, '.') + 1));
        }

        //Gets data for local file
        if ($local) {
            $data = 'css' == $type ? array('href' => $name) : array('src' => $name);
        //Gets data for external library
        } else {
            $data = $this->includeLibraryService->getData($name, $type, $version);
        }

        //Returns the content from href or src part
        if (null != $data) {
            $content = null;
            if ('css' == $type) {
                $content = '<style type="text/css">' . file_get_contents($data['href']) . '</style>';
            } elseif ('js' == $type) {
                $content = '<script type="text/javascript">' . file_get_contents($data['src']) . '</script>';
            }

            return $content;
        }

        //Throws an error if not found
        throw new Error('The Library "' . $name . ' (' . $type . ') version ' . $version . '" requested via "inc_content()" was not found. Please check name and supported library/versions.');
    }
382371
public static TypeSignature ofNamed(String name, Object namedTypeDescriptor) {
        return new TypeSignature(requireNonNull(name, "name"),
                                 requireNonNull(namedTypeDescriptor, "namedTypeDescriptor"));
    }
1258947
static String replacementTypeVarName(Name name, Set<String> superTypeVars) {
    String baseName = name.toString();
    int typeVarNum = 2;

    Matcher matcher = TRAILING_DIGIT_EXTRACTOR.matcher(name);
    if (matcher.matches()) {
      baseName = matcher.group(1);
      typeVarNum = Integer.parseInt(matcher.group(2)) + 1;
    }

    String replacementName;
    while (superTypeVars.contains(replacementName = baseName + typeVarNum)) {
      typeVarNum++;
    }

    return replacementName;
  }
351023
public static DiagnosticType error(String name, String descriptionFormat) {
    return make(name, CheckLevel.ERROR, descriptionFormat);
  }
1203208
public static <F> Protocol.Builder<F> builder(final String name) {
        return new ProtocolImpl<F>(name);
    }
439411
public ConstructorDeclarationBuilder param(Type type, String name) {
    return new ConstructorDeclarationBuilder(
        classIdentifier,
        protection,
        parameters.append(new Parameter(type, name, parameters.size())),
        methodHandler,
        builder);
  }
668326
@Override
    public void visitFormalTypeParameter(final String name) {
        if (type == TYPE_SIGNATURE
                || (state != EMPTY && state != FORMAL && state != BOUND)) {
            throw new IllegalStateException();
        }
        CheckMethodAdapter.checkIdentifier(name, "formal type parameter");
        state = FORMAL;
        if (sv != null) {
            sv.visitFormalTypeParameter(name);
        }
    }