Search in sources :

Example 41 with Location

use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.

the class OutlinePage method selectionChanged.

@Override
public void selectionChanged(final SelectionChangedEvent event) {
    super.selectionChanged(event);
    ISelection selection = event.getSelection();
    if (selection.isEmpty()) {
        return;
    }
    Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
    Identifier identifier = null;
    if (selectedElement instanceof IOutlineElement) {
        identifier = ((IOutlineElement) selectedElement).getIdentifier();
    }
    if (identifier == null || identifier.getLocation() == null) {
        return;
    }
    Location location = identifier.getLocation();
    editor.selectAndReveal(location.getOffset(), location.getEndOffset() - location.getOffset());
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOutlineElement(org.eclipse.titan.designer.AST.IOutlineElement) Location(org.eclipse.titan.designer.AST.Location)

Example 42 with Location

use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.

the class VariantAttributeAnalyzer method parse.

public void parse(final RawAST rawAST, final AttributeSpecification specification, final int lengthMultiplier, final AtomicBoolean raw_found) {
    VariantAttributeLexer lexer;
    Location location = specification.getLocation();
    StringReader reader = new StringReader(specification.getSpecification());
    CharStream charStream = new UnbufferedCharStream(reader);
    lexer = new VariantAttributeLexer(charStream);
    lexer.setTokenFactory(new CommonTokenFactory(true));
    TitanListener lexerListener = new TitanListener();
    lexer.removeErrorListeners();
    lexer.addErrorListener(lexerListener);
    final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    VariantAttributeParser parser = new VariantAttributeParser(tokenStream);
    parser.setBuildParseTree(false);
    TitanListener parserListener = new TitanListener();
    parser.removeErrorListeners();
    parser.addErrorListener(parserListener);
    parser.setActualFile((IFile) location.getFile());
    parser.setLine(location.getLine());
    parser.setOffset(location.getOffset() + 1);
    MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, location.getFile(), location.getOffset(), location.getEndOffset());
    parser.setRawAST(rawAST);
    parser.setLengthMultiplier(lengthMultiplier);
    parser.pr_AttribSpec();
    if (!lexerListener.getErrorsStored().isEmpty()) {
        for (int i = 0; i < lexerListener.getErrorsStored().size(); i++) {
            Location temp = new Location(location);
            temp.setOffset(temp.getOffset() + 1);
            ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) location.getFile(), lexerListener.getErrorsStored().get(i), IMarker.SEVERITY_ERROR, temp);
        }
    }
    if (!parserListener.getErrorsStored().isEmpty()) {
        for (int i = 0; i < parserListener.getErrorsStored().size(); i++) {
            Location temp = new Location(location);
            temp.setOffset(temp.getOffset() + 1);
            ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) location.getFile(), parserListener.getErrorsStored().get(i), IMarker.SEVERITY_ERROR, temp);
        }
    }
    if (!raw_found.get()) {
        raw_found.set(parser.getRawFound());
    }
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CommonTokenFactory(org.antlr.v4.runtime.CommonTokenFactory) StringReader(java.io.StringReader) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) TitanListener(org.eclipse.titan.common.parsers.TitanListener) Location(org.eclipse.titan.designer.AST.Location)

Example 43 with Location

use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.

the class ExtensionAttributeAnalyzer method parse.

