Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
krasa committed Jan 11, 2021
1 parent 6a5ccd7 commit 7b5d0ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ public FileAnnotationResult doAnnotate(PsiFile file) {
String source = sourceData.getValue();
sourceAnnotationResult.addAll(PlantUmlFacade.get().annotateSyntaxErrors(file, source));

List<SourceAnnotation> blockComments = annotateBlockComments(source);
List<SyntaxHighlightAnnotation> blockComments = annotateBlockComments(source);
sourceAnnotationResult.addBlockComments(blockComments);

annotateByLine(sourceAnnotationResult, source, blockComments);
annotateByLine(sourceAnnotationResult, source);

result.add(sourceAnnotationResult);
}
}
return result;
}

public void annotateByLine(SourceAnnotationResult result, String source, List<SourceAnnotation> blockComments) {
public void annotateByLine(SourceAnnotationResult result, String source) {
Matcher keywords = LanguagePatternHolder.INSTANCE.keywordsPattern.matcher("");
Matcher pluginSettings = LanguagePatternHolder.INSTANCE.pluginSettingsPattern.matcher("");
Matcher types = LanguagePatternHolder.INSTANCE.typesPattern.matcher("");
Expand Down Expand Up @@ -97,8 +97,8 @@ private void annotate(SourceAnnotationResult result, String line, int i, TextAtt
}
}

private List<SourceAnnotation> annotateBlockComments(String source) {
List<SourceAnnotation> result = new ArrayList<SourceAnnotation>();
private List<SyntaxHighlightAnnotation> annotateBlockComments(String source) {
List<SyntaxHighlightAnnotation> result = new ArrayList<>();

Matcher matcher = LanguagePatternHolder.INSTANCE.startBlockComment.matcher(source);
Matcher endMatcher = null;
Expand Down
22 changes: 7 additions & 15 deletions src/org/plantuml/idea/lang/annotator/SourceAnnotationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class SourceAnnotationResult {
private int sourceOffset;

private final Collection<SourceAnnotation> annotations = new ArrayList<SourceAnnotation>();
private int[][] skip;
private List<SyntaxHighlightAnnotation> blockComments;

public SourceAnnotationResult(int sourceOffset) {
this.sourceOffset = sourceOffset;
}

public void addAll(Collection<SourceAnnotation> sourceAnnotations) {
public void addAll(Collection<? extends SourceAnnotation> sourceAnnotations) {
annotations.addAll(sourceAnnotations);
}

Expand All @@ -42,26 +42,18 @@ public void addWithBlockCommentCheck(SyntaxHighlightAnnotation syntaxHighlightAn
}

private boolean inBlockComment(SyntaxHighlightAnnotation syntaxHighlightAnnotation) {
for (int i = 0, skipLength = skip.length; i < skipLength; i++) {
int[] range = skip[i];
for (int i = 0, blockCommentsSize = blockComments.size(); i < blockCommentsSize; i++) {
SyntaxHighlightAnnotation blockComment = blockComments.get(i);
int startSourceOffset = syntaxHighlightAnnotation.startSourceOffset;
if (range[0] < startSourceOffset && startSourceOffset < range[1]) {
if (blockComment.getStartSourceOffset() < startSourceOffset && startSourceOffset < blockComment.getEndSourceOffset()) {
return true;
}
}
return false;
}

public void addBlockComments(List<SourceAnnotation> blockComments) {
skip = new int[blockComments.size()][2];
for (int i = 0, blockCommentsSize = blockComments.size(); i < blockCommentsSize; i++) {
SourceAnnotation blockComment = blockComments.get(i);
SyntaxHighlightAnnotation b = (SyntaxHighlightAnnotation) blockComment;
int startSourceOffset = b.getStartSourceOffset();
int endSourceOffset = b.getEndSourceOffset();
skip[i][0] = startSourceOffset;
skip[i][1] = endSourceOffset;
}
public void addBlockComments(List<SyntaxHighlightAnnotation> blockComments) {
this.blockComments = blockComments;
addAll(blockComments);
}
}

0 comments on commit 7b5d0ef

Please sign in to comment.