Search in sources :

Example 6 with Hit

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

the class ReferenceSearchQuery method run.

@Override
public IStatus run(final IProgressMonitor monitor) {
    result.removeAll();
    Map<Module, List<Hit>> map = referenceFinder.findAllReferences(module, project, monitor, false);
    for (Map.Entry<Module, List<Hit>> entry : map.entrySet()) {
        IResource resource = entry.getKey().getLocation().getFile();
        if (!(resource instanceof IFile)) {
            continue;
        }
        for (Hit hit : entry.getValue()) {
            result.addMatch(new ReferenceSearchMatch(hit.identifier));
        }
    }
    monitor.done();
    return new Status(IStatus.OK, ProductConstants.PRODUCT_ID_DESIGNER, IStatus.OK, "Search done.", null);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) IFile(org.eclipse.core.resources.IFile) List(java.util.List) Module(org.eclipse.titan.designer.AST.Module) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource)

Example 7 with Hit

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

the class DefinitionDeclaration method getReferences.

@Override
public List<Hit> getReferences(final Module module) {
    try {
        final ReferenceFinder referenceFinder = new ReferenceFinder(ass);
        final List<Hit> result = referenceFinder.findReferencesInModule(module);
        if (ass.getMyScope().getModuleScope() == module) {
            result.add(new Hit(ass.getIdentifier()));
        }
        return result;
    } catch (final IllegalArgumentException e) {
        return new ArrayList<ReferenceFinder.Hit>();
    }
}
Also used : Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) ReferenceFinder(org.eclipse.titan.designer.AST.ReferenceFinder)

Example 8 with Hit

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

the class FieldDeclaration method getReferences.

@Override
public List<Hit> getReferences(final Module module) {
    try {
        final ReferenceFinder referenceFinder = new ReferenceFinder(ass);
        referenceFinder.fieldId = fieldId;
        final List<Hit> result = referenceFinder.findReferencesInModule(module);
        if (ass.getMyScope().getModuleScope() == module) {
            result.add(new Hit(fieldId));
        }
        return result;
    } catch (final IllegalArgumentException e) {
        return new ArrayList<ReferenceFinder.Hit>();
    }
}
Also used : Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) ReferenceFinder(org.eclipse.titan.designer.AST.ReferenceFinder)

Example 9 with Hit

use of org.eclipse.titan.designer.AST.ReferenceFinder.Hit 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 10 with Hit

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

the class RenameRefactoring method createChange.

@Override
public Change createChange(final IProgressMonitor pm) throws CoreException {
    CompositeChange result = new CompositeChange(getName());
    // add the change of all found identifiers grouped by module
    boolean isAsnRename = module.getModuletype() == Module.module_type.ASN_MODULE;
    String newTtcnIdentifierName = newIdentifierName;
    if (isAsnRename) {
        newTtcnIdentifierName = Identifier.getTtcnNameFromAsnName(newIdentifierName);
    }
    List<IFile> filesToProcess = new ArrayList<IFile>(idsMap.size());
    for (Module m : idsMap.keySet()) {
        List<Hit> hitList = idsMap.get(m);
        boolean isTtcnModule = m.getModuletype() == Module.module_type.TTCN3_MODULE;
        IFile file = (IFile) hitList.get(0).identifier.getLocation().getFile();
        TextFileChange tfc = new TextFileChange(file.getName(), file);
        result.add(tfc);
        MultiTextEdit rootEdit = new MultiTextEdit();
        tfc.setEdit(rootEdit);
        for (Hit hit : hitList) {
            int offset = hit.identifier.getLocation().getOffset();
            int length = hit.identifier.getLocation().getEndOffset() - offset;
            String newName = isTtcnModule ? newTtcnIdentifierName : newIdentifierName;
            // reference.
            if (rf.fieldId == null && hit.reference != null && hit.reference.getModuleIdentifier() == null && rf.assignment.getMyScope().getModuleScope() != hit.reference.getMyScope().getModuleScope() && hit.reference.getMyScope().hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), new Identifier(isTtcnModule ? Identifier_type.ID_TTCN : Identifier_type.ID_ASN, newIdentifierName))) {
                newName = rf.assignment.getMyScope().getModuleScope().getName() + "." + newName;
            }
            rootEdit.addChild(new ReplaceEdit(offset, length, newName));
        }
        filesToProcess.add((IFile) m.getLocation().getFile());
    }
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) Identifier(org.eclipse.titan.designer.AST.Identifier) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Module(org.eclipse.titan.designer.AST.Module) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Aggregations

Hit (org.eclipse.titan.designer.AST.ReferenceFinder.Hit)11 ArrayList (java.util.ArrayList)5 Module (org.eclipse.titan.designer.AST.Module)4 IFile (org.eclipse.core.resources.IFile)3 Identifier (org.eclipse.titan.designer.AST.Identifier)3 Reference (org.eclipse.titan.designer.AST.Reference)3 ReferenceFinder (org.eclipse.titan.designer.AST.ReferenceFinder)3 Map (java.util.Map)2 ASN1Module (org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module)2 Assignment (org.eclipse.titan.designer.AST.Assignment)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 IType (org.eclipse.titan.designer.AST.IType)2 Scope (org.eclipse.titan.designer.AST.Scope)2 HashMap (java.util.HashMap)1 List (java.util.List)1 IResource (org.eclipse.core.resources.IResource)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Position (org.eclipse.jface.text.Position)1