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