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());
}
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);
}
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;
}
Aggregations