From 3c9e58e3f4225cc3451c3dbc33f59280d8950335 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 26 Mar 2015 11:20:04 +0100 Subject: [PATCH] SONAR-6318 Highlighting in compute --- .../step/PersistSyntaxHighLightingStep.java | 103 ++ .../PersistSyntaxHighLightingStepTest.java | 151 ++ .../org/sonar/batch/protocol/Constants.java | 152 +- .../batch/protocol/output/BatchReport.java | 1493 ++++++++++++++++- .../protocol/output/BatchReportReader.java | 10 + .../protocol/output/BatchReportWriter.java | 8 + .../batch/protocol/output/FileStructure.java | 13 +- .../src/main/protobuf/batch_report.proto | 11 + .../src/main/protobuf/constants.proto | 12 + .../output/BatchReportReaderTest.java | 29 +- .../output/BatchReportWriterTest.java | 24 + 11 files changed, 1997 insertions(+), 9 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java new file mode 100644 index 00000000000..1a2c1c1c126 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java @@ -0,0 +1,103 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.server.computation.step; + +import com.google.common.annotations.VisibleForTesting; +import org.sonar.api.resources.Qualifiers; +import org.sonar.batch.protocol.output.BatchReport; +import org.sonar.batch.protocol.output.BatchReportReader; +import org.sonar.server.computation.ComputationContext; + +import java.util.List; +import java.util.Map; + +import static com.google.common.collect.Maps.newHashMap; + +/** + * Nothing is persist for the moment. Only Syntax Highlighting are read and not persist for the moment + */ +public class PersistSyntaxHighLightingStep implements ComputationStep { + + private static final String OFFSET_SEPARATOR = ","; + + // Temporary variable in order to be able to test that syntax highlighting are well computed. Will only contains data from last processed + // file + private Map syntaxHighlightingByLineForLastProcessedFile; + + @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT}; + } + + @Override + public void execute(ComputationContext context) { + int rootComponentRef = context.getReportMetadata().getRootComponentRef(); + recursivelyProcessComponent(context, rootComponentRef); + } + + private void recursivelyProcessComponent(ComputationContext context, int componentRef) { + BatchReportReader reportReader = context.getReportReader(); + BatchReport.Component component = reportReader.readComponent(componentRef); + List highlightingRules = reportReader.readComponentSyntaxHighlighting(componentRef); + processSyntaxHightlighting(component, highlightingRules); + + for (Integer childRef : component.getChildRefList()) { + recursivelyProcessComponent(context, childRef); + } + } + + private void processSyntaxHightlighting(BatchReport.Component component, List highlightingRules) { + syntaxHighlightingByLineForLastProcessedFile = newHashMap(); + if (!highlightingRules.isEmpty()) { + for (BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule : highlightingRules) { + processHighlightingRule(highlightingRule); + } + } + } + + private void processHighlightingRule(BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule) { + BatchReport.Range range = highlightingRule.getRange(); + int startLine = range.getStartLine(); + int endLine = range.getEndLine(); + if (startLine != endLine) { + // TODO support syntax highlighting on multiple lines when source will be in compute, in order to be able to know the end line in this case + throw new IllegalStateException("To be implemented : Syntax Highlighting on multiple lines are not supported for the moment"); + } + StringBuilder symbolLine = syntaxHighlightingByLineForLastProcessedFile.get(startLine); + if (symbolLine == null) { + symbolLine = new StringBuilder(); + syntaxHighlightingByLineForLastProcessedFile.put(startLine, symbolLine); + } + symbolLine.append(range.getStartOffset()).append(OFFSET_SEPARATOR); + symbolLine.append(range.getEndOffset()).append(OFFSET_SEPARATOR); + symbolLine.append(highlightingRule.getType().toString()); + } + + @VisibleForTesting + Map getSyntaxHighlightingByLine() { + return syntaxHighlightingByLineForLastProcessedFile; + } + + @Override + public String getDescription() { + return "Read Syntax Highlighting"; + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java new file mode 100644 index 00000000000..0db99fa1779 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java @@ -0,0 +1,151 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.computation.step; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.batch.protocol.Constants; +import org.sonar.batch.protocol.output.BatchReport; +import org.sonar.batch.protocol.output.BatchReportReader; +import org.sonar.batch.protocol.output.BatchReportWriter; +import org.sonar.core.component.ComponentDto; +import org.sonar.server.component.ComponentTesting; +import org.sonar.server.computation.ComputationContext; + +import java.io.File; +import java.io.IOException; + +import static com.google.common.collect.Lists.newArrayList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +public class PersistSyntaxHighLightingStepTest extends BaseStepTest { + + private static final Integer FILE_REF = 3; + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + File reportDir; + + PersistSyntaxHighLightingStep step; + + @Before + public void setup() throws Exception { + reportDir = temp.newFolder(); + step = new PersistSyntaxHighLightingStep(); + } + + @Override + protected ComputationStep step() throws IOException { + return step; + } + + @Test + public void compute_no_symbol() throws Exception { + initReport(); + + step.execute(new ComputationContext(new BatchReportReader(reportDir), + ComponentTesting.newProjectDto("PROJECT_A"))); + + assertThat(step.getSyntaxHighlightingByLine()).isEmpty(); + } + + @Test + public void compute_syntax_highlighting() throws Exception { + BatchReportWriter writer = initReport(); + + writer.writeComponentSyntaxHighlighting(FILE_REF, newArrayList( + BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() + .setRange(BatchReport.Range.newBuilder() + .setStartLine(1) + .setStartOffset(3) + .setEndLine(1) + .setEndOffset(5) + .build()) + .setType(Constants.HighlightingType.ANNOTATION) + .build(), + BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() + .setRange(BatchReport.Range.newBuilder() + .setStartLine(3) + .setStartOffset(6) + .setEndLine(3) + .setEndOffset(7) + .build()) + .setType(Constants.HighlightingType.COMMENT) + .build()) + ); + + step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class))); + + assertThat(step.getSyntaxHighlightingByLine()).hasSize(2); + assertThat(step.getSyntaxHighlightingByLine().get(1).toString()).isEqualTo("3,5,ANNOTATION"); + assertThat(step.getSyntaxHighlightingByLine().get(3).toString()).isEqualTo("6,7,COMMENT"); + } + + @Test(expected = IllegalStateException.class) + public void fail_when_range_is_defined_on_different_line() throws Exception { + BatchReportWriter writer = initReport(); + + writer.writeComponentSyntaxHighlighting(FILE_REF, newArrayList( + BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() + .setRange(BatchReport.Range.newBuilder() + .setStartLine(1) + .setStartOffset(3) + .setEndLine(2) + .setEndOffset(2) + .build()) + .setType(Constants.HighlightingType.ANNOTATION) + .build())); + + step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class))); + } + + private BatchReportWriter initReport() { + BatchReportWriter writer = new BatchReportWriter(reportDir); + writer.writeMetadata(BatchReport.Metadata.newBuilder() + .setRootComponentRef(1) + .setProjectKey("PROJECT_KEY") + .setAnalysisDate(150000000L) + .build()); + + writer.writeComponent(BatchReport.Component.newBuilder() + .setRef(1) + .setType(Constants.ComponentType.PROJECT) + .setUuid("PROJECT_A") + .addChildRef(2) + .build()); + writer.writeComponent(BatchReport.Component.newBuilder() + .setRef(2) + .setType(Constants.ComponentType.MODULE) + .setUuid("BCDE") + .addChildRef(FILE_REF) + .build()); + writer.writeComponent(BatchReport.Component.newBuilder() + .setRef(FILE_REF) + .setType(Constants.ComponentType.FILE) + .setUuid("FILE_A") + .build()); + return writer; + } + +} diff --git a/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/Constants.java b/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/Constants.java index fe5456aaf32..1e58e9104fb 100644 --- a/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/Constants.java +++ b/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/Constants.java @@ -539,6 +539,151 @@ public final class Constants { // @@protoc_insertion_point(enum_scope:ComponentLinkType) } + /** + * Protobuf enum {@code HighlightingType} + */ + public enum HighlightingType + implements com.google.protobuf.ProtocolMessageEnum { + /** + * ANNOTATION = 0; + */ + ANNOTATION(0, 0), + /** + * CONSTANT = 1; + */ + CONSTANT(1, 1), + /** + * COMMENT = 2; + */ + COMMENT(2, 2), + /** + * CPP_DOC = 3; + */ + CPP_DOC(3, 3), + /** + * STRUCTURED_COMMENT = 4; + */ + STRUCTURED_COMMENT(4, 4), + /** + * KEYWORD = 5; + */ + KEYWORD(5, 5), + /** + * HIGHLIGHTING_STRING = 6; + */ + HIGHLIGHTING_STRING(6, 6), + /** + * KEYWORD_LIGHT = 7; + */ + KEYWORD_LIGHT(7, 7), + /** + * PREPROCESS_DIRECTIVE = 8; + */ + PREPROCESS_DIRECTIVE(8, 8), + ; + + /** + * ANNOTATION = 0; + */ + public static final int ANNOTATION_VALUE = 0; + /** + * CONSTANT = 1; + */ + public static final int CONSTANT_VALUE = 1; + /** + * COMMENT = 2; + */ + public static final int COMMENT_VALUE = 2; + /** + * CPP_DOC = 3; + */ + public static final int CPP_DOC_VALUE = 3; + /** + * STRUCTURED_COMMENT = 4; + */ + public static final int STRUCTURED_COMMENT_VALUE = 4; + /** + * KEYWORD = 5; + */ + public static final int KEYWORD_VALUE = 5; + /** + * HIGHLIGHTING_STRING = 6; + */ + public static final int HIGHLIGHTING_STRING_VALUE = 6; + /** + * KEYWORD_LIGHT = 7; + */ + public static final int KEYWORD_LIGHT_VALUE = 7; + /** + * PREPROCESS_DIRECTIVE = 8; + */ + public static final int PREPROCESS_DIRECTIVE_VALUE = 8; + + + public final int getNumber() { return value; } + + public static HighlightingType valueOf(int value) { + switch (value) { + case 0: return ANNOTATION; + case 1: return CONSTANT; + case 2: return COMMENT; + case 3: return CPP_DOC; + case 4: return STRUCTURED_COMMENT; + case 5: return KEYWORD; + case 6: return HIGHLIGHTING_STRING; + case 7: return KEYWORD_LIGHT; + case 8: return PREPROCESS_DIRECTIVE; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static com.google.protobuf.Internal.EnumLiteMap + internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public HighlightingType findValueByNumber(int number) { + return HighlightingType.valueOf(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor + getValueDescriptor() { + return getDescriptor().getValues().get(index); + } + public final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptorForType() { + return getDescriptor(); + } + public static final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptor() { + return org.sonar.batch.protocol.Constants.getDescriptor().getEnumTypes().get(5); + } + + private static final HighlightingType[] VALUES = values(); + + public static HighlightingType valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "EnumValueDescriptor is not for this type."); + } + return VALUES[desc.getIndex()]; + } + + private final int index; + private final int value; + + private HighlightingType(int index, int value) { + this.index = index; + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:HighlightingType) + } + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { @@ -557,7 +702,12 @@ public final class Constants { "\020\003\022\n\n\006STRING\020\004*\'\n\rEventCategory\022\t\n\005ALERT" + "\020\000\022\013\n\007PROFILE\020\001*F\n\021ComponentLinkType\022\010\n\004" + "HOME\020\000\022\007\n\003SCM\020\001\022\013\n\007SCM_DEV\020\002\022\t\n\005ISSUE\020\003\022" + - "\006\n\002CI\020\004B\034\n\030org.sonar.batch.protocolH\001" + "\006\n\002CI\020\004*\265\001\n\020HighlightingType\022\016\n\nANNOTATI", + "ON\020\000\022\014\n\010CONSTANT\020\001\022\013\n\007COMMENT\020\002\022\013\n\007CPP_D" + + "OC\020\003\022\026\n\022STRUCTURED_COMMENT\020\004\022\013\n\007KEYWORD\020" + + "\005\022\027\n\023HIGHLIGHTING_STRING\020\006\022\021\n\rKEYWORD_LI" + + "GHT\020\007\022\030\n\024PREPROCESS_DIRECTIVE\020\010B\034\n\030org.s" + + "onar.batch.protocolH\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { diff --git a/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java b/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java index 63bc76b758e..3caa3c3a737 100644 --- a/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java +++ b/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java @@ -17545,6 +17545,1470 @@ public final class BatchReport { // @@protoc_insertion_point(class_scope:Symbols) } + public interface SyntaxHighlightingOrBuilder extends + // @@protoc_insertion_point(interface_extends:SyntaxHighlighting) + com.google.protobuf.MessageOrBuilder { + + /** + * optional int32 component_ref = 1; + */ + boolean hasComponentRef(); + /** + * optional int32 component_ref = 1; + */ + int getComponentRef(); + + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+     * Rule must be sorted by line and start offset
+     * 
+ */ + java.util.List + getHighlightingRuleList(); + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+     * Rule must be sorted by line and start offset
+     * 
+ */ + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule getHighlightingRule(int index); + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+     * Rule must be sorted by line and start offset
+     * 
+ */ + int getHighlightingRuleCount(); + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+     * Rule must be sorted by line and start offset
+     * 
+ */ + java.util.List + getHighlightingRuleOrBuilderList(); + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+     * Rule must be sorted by line and start offset
+     * 
+ */ + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder getHighlightingRuleOrBuilder( + int index); + } + /** + * Protobuf type {@code SyntaxHighlighting} + */ + public static final class SyntaxHighlighting extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:SyntaxHighlighting) + SyntaxHighlightingOrBuilder { + // Use SyntaxHighlighting.newBuilder() to construct. + private SyntaxHighlighting(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); + } + private SyntaxHighlighting(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + + private static final SyntaxHighlighting defaultInstance; + public static SyntaxHighlighting getDefaultInstance() { + return defaultInstance; + } + + public SyntaxHighlighting getDefaultInstanceForType() { + return defaultInstance; + } + + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private SyntaxHighlighting( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + done = true; + } + break; + } + case 8: { + bitField0_ |= 0x00000001; + componentRef_ = input.readInt32(); + break; + } + case 18: { + if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { + highlightingRule_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000002; + } + highlightingRule_.add(input.readMessage(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.PARSER, extensionRegistry)); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) { + highlightingRule_ = java.util.Collections.unmodifiableList(highlightingRule_); + } + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.class, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public SyntaxHighlighting parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new SyntaxHighlighting(input, extensionRegistry); + } + }; + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public interface HighlightingRuleOrBuilder extends + // @@protoc_insertion_point(interface_extends:SyntaxHighlighting.HighlightingRule) + com.google.protobuf.MessageOrBuilder { + + /** + * optional .Range range = 1; + */ + boolean hasRange(); + /** + * optional .Range range = 1; + */ + org.sonar.batch.protocol.output.BatchReport.Range getRange(); + /** + * optional .Range range = 1; + */ + org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder getRangeOrBuilder(); + + /** + * optional .HighlightingType type = 2; + */ + boolean hasType(); + /** + * optional .HighlightingType type = 2; + */ + org.sonar.batch.protocol.Constants.HighlightingType getType(); + } + /** + * Protobuf type {@code SyntaxHighlighting.HighlightingRule} + */ + public static final class HighlightingRule extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:SyntaxHighlighting.HighlightingRule) + HighlightingRuleOrBuilder { + // Use HighlightingRule.newBuilder() to construct. + private HighlightingRule(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); + } + private HighlightingRule(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + + private static final HighlightingRule defaultInstance; + public static HighlightingRule getDefaultInstance() { + return defaultInstance; + } + + public HighlightingRule getDefaultInstanceForType() { + return defaultInstance; + } + + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private HighlightingRule( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + org.sonar.batch.protocol.output.BatchReport.Range.Builder subBuilder = null; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + subBuilder = range_.toBuilder(); + } + range_ = input.readMessage(org.sonar.batch.protocol.output.BatchReport.Range.PARSER, extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom(range_); + range_ = subBuilder.buildPartial(); + } + bitField0_ |= 0x00000001; + break; + } + case 16: { + int rawValue = input.readEnum(); + org.sonar.batch.protocol.Constants.HighlightingType value = org.sonar.batch.protocol.Constants.HighlightingType.valueOf(rawValue); + if (value == null) { + unknownFields.mergeVarintField(2, rawValue); + } else { + bitField0_ |= 0x00000002; + type_ = value; + } + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_HighlightingRule_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_HighlightingRule_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.class, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public HighlightingRule parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new HighlightingRule(input, extensionRegistry); + } + }; + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + private int bitField0_; + public static final int RANGE_FIELD_NUMBER = 1; + private org.sonar.batch.protocol.output.BatchReport.Range range_; + /** + * optional .Range range = 1; + */ + public boolean hasRange() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional .Range range = 1; + */ + public org.sonar.batch.protocol.output.BatchReport.Range getRange() { + return range_; + } + /** + * optional .Range range = 1; + */ + public org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder getRangeOrBuilder() { + return range_; + } + + public static final int TYPE_FIELD_NUMBER = 2; + private org.sonar.batch.protocol.Constants.HighlightingType type_; + /** + * optional .HighlightingType type = 2; + */ + public boolean hasType() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional .HighlightingType type = 2; + */ + public org.sonar.batch.protocol.Constants.HighlightingType getType() { + return type_; + } + + private void initFields() { + range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); + type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeMessage(1, range_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeEnum(2, type_.getNumber()); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(1, range_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(2, type_.getNumber()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code SyntaxHighlighting.HighlightingRule} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:SyntaxHighlighting.HighlightingRule) + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_HighlightingRule_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_HighlightingRule_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.class, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder.class); + } + + // Construct using org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getRangeFieldBuilder(); + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + if (rangeBuilder_ == null) { + range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); + } else { + rangeBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000001); + type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; + bitField0_ = (bitField0_ & ~0x00000002); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_HighlightingRule_descriptor; + } + + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule getDefaultInstanceForType() { + return org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.getDefaultInstance(); + } + + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule build() { + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule buildPartial() { + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule result = new org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + if (rangeBuilder_ == null) { + result.range_ = range_; + } else { + result.range_ = rangeBuilder_.build(); + } + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.type_ = type_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule) { + return mergeFrom((org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule other) { + if (other == org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.getDefaultInstance()) return this; + if (other.hasRange()) { + mergeRange(other.getRange()); + } + if (other.hasType()) { + setType(other.getType()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private org.sonar.batch.protocol.output.BatchReport.Range range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); + private com.google.protobuf.SingleFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.Range, org.sonar.batch.protocol.output.BatchReport.Range.Builder, org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder> rangeBuilder_; + /** + * optional .Range range = 1; + */ + public boolean hasRange() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional .Range range = 1; + */ + public org.sonar.batch.protocol.output.BatchReport.Range getRange() { + if (rangeBuilder_ == null) { + return range_; + } else { + return rangeBuilder_.getMessage(); + } + } + /** + * optional .Range range = 1; + */ + public Builder setRange(org.sonar.batch.protocol.output.BatchReport.Range value) { + if (rangeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + range_ = value; + onChanged(); + } else { + rangeBuilder_.setMessage(value); + } + bitField0_ |= 0x00000001; + return this; + } + /** + * optional .Range range = 1; + */ + public Builder setRange( + org.sonar.batch.protocol.output.BatchReport.Range.Builder builderForValue) { + if (rangeBuilder_ == null) { + range_ = builderForValue.build(); + onChanged(); + } else { + rangeBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000001; + return this; + } + /** + * optional .Range range = 1; + */ + public Builder mergeRange(org.sonar.batch.protocol.output.BatchReport.Range value) { + if (rangeBuilder_ == null) { + if (((bitField0_ & 0x00000001) == 0x00000001) && + range_ != org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance()) { + range_ = + org.sonar.batch.protocol.output.BatchReport.Range.newBuilder(range_).mergeFrom(value).buildPartial(); + } else { + range_ = value; + } + onChanged(); + } else { + rangeBuilder_.mergeFrom(value); + } + bitField0_ |= 0x00000001; + return this; + } + /** + * optional .Range range = 1; + */ + public Builder clearRange() { + if (rangeBuilder_ == null) { + range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); + onChanged(); + } else { + rangeBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000001); + return this; + } + /** + * optional .Range range = 1; + */ + public org.sonar.batch.protocol.output.BatchReport.Range.Builder getRangeBuilder() { + bitField0_ |= 0x00000001; + onChanged(); + return getRangeFieldBuilder().getBuilder(); + } + /** + * optional .Range range = 1; + */ + public org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder getRangeOrBuilder() { + if (rangeBuilder_ != null) { + return rangeBuilder_.getMessageOrBuilder(); + } else { + return range_; + } + } + /** + * optional .Range range = 1; + */ + private com.google.protobuf.SingleFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.Range, org.sonar.batch.protocol.output.BatchReport.Range.Builder, org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder> + getRangeFieldBuilder() { + if (rangeBuilder_ == null) { + rangeBuilder_ = new com.google.protobuf.SingleFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.Range, org.sonar.batch.protocol.output.BatchReport.Range.Builder, org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder>( + getRange(), + getParentForChildren(), + isClean()); + range_ = null; + } + return rangeBuilder_; + } + + private org.sonar.batch.protocol.Constants.HighlightingType type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; + /** + * optional .HighlightingType type = 2; + */ + public boolean hasType() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional .HighlightingType type = 2; + */ + public org.sonar.batch.protocol.Constants.HighlightingType getType() { + return type_; + } + /** + * optional .HighlightingType type = 2; + */ + public Builder setType(org.sonar.batch.protocol.Constants.HighlightingType value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + type_ = value; + onChanged(); + return this; + } + /** + * optional .HighlightingType type = 2; + */ + public Builder clearType() { + bitField0_ = (bitField0_ & ~0x00000002); + type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:SyntaxHighlighting.HighlightingRule) + } + + static { + defaultInstance = new HighlightingRule(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:SyntaxHighlighting.HighlightingRule) + } + + private int bitField0_; + public static final int COMPONENT_REF_FIELD_NUMBER = 1; + private int componentRef_; + /** + * optional int32 component_ref = 1; + */ + public boolean hasComponentRef() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional int32 component_ref = 1; + */ + public int getComponentRef() { + return componentRef_; + } + + public static final int HIGHLIGHTING_RULE_FIELD_NUMBER = 2; + private java.util.List highlightingRule_; + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+     * Rule must be sorted by line and start offset
+     * 
+ */ + public java.util.List getHighlightingRuleList() { + return highlightingRule_; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+     * Rule must be sorted by line and start offset
+     * 
+ */ + public java.util.List + getHighlightingRuleOrBuilderList() { + return highlightingRule_; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+     * Rule must be sorted by line and start offset
+     * 
+ */ + public int getHighlightingRuleCount() { + return highlightingRule_.size(); + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+     * Rule must be sorted by line and start offset
+     * 
+ */ + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule getHighlightingRule(int index) { + return highlightingRule_.get(index); + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+     * Rule must be sorted by line and start offset
+     * 
+ */ + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder getHighlightingRuleOrBuilder( + int index) { + return highlightingRule_.get(index); + } + + private void initFields() { + componentRef_ = 0; + highlightingRule_ = java.util.Collections.emptyList(); + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeInt32(1, componentRef_); + } + for (int i = 0; i < highlightingRule_.size(); i++) { + output.writeMessage(2, highlightingRule_.get(i)); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(1, componentRef_); + } + for (int i = 0; i < highlightingRule_.size(); i++) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(2, highlightingRule_.get(i)); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code SyntaxHighlighting} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:SyntaxHighlighting) + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlightingOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.class, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.Builder.class); + } + + // Construct using org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getHighlightingRuleFieldBuilder(); + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + componentRef_ = 0; + bitField0_ = (bitField0_ & ~0x00000001); + if (highlightingRuleBuilder_ == null) { + highlightingRule_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000002); + } else { + highlightingRuleBuilder_.clear(); + } + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_descriptor; + } + + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting getDefaultInstanceForType() { + return org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.getDefaultInstance(); + } + + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting build() { + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting buildPartial() { + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting result = new org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.componentRef_ = componentRef_; + if (highlightingRuleBuilder_ == null) { + if (((bitField0_ & 0x00000002) == 0x00000002)) { + highlightingRule_ = java.util.Collections.unmodifiableList(highlightingRule_); + bitField0_ = (bitField0_ & ~0x00000002); + } + result.highlightingRule_ = highlightingRule_; + } else { + result.highlightingRule_ = highlightingRuleBuilder_.build(); + } + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting) { + return mergeFrom((org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting other) { + if (other == org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.getDefaultInstance()) return this; + if (other.hasComponentRef()) { + setComponentRef(other.getComponentRef()); + } + if (highlightingRuleBuilder_ == null) { + if (!other.highlightingRule_.isEmpty()) { + if (highlightingRule_.isEmpty()) { + highlightingRule_ = other.highlightingRule_; + bitField0_ = (bitField0_ & ~0x00000002); + } else { + ensureHighlightingRuleIsMutable(); + highlightingRule_.addAll(other.highlightingRule_); + } + onChanged(); + } + } else { + if (!other.highlightingRule_.isEmpty()) { + if (highlightingRuleBuilder_.isEmpty()) { + highlightingRuleBuilder_.dispose(); + highlightingRuleBuilder_ = null; + highlightingRule_ = other.highlightingRule_; + bitField0_ = (bitField0_ & ~0x00000002); + highlightingRuleBuilder_ = + com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? + getHighlightingRuleFieldBuilder() : null; + } else { + highlightingRuleBuilder_.addAllMessages(other.highlightingRule_); + } + } + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private int componentRef_ ; + /** + * optional int32 component_ref = 1; + */ + public boolean hasComponentRef() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional int32 component_ref = 1; + */ + public int getComponentRef() { + return componentRef_; + } + /** + * optional int32 component_ref = 1; + */ + public Builder setComponentRef(int value) { + bitField0_ |= 0x00000001; + componentRef_ = value; + onChanged(); + return this; + } + /** + * optional int32 component_ref = 1; + */ + public Builder clearComponentRef() { + bitField0_ = (bitField0_ & ~0x00000001); + componentRef_ = 0; + onChanged(); + return this; + } + + private java.util.List highlightingRule_ = + java.util.Collections.emptyList(); + private void ensureHighlightingRuleIsMutable() { + if (!((bitField0_ & 0x00000002) == 0x00000002)) { + highlightingRule_ = new java.util.ArrayList(highlightingRule_); + bitField0_ |= 0x00000002; + } + } + + private com.google.protobuf.RepeatedFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder> highlightingRuleBuilder_; + + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public java.util.List getHighlightingRuleList() { + if (highlightingRuleBuilder_ == null) { + return java.util.Collections.unmodifiableList(highlightingRule_); + } else { + return highlightingRuleBuilder_.getMessageList(); + } + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public int getHighlightingRuleCount() { + if (highlightingRuleBuilder_ == null) { + return highlightingRule_.size(); + } else { + return highlightingRuleBuilder_.getCount(); + } + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule getHighlightingRule(int index) { + if (highlightingRuleBuilder_ == null) { + return highlightingRule_.get(index); + } else { + return highlightingRuleBuilder_.getMessage(index); + } + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public Builder setHighlightingRule( + int index, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule value) { + if (highlightingRuleBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureHighlightingRuleIsMutable(); + highlightingRule_.set(index, value); + onChanged(); + } else { + highlightingRuleBuilder_.setMessage(index, value); + } + return this; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public Builder setHighlightingRule( + int index, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder builderForValue) { + if (highlightingRuleBuilder_ == null) { + ensureHighlightingRuleIsMutable(); + highlightingRule_.set(index, builderForValue.build()); + onChanged(); + } else { + highlightingRuleBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public Builder addHighlightingRule(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule value) { + if (highlightingRuleBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureHighlightingRuleIsMutable(); + highlightingRule_.add(value); + onChanged(); + } else { + highlightingRuleBuilder_.addMessage(value); + } + return this; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public Builder addHighlightingRule( + int index, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule value) { + if (highlightingRuleBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureHighlightingRuleIsMutable(); + highlightingRule_.add(index, value); + onChanged(); + } else { + highlightingRuleBuilder_.addMessage(index, value); + } + return this; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public Builder addHighlightingRule( + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder builderForValue) { + if (highlightingRuleBuilder_ == null) { + ensureHighlightingRuleIsMutable(); + highlightingRule_.add(builderForValue.build()); + onChanged(); + } else { + highlightingRuleBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public Builder addHighlightingRule( + int index, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder builderForValue) { + if (highlightingRuleBuilder_ == null) { + ensureHighlightingRuleIsMutable(); + highlightingRule_.add(index, builderForValue.build()); + onChanged(); + } else { + highlightingRuleBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public Builder addAllHighlightingRule( + java.lang.Iterable values) { + if (highlightingRuleBuilder_ == null) { + ensureHighlightingRuleIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll( + values, highlightingRule_); + onChanged(); + } else { + highlightingRuleBuilder_.addAllMessages(values); + } + return this; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public Builder clearHighlightingRule() { + if (highlightingRuleBuilder_ == null) { + highlightingRule_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + } else { + highlightingRuleBuilder_.clear(); + } + return this; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public Builder removeHighlightingRule(int index) { + if (highlightingRuleBuilder_ == null) { + ensureHighlightingRuleIsMutable(); + highlightingRule_.remove(index); + onChanged(); + } else { + highlightingRuleBuilder_.remove(index); + } + return this; + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder getHighlightingRuleBuilder( + int index) { + return getHighlightingRuleFieldBuilder().getBuilder(index); + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder getHighlightingRuleOrBuilder( + int index) { + if (highlightingRuleBuilder_ == null) { + return highlightingRule_.get(index); } else { + return highlightingRuleBuilder_.getMessageOrBuilder(index); + } + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public java.util.List + getHighlightingRuleOrBuilderList() { + if (highlightingRuleBuilder_ != null) { + return highlightingRuleBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(highlightingRule_); + } + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder addHighlightingRuleBuilder() { + return getHighlightingRuleFieldBuilder().addBuilder( + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.getDefaultInstance()); + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder addHighlightingRuleBuilder( + int index) { + return getHighlightingRuleFieldBuilder().addBuilder( + index, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.getDefaultInstance()); + } + /** + * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; + * + *
+       * Rule must be sorted by line and start offset
+       * 
+ */ + public java.util.List + getHighlightingRuleBuilderList() { + return getHighlightingRuleFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder> + getHighlightingRuleFieldBuilder() { + if (highlightingRuleBuilder_ == null) { + highlightingRuleBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder>( + highlightingRule_, + ((bitField0_ & 0x00000002) == 0x00000002), + getParentForChildren(), + isClean()); + highlightingRule_ = null; + } + return highlightingRuleBuilder_; + } + + // @@protoc_insertion_point(builder_scope:SyntaxHighlighting) + } + + static { + defaultInstance = new SyntaxHighlighting(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:SyntaxHighlighting) + } + private static final com.google.protobuf.Descriptors.Descriptor internal_static_Metadata_descriptor; private static @@ -17615,6 +19079,16 @@ public final class BatchReport { private static com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_Symbols_Symbol_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_SyntaxHighlighting_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_SyntaxHighlighting_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_SyntaxHighlighting_HighlightingRule_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_SyntaxHighlighting_HighlightingRule_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { @@ -17682,7 +19156,12 @@ public final class BatchReport { "\022\025\n\rcomponent_ref\030\001 \001(\005\022\037\n\006symbol\030\002 \003(\0132" + "\017.Symbols.Symbol\032@\n\006Symbol\022\033\n\013declaratio" + "n\030\001 \001(\0132\006.Range\022\031\n\treference\030\002 \003(\0132\006.Ran" + - "geB#\n\037org.sonar.batch.protocol.outputH\001" + "ge\"\270\001\n\022SyntaxHighlighting\022\025\n\rcomponent_r" + + "ef\030\001 \001(\005\022?\n\021highlighting_rule\030\002 \003(\0132$.Sy", + "ntaxHighlighting.HighlightingRule\032J\n\020Hig" + + "hlightingRule\022\025\n\005range\030\001 \001(\0132\006.Range\022\037\n\004" + + "type\030\002 \001(\0162\021.HighlightingTypeB#\n\037org.son" + + "ar.batch.protocol.outputH\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { @@ -17781,6 +19260,18 @@ public final class BatchReport { com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_Symbols_Symbol_descriptor, new java.lang.String[] { "Declaration", "Reference", }); + internal_static_SyntaxHighlighting_descriptor = + getDescriptor().getMessageTypes().get(13); + internal_static_SyntaxHighlighting_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_SyntaxHighlighting_descriptor, + new java.lang.String[] { "ComponentRef", "HighlightingRule", }); + internal_static_SyntaxHighlighting_HighlightingRule_descriptor = + internal_static_SyntaxHighlighting_descriptor.getNestedTypes().get(0); + internal_static_SyntaxHighlighting_HighlightingRule_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_SyntaxHighlighting_HighlightingRule_descriptor, + new java.lang.String[] { "Range", "Type", }); org.sonar.batch.protocol.Constants.getDescriptor(); } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java index 74aa05571d6..f351be21f40 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java @@ -99,6 +99,16 @@ public class BatchReportReader { return Collections.emptyList(); } + public List readComponentSyntaxHighlighting(int componentRef) { + File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTING, componentRef); + if (file.exists() && file.isFile()) { + // all the highlighting are loaded in memory + BatchReport.SyntaxHighlighting syntaxHighlighting = ProtobufUtil.readFile(file, BatchReport.SyntaxHighlighting.PARSER); + return syntaxHighlighting.getHighlightingRuleList(); + } + return Collections.emptyList(); + } + private boolean isNotAnExistingFile(File file) { return !file.exists() || !file.isFile(); } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java index 41ab54b5dd4..7ed971cbb15 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java @@ -100,4 +100,12 @@ public class BatchReportWriter { ProtobufUtil.writeToFile(builder.build(), file); } + public void writeComponentSyntaxHighlighting(int componentRef, Iterable highlightingRules) { + BatchReport.SyntaxHighlighting.Builder builder = BatchReport.SyntaxHighlighting.newBuilder(); + builder.setComponentRef(componentRef); + builder.addAllHighlightingRule(highlightingRules); + File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTING, componentRef); + ProtobufUtil.writeToFile(builder.build(), file); + } + } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/FileStructure.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/FileStructure.java index c983e655742..f91fc955b1c 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/FileStructure.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/FileStructure.java @@ -27,14 +27,15 @@ import java.io.File; public class FileStructure { public static enum Domain { - ISSUES("issues-"), - ISSUES_ON_DELETED("issues-deleted-"), - COMPONENT("component-"), - MEASURES("measures-"), - DUPLICATIONS("duplications-"), + ISSUES("issues-"), + ISSUES_ON_DELETED("issues-deleted-"), + COMPONENT("component-"), + MEASURES("measures-"), + DUPLICATIONS("duplications-"), + SYNTAX_HIGHLIGHTING("syntax-highlighting-"), SYMBOLS("symbol-") ; - + private final String filePrefix; Domain(String filePrefix) { diff --git a/sonar-batch-protocol/src/main/protobuf/batch_report.proto b/sonar-batch-protocol/src/main/protobuf/batch_report.proto index 629064fe5f4..b1ae155e547 100644 --- a/sonar-batch-protocol/src/main/protobuf/batch_report.proto +++ b/sonar-batch-protocol/src/main/protobuf/batch_report.proto @@ -191,3 +191,14 @@ message Symbols { repeated Range reference = 2; } } + +message SyntaxHighlighting { + optional int32 component_ref = 1; + // Rule must be sorted by line and start offset + repeated HighlightingRule highlighting_rule = 2; + + message HighlightingRule { + optional Range range = 1; + optional HighlightingType type = 2; + } +} diff --git a/sonar-batch-protocol/src/main/protobuf/constants.proto b/sonar-batch-protocol/src/main/protobuf/constants.proto index 4955dbaaa70..d41548178e5 100644 --- a/sonar-batch-protocol/src/main/protobuf/constants.proto +++ b/sonar-batch-protocol/src/main/protobuf/constants.proto @@ -59,3 +59,15 @@ enum ComponentLinkType { ISSUE = 3; CI = 4; } + +enum HighlightingType { + ANNOTATION = 0; + CONSTANT = 1; + COMMENT = 2; + CPP_DOC = 3; + STRUCTURED_COMMENT = 4; + KEYWORD = 5; + HIGHLIGHTING_STRING = 6; + KEYWORD_LIGHT = 7; + PREPROCESS_DIRECTIVE = 8; +} diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java index 4a91ed696f2..50894c5c487 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java @@ -23,6 +23,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.output.BatchReport.Issues; import org.sonar.batch.protocol.output.BatchReport.Metadata; @@ -96,6 +97,32 @@ public class BatchReportReaderTest { assertThat(sut.readComponentDuplications(1).get(0).getDuplicatedByList()).hasSize(1); } + @Test + public void read_syntax_highlighting() throws Exception { + File dir = temp.newFolder(); + BatchReportWriter writer = new BatchReportWriter(dir); + + writer.writeMetadata(BatchReport.Metadata.newBuilder() + .setRootComponentRef(1).build()); + + writer.writeComponent(BatchReport.Component.newBuilder() + .setRef(1).build()); + + BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule = BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() + .setRange(BatchReport.Range.newBuilder() + .setStartLine(1) + .setEndLine(1) + .build()) + .setType(Constants.HighlightingType.ANNOTATION) + .build(); + writer.writeComponentSyntaxHighlighting(1, Arrays.asList(highlightingRule)); + + BatchReportReader sut = new BatchReportReader(dir); + assertThat(sut.readComponentSyntaxHighlighting(1)).hasSize(1); + assertThat(sut.readComponentSyntaxHighlighting(1).get(0).getRange()).isNotNull(); + assertThat(sut.readComponentSyntaxHighlighting(1).get(0).getType()).isEqualTo(Constants.HighlightingType.ANNOTATION); + } + @Test public void read_symbols() throws Exception { File dir = temp.newFolder(); @@ -135,7 +162,7 @@ public class BatchReportReaderTest { } @Test(expected = IllegalStateException.class) - public void fail_if_missing_file_on_deleted_component() throws Exception { + public void fail_if_missing_file_on_deleted_component() throws Exception { sut.readDeletedComponentIssues(666); } diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java index 38e7e1539a7..eed0658d3e4 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java @@ -234,4 +234,28 @@ public class BatchReportWriterTest { assertThat(read.getComponentRef()).isEqualTo(1); assertThat(read.getSymbolList()).hasSize(1); } + + @Test + public void write_syntax_highlighting() throws Exception { + File dir = temp.newFolder(); + BatchReportWriter writer = new BatchReportWriter(dir); + + assertThat(writer.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTING, 1)).isFalse(); + + BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule = BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() + .setRange(BatchReport.Range.newBuilder() + .setStartLine(1) + .setEndLine(1) + .build()) + .setType(Constants.HighlightingType.ANNOTATION) + .build(); + writer.writeComponentSyntaxHighlighting(1, Arrays.asList(highlightingRule)); + + assertThat(writer.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTING, 1)).isTrue(); + File file = writer.getFileStructure().fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTING, 1); + assertThat(file).exists().isFile(); + BatchReport.SyntaxHighlighting syntaxHighlighting = ProtobufUtil.readFile(file, BatchReport.SyntaxHighlighting.PARSER); + assertThat(syntaxHighlighting.getComponentRef()).isEqualTo(1); + assertThat(syntaxHighlighting.getHighlightingRuleList()).hasSize(1); + } } -- 2.39.5