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