public void parse(final AttributeSpecification specification) {
    ExtensionAttributeLexer lexer;
    Location location = specification.getLocation();
    StringReader reader = new StringReader(specification.getSpecification());
    CharStream charStream = new UnbufferedCharStream(reader);
    lexer = new ExtensionAttributeLexer(charStream);
    lexer.setTokenFactory(new CommonTokenFactory(true));
    TitanListener lexerListener = new TitanListener();
    lexer.removeErrorListeners();
    lexer.addErrorListener(lexerListener);
    // 1. Previously it was UnbufferedTokenStream(lexer), but it was changed to BufferedTokenStream, because UnbufferedTokenStream seems to be unusable. It is an ANTLR 4 bug.
    // Read this: https://groups.google.com/forum/#!topic/antlr-discussion/gsAu-6d3pKU
    // pr_PatternChunk[StringBuilder builder, boolean[] uni]:
    // $builder.append($v.text); <-- exception is thrown here: java.lang.UnsupportedOperationException: interval 85..85 not in token buffer window: 86..341
    // 2. Changed from BufferedTokenStream to CommonTokenStream, otherwise tokens with "-> channel(HIDDEN)" are not filtered out in lexer.
    final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    ExtensionAttributeParser parser = new ExtensionAttributeParser(tokenStream);
    parser.setBuildParseTree(false);
    TitanListener parserListener = new TitanListener();
    parser.removeErrorListeners();
    parser.addErrorListener(parserListener);
    parser.setActualFile((IFile) location.getFile());
    parser.setLine(location.getLine());
    parser.setOffset(location.getOffset() + 1);
    MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, location.getFile(), location.getOffset(), location.getEndOffset());
    attributes = null;
    attributes = parser.pr_ExtensionAttributeRoot().list;
    if (!lexerListener.getErrorsStored().isEmpty()) {
        String reportLevel = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTERRORSINEXTENSIONSYNTAX, GeneralConstants.WARNING, null);
        int errorLevel;
        if (GeneralConstants.ERROR.equals(reportLevel)) {
            errorLevel = IMarker.SEVERITY_ERROR;
        } else if (GeneralConstants.WARNING.equals(reportLevel)) {
            errorLevel = IMarker.SEVERITY_WARNING;
        } else {
            return;
        }
        for (int i = 0; i < lexerListener.getErrorsStored().size(); i++) {
            Location temp = new Location(location);
            temp.setOffset(temp.getOffset() + 1);
            ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) location.getFile(), lexerListener.getErrorsStored().get(i), errorLevel, temp);
        }
    }
    if (!parserListener.getErrorsStored().isEmpty()) {
        String reportLevel = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTERRORSINEXTENSIONSYNTAX, GeneralConstants.WARNING, null);
        int errorLevel;
        if (GeneralConstants.ERROR.equals(reportLevel)) {
            errorLevel = IMarker.SEVERITY_ERROR;
        } else if (GeneralConstants.WARNING.equals(reportLevel)) {
            errorLevel = IMarker.SEVERITY_WARNING;
        } else {
            return;
        }
        for (int i = 0; i < parserListener.getErrorsStored().size(); i++) {
            Location temp = new Location(location);
            temp.setOffset(temp.getOffset() + 1);
            ParserMarkerSupport.createOnTheFlyMixedMarker((IFile) location.getFile(), parserListener.getErrorsStored().get(i), errorLevel, temp);
        }
    }
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CommonTokenFactory(org.antlr.v4.runtime.CommonTokenFactory) StringReader(java.io.StringReader) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) TitanListener(org.eclipse.titan.common.parsers.TitanListener) Location(org.eclipse.titan.designer.AST.Location)

Example 44 with Location

use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method createTextEdit.

