Commit 27c79a6e authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Code peek for ASN1 now uses ASN1 coloring (issue #480)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 22dbba6a
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* Copyright (c) 2000-2022 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
......@@ -14,6 +14,7 @@ import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.titan.designer.AST.Location;
......@@ -26,18 +27,39 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
/**
* Supporting class for loading and colorizing parts of source code.
* Used with code hovering to show syntax highlighted source of the given element.
*
* @author Miklos Magyari
* @author Adam Knapp
* */
public class PeekSource {
private enum PeekType { Ttcn3, Asn1 }
private static Location lastPeekedLocation;
private static PeekType lastPeekedType;
public static String getPeekSource(IEditorPart targetEditor, Location codeLoc) {
if (codeLoc == null || codeLoc.equals(NULL_Location.INSTANCE)) {
return null;
}
final IResource fileToLoad = codeLoc.getFile();
if (fileToLoad instanceof IFile) {
final IFile file = (IFile)fileToLoad;
switch(file.getFileExtension()) {
case "asn":
case "asn1":
lastPeekedType = PeekType.Asn1;
break;
case "ttcn":
case "ttcn3":
case "ttcnpp":
default:
lastPeekedType = PeekType.Ttcn3;
break;
}
}
IResource actual = (IResource)targetEditor.getEditorInput().getAdapter(IFile.class);
String codeText = null;
......@@ -127,7 +149,16 @@ public class PeekSource {
}
IDocument doc = new Document(source);
CodeScanner scanner = new CodeScanner(new ColorManager(), lastPeekedLocation);
RuleBasedScanner scanner = null;
switch(lastPeekedType) {
case Asn1:
scanner = new org.eclipse.titan.designer.editors.asn1editor.CodeScanner(new ColorManager());
break;
case Ttcn3:
default:
scanner = new CodeScanner(new ColorManager(), lastPeekedLocation);
break;
}
scanner.setRange(doc, 0, source.length());
IToken token;
StringBuilder codestr = new StringBuilder("<pre>");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment