Search in sources :

Example 76 with Location

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

the class OccurencesMarker method doMark.

private void doMark(final IDocument document, final int offset) {
    IAnnotationModel annotationModel = getAnnotationModel();
    if (annotationModel == null) {
        removeOccurences(false);
        error(document, offset, "AnnotationModel is null");
        return;
    }
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        removeOccurences(false);
        error(document, offset, "can not determine the file in the editor.");
        return;
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    if (projectSourceParser == null) {
        removeOccurences(false);
        error(document, offset, "Can not find the projectsourceparser for the project: " + file.getProject());
        return;
    }
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        removeOccurences(false);
        error(document, offset, "The module can not be found in the project.");
        return;
    }
    if (printASTElem.getValue()) {
        ASTLocationChainVisitor locVisitor = new ASTLocationChainVisitor(offset);
        module.accept(locVisitor);
        locVisitor.printChain();
    }
    final Reference reference = getReferenceParser().findReferenceForOpening(file, offset, document);
    if (reference == null) {
        removeOccurences(false);
        // "The reference can not be parsed.");
        return;
    }
    final Location referenceLocaton = reference.getLocation();
    if (referenceLocaton.getOffset() == referenceLocaton.getEndOffset()) {
        removeOccurences(false);
        return;
    }
    // if (reportDebugInformation) {
    // ASTLocationConsistencyVisitor visitor = new
    // ASTLocationConsistencyVisitor(document,
    // module.get_moduletype()==Module.module_type.TTCN3_MODULE);
    // module.accept(visitor);
    // }
    final List<Hit> result = findOccurrences(document, reference, module, offset);
    if (result.isEmpty()) {
        return;
    }
    Map<Annotation, Position> annotationMap = new HashMap<Annotation, Position>();
    for (Hit hit : result) {
        if (hit.identifier != null) {
            int hitOffset = hit.identifier.getLocation().getOffset();
            int hitEndOffset = hit.identifier.getLocation().getEndOffset();
            if (hitOffset >= 0 && hitEndOffset >= 0 && hitEndOffset >= hitOffset) {
                final Annotation annotationToAdd = new Annotation(ANNOTATION_TYPE, false, hit.identifier.getDisplayName());
                final Position position = new Position(hitOffset, hitEndOffset - hitOffset);
                annotationMap.put(annotationToAdd, position);
            }
        }
    }
    synchronized (getLockObject(annotationModel)) {
        if (annotationModel instanceof IAnnotationModelExtension) {
            ((IAnnotationModelExtension) annotationModel).replaceAnnotations(occurrenceAnnotations, annotationMap);
        } else {
            if (occurrenceAnnotations != null) {
                for (Annotation annotationToRemove : occurrenceAnnotations) {
                    annotationModel.removeAnnotation(annotationToRemove);
                }
            }
            for (Map.Entry<Annotation, Position> entry : annotationMap.entrySet()) {
                annotationModel.addAnnotation(entry.getKey(), entry.getValue());
            }
        }
        occurrenceAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) Reference(org.eclipse.titan.designer.AST.Reference) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Annotation(org.eclipse.jface.text.source.Annotation) Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) ASTLocationChainVisitor(org.eclipse.titan.designer.AST.ASTLocationChainVisitor) Module(org.eclipse.titan.designer.AST.Module) HashMap(java.util.HashMap) Map(java.util.Map) Location(org.eclipse.titan.designer.AST.Location)

Example 77 with Location

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

the class ContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
    IDocument doc = viewer.getDocument();
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    int ofs = findWordStart(offset, doc);
    String incompleteString = "";
    try {
        if (doc != null && offset >= ofs) {
            incompleteString = doc.get(ofs, offset - ofs);
        }
    } catch (BadLocationException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    String[] reference = incompleteString.trim().split(REFERENCE_SPLITTER, -1);
    Reference ref = new Reference(null);
    ref.setLocation(new Location(file, 0, 0, offset - ofs));
    FieldSubReference subref = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, reference[0]));
    subref.setLocation(new Location(file, 0, 0, reference[0].length()));
    ref.addSubReference(subref);
    if (reference.length > 1) {
        subref = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, reference[1]));
        subref.setLocation(new Location(file, 0, reference[0].length() + 1, offset - ofs));
        ref.addSubReference(subref);
    }
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, doc, ref, ofs);
    propCollector.addProposal(CodeScanner.SECTION_TITLES, null, KEYWORD);
    propCollector.addProposal(CodeScanner.KEYWORDS, null, KEYWORD);
    propCollector.addProposal(CodeScanner.MASK_OPTIONS, null, KEYWORD);
    propCollector.addProposal(CodeScanner.EXTERNAL_COMMAND_TYPES, null, KEYWORD);
    propCollector.addProposal(CodeScanner.OPTIONS, null, KEYWORD);
    String sortingpolicy = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CONTENTASSISTANT_PROPOSAL_SORTING);
    if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
        propCollector.sortAll();
    }
    return propCollector.getCompletitions();
}
Also used : ProposalCollector(org.eclipse.titan.designer.editors.ProposalCollector) IFile(org.eclipse.core.resources.IFile) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Location(org.eclipse.titan.designer.AST.Location)

