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;
}
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);
}
}
Aggregations