Search in sources :

Example 1 with InstrumentationException

use of org.jetbrains.jps.intellilang.model.InstrumentationException in project intellij-community by JetBrains.

the class PatternValidatorBuilder method instrument.

@Nullable
@Override
protected BinaryContent instrument(CompileContext context, CompiledClass compiled, ClassReader reader, ClassWriter writer, InstrumentationClassFinder finder) {
    final JpsIntelliLangConfiguration config = JpsIntelliLangExtensionService.getInstance().getConfiguration(context.getProjectDescriptor().getModel().getGlobal());
    final PatternInstrumenter instrumenter = new PatternInstrumenter(config.getPatternAnnotationClass(), writer, config.getInstrumentationType(), finder);
    try {
        reader.accept(instrumenter, 0);
        if (instrumenter.instrumented()) {
            return new BinaryContent(writer.toByteArray());
        }
    } catch (InstrumentationException e) {
        context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, e.getMessage()));
    }
    return null;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) BinaryContent(org.jetbrains.jps.incremental.BinaryContent) JpsIntelliLangConfiguration(org.jetbrains.jps.intellilang.model.JpsIntelliLangConfiguration) InstrumentationException(org.jetbrains.jps.intellilang.model.InstrumentationException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with InstrumentationException

use of org.jetbrains.jps.intellilang.model.InstrumentationException in project intellij-community by JetBrains.

the class PatternInstrumenter method initPatterns.

// verify pattern and add compiled pattern to static cache
private void initPatterns(MethodVisitor mv) {
    mv.visitIntInsn(BIPUSH, myPatterns.size());
    mv.visitTypeInsn(ANEWARRAY, "java/util/regex/Pattern");
    mv.visitFieldInsn(PUTSTATIC, myClassName, PATTERN_CACHE_NAME, JAVA_UTIL_REGEX_PATTERN);
    int i = 0;
    for (String pattern : myPatterns) {
        // check the pattern so we can rely on the pattern being valid at runtime
        try {
            Pattern.compile(pattern);
        } catch (Exception e) {
            throw new InstrumentationException("Illegal Pattern: " + pattern, e);
        }
        mv.visitFieldInsn(GETSTATIC, myClassName, PATTERN_CACHE_NAME, JAVA_UTIL_REGEX_PATTERN);
        mv.visitIntInsn(BIPUSH, i++);
        mv.visitLdcInsn(pattern);
        mv.visitMethodInsn(INVOKESTATIC, "java/util/regex/Pattern", "compile", "(Ljava/lang/String;)Ljava/util/regex/Pattern;", false);
        mv.visitInsn(AASTORE);
    }
}
Also used : IOException(java.io.IOException) InstrumentationException(org.jetbrains.jps.intellilang.model.InstrumentationException) InstrumentationException(org.jetbrains.jps.intellilang.model.InstrumentationException)

Aggregations

InstrumentationException (org.jetbrains.jps.intellilang.model.InstrumentationException)2 IOException (java.io.IOException)1 Nullable (org.jetbrains.annotations.Nullable)1 BinaryContent (org.jetbrains.jps.incremental.BinaryContent)1 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)1 JpsIntelliLangConfiguration (org.jetbrains.jps.intellilang.model.JpsIntelliLangConfiguration)1