Example 78 with Location

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

the class Definition method parseErrAttrSpecString.

private static ErroneousAttributeSpecification parseErrAttrSpecString(final AttributeSpecification aAttrSpec) {
    String code = aAttrSpec.getSpecification();
    if (code == null) {
        return null;
    }
    final Location location = aAttrSpec.getLocation();
    // code must be transformed, according to
    // compiler2/ttcn3/charstring_la.l
    // TODO
    code = Ttcn3CharstringLexer.parseCharstringValue(code, location);
    final Reader reader = new StringReader(code);
    final CharStream charStream = new UnbufferedCharStream(reader);
    final Ttcn3Lexer lexer = new Ttcn3Lexer(charStream);
    lexer.setTokenFactory(new CommonTokenFactory(true));
    // needs to be shifted by one because of the \" of the string
    lexer.setCharPositionInLine(0);
    // lexer and parser listener
    final TitanListener parserListener = new TitanListener();
    // remove ConsoleErrorListener
    lexer.removeErrorListeners();
    lexer.addErrorListener(parserListener);
    // 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);
    final Ttcn3Reparser parser = new Ttcn3Reparser(tokenStream);
    ParserUtilities.setBuildParseTree(parser);
    final IFile file = (IFile) location.getFile();
    parser.setActualFile(file);
    parser.setOffset(location.getOffset());
    parser.setLine(location.getLine());
    // remove ConsoleErrorListener
    parser.removeErrorListeners();
    parser.addErrorListener(parserListener);
    MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, location.getFile(), location.getOffset(), location.getEndOffset());
    final Pr_ErroneousAttributeSpecContext root = parser.pr_ErroneousAttributeSpec();
    ParserUtilities.logParseTree(root, parser);
    final ErroneousAttributeSpecification returnValue = root.errAttrSpec;
    final List<SyntacticErrorStorage> errors = parser.getErrors();
    final List<TITANMarker> warnings = parser.getWarnings();
    final List<TITANMarker> unsupportedConstructs = parser.getUnsupportedConstructs();
    // add markers
    if (errors != null) {
        for (int i = 0; i < errors.size(); i++) {
            final Location temp = new Location(location);
            temp.setOffset(temp.getOffset());
            ParserMarkerSupport.createOnTheFlySyntacticMarker(file, errors.get(i), IMarker.SEVERITY_ERROR, temp);
        }
    }
    if (warnings != null) {
        for (final TITANMarker marker : warnings) {
            if (file.isAccessible()) {
                final Location loc = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
                loc.reportExternalProblem(marker.getMessage(), marker.getSeverity(), GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
            }
        }
    }
    if (unsupportedConstructs != null) {
        for (final TITANMarker marker : unsupportedConstructs) {
            if (file.isAccessible()) {
                final Location loc = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
                loc.reportExternalProblem(marker.getMessage(), marker.getSeverity(), GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
            }
        }
    }
    return returnValue;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CommonTokenFactory(org.antlr.v4.runtime.CommonTokenFactory) IFile(org.eclipse.core.resources.IFile) ErroneousAttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributeSpecification) Ttcn3Reparser(org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Reparser) Ttcn3Lexer(org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Lexer) Reader(java.io.Reader) StringReader(java.io.StringReader) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) CharStream(org.antlr.v4.runtime.CharStream) TitanListener(org.eclipse.titan.common.parsers.TitanListener) TITANMarker(org.eclipse.titan.common.parsers.TITANMarker) Pr_ErroneousAttributeSpecContext(org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Reparser.Pr_ErroneousAttributeSpecContext) SyntacticErrorStorage(org.eclipse.titan.common.parsers.SyntacticErrorStorage) StringReader(java.io.StringReader) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) Location(org.eclipse.titan.designer.AST.Location)

