Search in sources :

Example 6 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 ASN1Editor)) {
        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 = ((ASN1Editor) targetEditor).getCarretOffset();
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        // TODO: How could this happen??? (NPE occured)
        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 : ASN1Editor(org.eclipse.titan.designer.editors.asn1editor.ASN1Editor) 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 7 with Declaration

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

the class RenameRefactoring 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 referencefinder
 */
protected static ReferenceFinder findOccurrencesLocationBased(final Module module, final int offset) {
    final IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
    module.accept(visitor);
    // It works for fields as well
    final Declaration def = visitor.getReferencedDeclaration();
    if (def == null || !def.shouldMarkOccurrences()) {
        return null;
    }
    return def.getReferenceFinder(module);
}
Also used : IdentifierFinderVisitor(org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration)

Example 8 with Declaration

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

the class TTCN3_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 localIndex = subRefIdx;
    while (localIndex < subreferences.size() && subreferences.get(localIndex) instanceof ArraySubReference) {
        ++localIndex;
    }
    if (localIndex == subreferences.size()) {
        return null;
    }
    final CompField compField = getComponentByName(subreferences.get(localIndex).getId().getName());
    if (compField == null) {
        return null;
    }
    if (subreferences.get(localIndex) == lastSubreference) {
        return Declaration.createInstance(getDefiningAssignment(), compField.getIdentifier());
    }
    final IType compFieldType = compField.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (compFieldType instanceof IReferenceableElement) {
        final Declaration decl = ((IReferenceableElement) compFieldType).resolveReference(reference, localIndex + 1, lastSubreference);
        return decl != null ? decl : Declaration.createInstance(getDefiningAssignment(), compField.getIdentifier());
    }
    return null;
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) 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)

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