private TextEdit[] createTextEdit(final IFile toVisit, final String fileContent, final Edit e, final Map<Edit, InsertEdit> editsDone) {
    // check for multi-declaration statement
    if (e.declSt.isMultiDeclaration()) {
        final Location cutLoc = calculateMultiDeclarationCutLoc(fileContent, e.declSt);
        final String moveContent = calculateMultiDeclarationMoveContent(fileContent, e.declSt);
        // remove stmt from multi-declaration
        e.declSt.removeFromMultiDeclaration();
        // create remove edit
        final int cutLen = cutLoc.getEndOffset() - cutLoc.getOffset();
        final TextEdit cut = new DeleteEdit(cutLoc.getOffset(), cutLen);
        // create insert edit
        InsertEdit insert = null;
        if (!e.isRemoveEdit()) {
            // update insert location if the insertionPoint stmt was moved
            int insertOffset = ((ILocateableNode) e.insertionPoint.getAstNode()).getLocation().getOffset();
            for (Map.Entry<Edit, InsertEdit> ed : editsDone.entrySet()) {
                if (ed.getKey().declSt.equals(e.insertionPoint)) {
                    insertOffset = ed.getValue().getOffset();
                    break;
                }
            }
            // 
            insertOffset = findLineBeginningOffset(fileContent, insertOffset);
            insert = new InsertEdit(insertOffset, moveContent);
            editsDone.put(e, insert);
        }
        if (insert != null) {
            return new TextEdit[] { insert, cut };
        }
        return new TextEdit[] { cut };
    } else {
        // 
        final Location cutLoc = findStatementLocation(fileContent, ((ILocateableNode) e.declSt.getAstNode()).getLocation(), true);
        InsertEdit insert = null;
        if (!e.isRemoveEdit()) {
            final Location copyLoc = findStatementLocation(fileContent, ((ILocateableNode) e.declSt.getAstNode()).getLocation(), false);
            // update insert location if the insertionPoint stmt was moved
            final Location insPLoc = ((ILocateableNode) e.insertionPoint.getAstNode()).getLocation();
            int insertOffset = insPLoc.getOffset();
            for (Map.Entry<Edit, InsertEdit> ed : editsDone.entrySet()) {
                if (ed.getKey().declSt.equals(e.insertionPoint)) {
                    insertOffset = ed.getValue().getOffset();
                    break;
                }
            }
            // 
            final int prefixStartOffset = findLineBeginningOffset(fileContent, insertOffset);
            final String insertText = fileContent.substring(copyLoc.getOffset(), copyLoc.getEndOffset()) + "\n";
            String insertPrefix = fileContent.substring(prefixStartOffset, insertOffset);
            // if prefix is not whitespace only, do not use the prefix
            if (!insertPrefix.trim().equals("")) {
                insertPrefix = "";
            }
            insert = new InsertEdit(prefixStartOffset, insertPrefix + insertText);
            editsDone.put(e, insert);
        }
        final int cutLen = cutLoc.getEndOffset() - cutLoc.getOffset();
        final TextEdit cut = new DeleteEdit(cutLoc.getOffset(), cutLen);
        // System.err.println("DeleteEdit: " + fileContent.substring(cutLoc.getOffset(), cutLoc.getEndOffset()));
        if (insert != null) {
            return new TextEdit[] { insert, cut };
        }
        return new TextEdit[] { cut };
    }
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) Edit(org.eclipse.titanium.refactoring.scope.nodes.Edit) InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) Map(java.util.Map) HashMap(java.util.HashMap) Location(org.eclipse.titan.designer.AST.Location)

Example 45 with Location

use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.

the class StatementNode method toString.

@Override
public String toString() {
    final StringBuilder sb = new StringBuilder();
    sb.append("SN(").append(astNode.toString()).append("), loc: ");
    if (astNode instanceof ILocateableNode) {
        final Location loc = ((ILocateableNode) astNode).getLocation();
        sb.append(loc.getOffset()).append('-').append(loc.getEndOffset()).append(';');
    } else {
        sb.append("<none>;");
    }
    sb.append(" parent: ");
    if (parent == null) {
        sb.append("<null>; ");
    } else {
        sb.append("BN(").append(parent.astNode.toString()).append("); ");
    }
    if (moved) {
        sb.append("MOVED; ");
    }
    if (isDeclaration()) {
        sb.append("declaration: " + declaredVar);
    }
    return sb.toString();
}
Also used : ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

Location (org.eclipse.titan.designer.AST.Location)109 Identifier (org.eclipse.titan.designer.AST.Identifier)24 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)24 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)21 IIdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser)18 IdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser)18 Module (org.eclipse.titan.designer.AST.Module)16 ArrayList (java.util.ArrayList)15 IFile (org.eclipse.core.resources.IFile)13 HashMap (java.util.HashMap)11 Reference (org.eclipse.titan.designer.AST.Reference)10 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)10 Assignment (org.eclipse.titan.designer.AST.Assignment)9 IDocument (org.eclipse.jface.text.IDocument)8 InsertEdit (org.eclipse.text.edits.InsertEdit)8 ILocateableNode (org.eclipse.titan.designer.AST.ILocateableNode)8 CoreException (org.eclipse.core.runtime.CoreException)7 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)7 TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)7 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7