Example 79 with Location

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

the class Definitions method updateSyntax.

/**
 * Handles the incremental parsing of this list of definitions.
 *
 * @param reparser
 *                the parser doing the incremental parsing.
 * @param importedModules
 *                the list of module importations found in the same
 *                module.
 * @param friendModules
 *                the list of friend module declaration in the same
 *                module.
 * @param controlpart
 *                the control part found in the same module.
 * @throws ReParseException
 *                 if there was an error while refreshing the location
 *                 information and it could not be solved internally.
 */
public void updateSyntax(final TTCN3ReparseUpdater reparser, final List<ImportModule> importedModules, final List<FriendModule> friendModules, final ControlPart controlpart) throws ReParseException {
    // calculate damaged region
    int result = 0;
    boolean enveloped = false;
    int nofDamaged = 0;
    int leftBoundary = location.getOffset();
    int rightBoundary = location.getEndOffset();
    final int damageOffset = reparser.getDamageStart();
    final int damageEndOffset = reparser.getDamageEnd();
    IAppendableSyntax lastAppendableBeforeChange = null;
    IAppendableSyntax lastPrependableBeforeChange = null;
    boolean isControlPossible = controlpart == null;
    if (controlpart != null) {
        final Location tempLocation = controlpart.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
        } else if (!reparser.isDamaged(tempLocation)) {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = controlpart;
            }
            if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = controlpart;
            }
        }
    }
    for (int i = 0, size = groups.size(); i < size && !enveloped; i++) {
        final Group tempGroup = groups.get(i);
        final Location tempLocation = tempGroup.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = tempGroup;
            }
            if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = tempGroup;
            }
        }
    }
    if (!groups.isEmpty()) {
        isControlPossible &= groups.get(groups.size() - 1).getLocation().getEndOffset() < leftBoundary;
    }
    for (int i = 0, size = importedModules.size(); i < size && !enveloped; i++) {
        final ImportModule tempImport = importedModules.get(i);
        if (tempImport.getParentGroup() == null) {
            final Location tempLocation = tempImport.getLocation();
            if (reparser.envelopsDamage(tempLocation)) {
                enveloped = true;
                leftBoundary = tempLocation.getOffset();
                rightBoundary = tempLocation.getEndOffset();
            } else if (reparser.isDamaged(tempLocation)) {
                nofDamaged++;
            } else {
                if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                    leftBoundary = tempLocation.getEndOffset();
                    lastAppendableBeforeChange = tempImport;
                }
                if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
                    rightBoundary = tempLocation.getOffset();
                    lastPrependableBeforeChange = tempImport;
                }
            }
        }
    }
    if (!importedModules.isEmpty()) {
        isControlPossible &= importedModules.get(importedModules.size() - 1).getLocation().getEndOffset() < leftBoundary;
    }
    for (int i = 0, size = friendModules.size(); i < size && !enveloped; i++) {
        final FriendModule tempFriend = friendModules.get(i);
        if (tempFriend.getParentGroup() == null) {
            final Location tempLocation = tempFriend.getLocation();
            if (reparser.envelopsDamage(tempLocation)) {
                enveloped = true;
                leftBoundary = tempLocation.getOffset();
                rightBoundary = tempLocation.getEndOffset();
            } else if (reparser.isDamaged(tempLocation)) {
                nofDamaged++;
            } else {
                if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                    leftBoundary = tempLocation.getEndOffset();
                    lastAppendableBeforeChange = tempFriend;
                }
                if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
                    rightBoundary = tempLocation.getOffset();
                    lastPrependableBeforeChange = tempFriend;
                }
            }
        }
    }
    if (!friendModules.isEmpty()) {
        isControlPossible &= friendModules.get(friendModules.size() - 1).getLocation().getEndOffset() < leftBoundary;
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
        final Definition temp = iterator.next();
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
            if (tempLocation.equals(cumulativeLocation) && reparser.envelopsDamage(cumulativeLocation)) {
                enveloped = true;
                leftBoundary = cumulativeLocation.getOffset();
                rightBoundary = cumulativeLocation.getEndOffset();
            } else if (reparser.isDamaged(cumulativeLocation)) {
                nofDamaged++;
                if (reparser.getDamageStart() == cumulativeLocation.getEndOffset()) {
                    lastAppendableBeforeChange = temp;
                } else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
                    lastPrependableBeforeChange = temp;
                }
            } else {
                if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
                    leftBoundary = cumulativeLocation.getEndOffset();
                    lastAppendableBeforeChange = temp;
                }
                if (cumulativeLocation.getOffset() > damageEndOffset && cumulativeLocation.getOffset() < rightBoundary) {
                    rightBoundary = cumulativeLocation.getOffset();
                    lastPrependableBeforeChange = temp;
                }
            }
            final Location tempCommentLocation = temp.getCommentLocation();
            if (tempCommentLocation != null && reparser.isDamaged(tempCommentLocation)) {
                nofDamaged++;
                rightBoundary = tempLocation.getEndOffset();
            }
        }
    }
    if (!definitions.isEmpty()) {
        isControlPossible &= definitions.get(definitions.size() - 1).getLocation().getEndOffset() < leftBoundary;
    }
    // was not enveloped
    if (!enveloped && reparser.isDamaged(location)) {
        // the extension might be correct
        if (lastAppendableBeforeChange != null) {
            final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
            if (isBeingExtended) {
                leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
                nofDamaged++;
                enveloped = false;
                reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            }
        }
        if (lastPrependableBeforeChange != null) {
            final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
            if (temp != null && reparser.endsWithToken(temp)) {
                rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
                nofDamaged++;
                enveloped = false;
                reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            }
        }
        if (nofDamaged != 0) {
            // remove damaged stuff
            removeStuffInRange(reparser, importedModules, friendModules);
            if (doubleDefinitions != null) {
                doubleDefinitions.clear();
            }
            lastUniquenessCheckTimeStamp = null;
            lastCompilationTimeStamp = null;
        }
        // extend damaged region till the neighbor definitions just here to avoid calculating something damaged or extended:
        // Perhaps it should be moved even farther:
        reparser.extendDamagedRegion(leftBoundary, rightBoundary);
    }
    // update what is left
    for (int i = 0; i < groups.size(); i++) {
        final Group temp = groups.get(i);
        final Location tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, importedModules, definitions, friendModules);
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    groups.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    if (doubleDefinitions != null) {
                        doubleDefinitions.clear();
                    }
                    lastUniquenessCheckTimeStamp = null;
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (int i = 0; i < importedModules.size(); i++) {
        final ImportModule temp = importedModules.get(i);
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            if (reparser.isAffected(tempLocation)) {
                try {
                    final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
                    temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
                    if (isDamaged) {
                        ((TTCN3Module) parentScope).checkRoot();
                    }
                } catch (ReParseException e) {
                    if (e.getDepth() == 1) {
                        enveloped = false;
                        importedModules.remove(i);
                        i--;
                        reparser.extendDamagedRegion(tempLocation);
                        result = 1;
                    } else {
                        if (doubleDefinitions != null) {
                            doubleDefinitions.clear();
                        }
                        lastUniquenessCheckTimeStamp = null;
                        e.decreaseDepth();
                        throw e;
                    }
                }
            }
        }
    }
    for (int i = 0; i < friendModules.size(); i++) {
        final FriendModule temp = friendModules.get(i);
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            if (reparser.isAffected(tempLocation)) {
                try {
                    final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
                    temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
                    if (isDamaged) {
                        ((TTCN3Module) parentScope).checkRoot();
                    }
                } catch (ReParseException e) {
                    if (e.getDepth() == 1) {
                        enveloped = false;
                        friendModules.remove(i);
                        i--;
                        reparser.extendDamagedRegion(tempLocation);
                        result = 1;
                    } else {
                        if (doubleDefinitions != null) {
                            doubleDefinitions.clear();
                        }
                        lastUniquenessCheckTimeStamp = null;
                        e.decreaseDepth();
                        throw e;
                    }
                }
            }
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
            if (reparser.isAffected(cumulativeLocation)) {
                try {
                    final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
                    temp.updateSyntax(reparser, isDamaged);
                    if (reparser.getNameChanged()) {
                        if (doubleDefinitions != null) {
                            doubleDefinitions.clear();
                        }
                        lastUniquenessCheckTimeStamp = null;
                        // to recheck the whole module
                        lastCompilationTimeStamp = null;
                        reparser.setNameChanged(false);
                    // This could also spread
                    }
                    if (isDamaged) {
                        // TODO lets move this into the definitions
                        temp.checkRoot();
                    }
                } catch (ReParseException e) {
                    if (e.getDepth() == 1) {
                        enveloped = false;
                        definitions.remove(temp);
                        reparser.extendDamagedRegion(cumulativeLocation);
                        result = 1;
                    } else {
                        if (doubleDefinitions != null) {
                            doubleDefinitions.clear();
                        }
                        lastUniquenessCheckTimeStamp = null;
                        e.decreaseDepth();
                        throw e;
                    }
                }
            }
        }
    }
    if (result == 1) {
        removeStuffInRange(reparser, importedModules, friendModules);
        if (doubleDefinitions != null) {
            doubleDefinitions.clear();
        }
        lastUniquenessCheckTimeStamp = null;
        lastCompilationTimeStamp = null;
    }
    for (int i = 0, size = groups.size(); i < size; i++) {
        final Group temp = groups.get(i);
        final Location tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (int i = 0, size = importedModules.size(); i < size; i++) {
        final ImportModule temp = importedModules.get(i);
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            if (reparser.isAffected(tempLocation)) {
                reparser.updateLocation(tempLocation);
            }
        }
    }
    for (int i = 0, size = friendModules.size(); i < size; i++) {
        final FriendModule temp = friendModules.get(i);
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            if (reparser.isAffected(tempLocation)) {
                reparser.updateLocation(tempLocation);
            }
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        if (temp.getParentGroup() == null) {
            final Location tempLocation = temp.getLocation();
            final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
            if (reparser.isAffected(tempLocation)) {
                if (tempLocation != cumulativeLocation) {
                    reparser.updateLocation(cumulativeLocation);
                }
                reparser.updateLocation(tempLocation);
            }
        }
    }
    final boolean tempIsControlPossible = isControlPossible;
    if (!enveloped) {
        if (reparser.envelopsDamage(location)) {
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            result = reparse(reparser, tempIsControlPossible);
            result = Math.max(result - 1, 0);
            lastCompilationTimeStamp = null;
        } else {
            result = Math.max(result, 1);
        }
    }
    if (result == 0) {
        lastUniquenessCheckTimeStamp = null;
    } else {
        if (doubleDefinitions != null) {
            doubleDefinitions.clear();
        }
        lastUniquenessCheckTimeStamp = null;
        throw new ReParseException(result);
    }
}
Also used : IAppendableSyntax(org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 80 with Location

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

the class Definitions method checkWithDefinitions.

/**
 * Experimental method for BrokenPartsViaInvertedImports.
 * The only difference to check() that not all assignments will be rechecked, just the listed in "assignments"
 */
public void checkWithDefinitions(final CompilationTimeStamp timestamp, final List<Assignment> assignments) {
    if (lastCompilationTimeStamp != null && !lastCompilationTimeStamp.isLess(timestamp)) {
        return;
    }
    if (lastCompilationTimeStamp == null) {
        // fall back to checking each definition:
        check(timestamp);
        return;
    }
    lastCompilationTimeStamp = timestamp;
    for (final Assignment assignment : assignments) {
        if (assignment.getLastTimeChecked() == null || assignment.getLastTimeChecked().isLess(timestamp)) {
            MarkerHandler.markAllSemanticMarkersForRemoval(assignment);
        }
    }
    int maxEndOffset = getLocation().getOffset();
    int lastEndOffset = 0;
    for (final Definition definition : definitions) {
        lastEndOffset = definition.getLocation().getEndOffset();
        if (lastEndOffset > maxEndOffset) {
            maxEndOffset = lastEndOffset;
        }
    }
    for (final Group group : groups) {
        group.markMarkersForRemoval(timestamp);
    }
    // remove markers on the final commented lines (for incremental parsing)
    final int defsEndOffset = getLocation().getEndOffset();
    if (maxEndOffset < defsEndOffset) {
        final Location loc = new Location(getLocation().getFile(), 0, maxEndOffset, defsEndOffset);
        MarkerHandler.markAllSemanticMarkersForRemoval(loc);
    }
    checkUniqueness(timestamp);
    checkGroups(timestamp);
    for (final Iterator<Assignment> iterator = assignments.iterator(); iterator.hasNext(); ) {
        final Assignment assignmentFrom = iterator.next();
        assignmentFrom.check(timestamp);
        LoadBalancingUtilities.astNodeChecked();
    }
    // perhaps checkUniqueness() was executed earlier and their markers have been removed
    reportDoubleDefinitions();
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) 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