Search in sources :

Example 1 with Declaration

use of org.eclipse.titan.designer.declarationsearch.Declaration in project titan.EclipsePlug-ins by eclipse.

the class ReferenceFinder method detectAssignmentDataByOffset.

public boolean detectAssignmentDataByOffset(final Module module, final int offset, final IEditorPart targetEditor, final boolean reportErrors, final boolean reportDebugInformation) {
    // detect the scope we are in
    scope = module.getSmallestEnclosingScope(offset);
    if (scope == null) {
        if (reportErrors) {
            targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NORECOGNISABLESCOPE);
        }
        return false;
    }
    final IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
    module.accept(visitor);
    final Declaration declaration = visitor.getReferencedDeclaration();
    if (declaration == null) {
        return false;
    }
    assignment = declaration.getAssignment();
    if (assignment == null) {
        if (reportErrors) {
            targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NORECOGNISABLEASSIGNMENT);
        }
        return false;
    }
    scope = detectSmallestScope(assignment);
    // assignments which are created during SA
    if (assignment instanceof Undefined_Assignment) {
        assignment = ((Undefined_Assignment) assignment).getRealAssignment(CompilationTimeStamp.getBaseTimestamp());
        if (assignment == null) {
            if (reportErrors) {
                targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NORECOGNISABLEASSIGNMENT);
            }
            return false;
        }
    }
    // in a field
    if (assignment.getAssignmentType() == Assignment_type.A_TYPE) {
        type = assignment.getType(CompilationTimeStamp.getBaseTimestamp());
        if (type == null) {
            if (reportErrors) {
                targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOASSIGNMENTTYPE);
            }
            return false;
        }
        type.getEnclosingField(offset, this);
        type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    }
    if (reportDebugInformation) {
        final MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
        TITANDebugConsole.println("found scope: name=" + scope.getScopeName() + "  type=" + scope.getClass().getName(), stream);
        TITANDebugConsole.println("found assignment: name=" + assignment.getIdentifier().getDisplayName() + "  type=" + assignment.getClass().getName(), stream);
        if (type != null) {
            TITANDebugConsole.println("found type: name=" + type.getTypename() + "  type=" + type.getClass().getName(), stream);
        }
        if (fieldId != null) {
            TITANDebugConsole.println("found field: name=" + fieldId.getDisplayName(), stream);
        }
    }
    return true;
}
Also used : Undefined_Assignment(org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment) IdentifierFinderVisitor(org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration)

Example 2 with Declaration

use of org.eclipse.titan.designer.declarationsearch.Declaration in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Set_Seq_Choice_BaseType method resolveReference.

@Override
public /**
 * {@inheritDoc}
 */
Declaration resolveReference(final Reference reference, final int subRefIdx, final ISubReference lastSubreference) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    int actualIndex = subRefIdx;
    while (actualIndex < subreferences.size() && subreferences.get(actualIndex) instanceof ArraySubReference) {
        ++actualIndex;
    }
    if (actualIndex == subreferences.size()) {
        return null;
    }
    final Identifier fieldID = subreferences.get(actualIndex).getId();
    if (subreferences.get(actualIndex) == lastSubreference) {
        return Declaration.createInstance(getDefiningAssignment(), fieldID);
    }
    final CompField compField = getComponentByName(fieldID);
    final IType compFieldType = compField.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (compFieldType instanceof IReferenceableElement) {
        final Declaration decl = ((IReferenceableElement) compFieldType).resolveReference(reference, actualIndex + 1, lastSubreference);
        return decl != null ? decl : Declaration.createInstance(getDefiningAssignment(), compField.getIdentifier());
    }
    return null;
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration) IReferenceableElement(org.eclipse.titan.designer.AST.IReferenceableElement) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) IType(org.eclipse.titan.designer.AST.IType)

Example 3 with Declaration

use of org.eclipse.titan.designer.declarationsearch.Declaration in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method doOpenDeclaration.

private final void doOpenDeclaration() {
    if (targetEditor == null || !(targetEditor instanceof TTCNPPEditor)) {
        return;
    }
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    if (ResourceExclusionHelper.isExcluded(file)) {
        MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
        return;
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((TTCNPPEditor) targetEditor).getCarretOffset();
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("Can not find the module.");
        }
        return;
    }
    IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
    module.accept(visitor);
    final Declaration decl = visitor.getReferencedDeclaration();
    if (decl == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("No visible elements found");
        }
        return;
    }
    selectAndRevealDeclaration(decl.getIdentifier().getLocation());
}
Also used : TTCNPPEditor(org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor) IFile(org.eclipse.core.resources.IFile) IdentifierFinderVisitor(org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor) TextSelection(org.eclipse.jface.text.TextSelection) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration) Module(org.eclipse.titan.designer.AST.Module) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 4 with Declaration

use of org.eclipse.titan.designer.declarationsearch.Declaration in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method doOpenDeclaration.

private final void doOpenDeclaration() {
    if (targetEditor == null || !(targetEditor instanceof TTCN3Editor)) {
        return;
    }
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    if (ResourceExclusionHelper.isExcluded(file)) {
        MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
        return;
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (selection instanceof TextSelection && !selection.isEmpty() && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((TTCN3Editor) targetEditor).getCarretOffset();
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("The file " + file.getLocation() + "does not seem to contain a valid module.");
            CompilationTimeStamp timestamp = projectSourceParser.getLastTimeChecked();
            if (timestamp == null) {
                TITANDebugConsole.println("The project " + file.getProject() + " was not yet analyzed semantically");
            } else {
                TITANDebugConsole.println("The project " + file.getProject() + " was last checked in " + projectSourceParser.getLastTimeChecked().toString());
            }
        }
        return;
    }
    IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
    module.accept(visitor);
    final Declaration decl = visitor.getReferencedDeclaration();
    if (decl == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("No visible elements found");
        }
        return;
    }
    selectAndRevealDeclaration(decl.getIdentifier().getLocation());
    return;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) IdentifierFinderVisitor(org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor) TextSelection(org.eclipse.jface.text.TextSelection) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration) Module(org.eclipse.titan.designer.AST.Module) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 5 with Declaration

use of org.eclipse.titan.designer.declarationsearch.Declaration in project titan.EclipsePlug-ins by eclipse.

the class OccurencesMarker method findOccurrencesLocationBased.

/**
 * Finds the occurrences of the element located on the given offset.
 * This search is based on the {@link ASTLocationChainVisitor}.
 *
 * @param module
 *                The module to search the occurrences in
 * @param offset
 *                An offset in the module
 * @return The found references. Includes the definition of the element.
 */
protected List<Hit> findOccurrencesLocationBased(final Module module, final int offset) {
    final IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
    module.accept(visitor);
    final Declaration def = visitor.getReferencedDeclaration();
    if (def == null || !def.shouldMarkOccurrences()) {
        removeOccurences(false);
        return new ArrayList<Hit>();
    }
    return def.getReferences(module);
}
Also used : IdentifierFinderVisitor(org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor) ArrayList(java.util.ArrayList) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration)

Aggregations

Declaration (org.eclipse.titan.designer.declarationsearch.Declaration)8 IdentifierFinderVisitor (org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor)6 IFile (org.eclipse.core.resources.IFile)3 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)3 TextSelection (org.eclipse.jface.text.TextSelection)3 Module (org.eclipse.titan.designer.AST.Module)3 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)3 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2 IReferenceableElement (org.eclipse.titan.designer.AST.IReferenceableElement)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 IType (org.eclipse.titan.designer.AST.IType)2 ArrayList (java.util.ArrayList)1 Undefined_Assignment (org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)1 ASN1Editor (org.eclipse.titan.designer.editors.asn1editor.ASN1Editor)1 TTCN3Editor (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor)1 TTCNPPEditor (org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor)1 CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)1 MessageConsoleStream (org.eclipse.ui.console.MessageConsoleStream)1