use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method createFileChange.
private Change createFileChange(final IFile toVisit) {
if (toVisit == null) {
return null;
}
final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
final Module module = sourceParser.containedModule(toVisit);
if (module == null) {
return null;
}
// find all locations in the module that should be edited
final DefinitionVisitor vis = new DefinitionVisitor();
module.accept(vis);
final NavigableSet<Definition> nodes = vis.getLocations();
if (nodes.isEmpty()) {
return null;
}
// calculate edit locations
final List<Definition> locations = new ArrayList<Definition>();
try {
final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, locations);
job1.join();
} catch (InterruptedException ie) {
ErrorReporter.logExceptionStackTrace(ie);
} catch (CoreException ce) {
ErrorReporter.logError("UngroupModuleparRefactoring/CreateChange.createFileChange(): " + "CoreException while calculating edit locations. ");
ErrorReporter.logExceptionStackTrace(ce);
}
if (locations.isEmpty()) {
return null;
}
// create a change for each edit location
final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
final MultiTextEdit rootEdit = new MultiTextEdit();
tfc.setEdit(rootEdit);
int precedeOffset = -1;
final String fileContents = loadFileContent(toVisit);
for (Definition node : locations) {
final Location l = node.getCumulativeDefinitionLocation();
final Location typeLocation = node.getType(CompilationTimeStamp.getBaseTimestamp()).getLocation();
final Location identifierLocation = node.getIdentifier().getLocation();
if (precedeOffset != l.getOffset()) {
precedeOffset = l.getOffset();
final int len = l.getEndOffset() - l.getOffset();
rootEdit.addChild(new DeleteEdit(l.getOffset(), len + 1));
}
String typeText = fileContents.substring(typeLocation.getOffset(), typeLocation.getEndOffset()).trim();
String name = fileContents.substring(identifierLocation.getOffset(), identifierLocation.getEndOffset()).trim();
String newModulePar = "";
if (node instanceof Def_ModulePar) {
Def_ModulePar modulePar = (Def_ModulePar) node;
if (modulePar.getDefaultValue() != null) {
final Location valueLocation = modulePar.getDefaultValue().getLocation();
String valueText = fileContents.substring(valueLocation.getOffset(), valueLocation.getEndOffset()).trim();
newModulePar = "modulepar " + typeText + " " + name + " := " + valueText + ";\n";
} else {
newModulePar = "modulepar " + typeText + " " + name + ";\n";
}
} else if (node instanceof Def_ModulePar_Template) {
Def_ModulePar_Template modulePar = (Def_ModulePar_Template) node;
if (modulePar.getDefaultTemplate() != null) {
final Location valueLocation = modulePar.getDefaultTemplate().getLocation();
String temlateText = fileContents.substring(valueLocation.getOffset(), valueLocation.getEndOffset()).trim();
newModulePar = "modulepar template " + typeText + " " + name + " := " + temlateText + ";\n";
} else {
newModulePar = "modulepar template " + typeText + " " + name + ";\n";
}
}
rootEdit.addChild(new InsertEdit(l.getOffset(), newModulePar));
}
return tfc;
}
use of org.eclipse.titan.designer.AST.Module 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.Module in project titan.EclipsePlug-ins by eclipse.
the class T3Doc method getCommentStringBasedOnReference.
public static String getCommentStringBasedOnReference(final DeclarationCollector declarationCollector, final List<DeclarationCollectionHelper> collected, final IEditorPart targetEditor, final IRegion hoverRegion, final IReferenceParser referenceParser, final ITextViewer textViewer) {
if (!T3Doc.isT3DocEnable()) {
return null;
}
Reference ref = declarationCollector.getReference();
if (ref == null) {
return null;
}
if ((ref.getMyScope() instanceof NamedBridgeScope || ref.getMyScope() instanceof FormalParameterList) && !collected.isEmpty()) {
DeclarationCollectionHelper declaration = collected.get(0);
if (declaration.node instanceof TTCN3_Sequence_Type || declaration.node instanceof FormalParameter) {
final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module tempModule = projectSourceParser.containedModule(file);
Assignment ass = tempModule.getEnclosingAssignment(hoverRegion.getOffset());
if (ass != null) {
Reference reference = referenceParser.findReferenceForOpening(file, hoverRegion.getOffset(), textViewer.getDocument());
String str = reference.getDisplayName();
List<String> al = T3Doc.getCommentStrings(ass.getCommentLocation(), str);
if (!al.isEmpty()) {
final StringBuilder sb = new StringBuilder();
for (String string : al) {
sb.append(string);
}
return sb.toString();
}
}
}
}
return null;
}
use of org.eclipse.titan.designer.AST.Module 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.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class OutlinePage method refresh.
public void refresh() {
Control control = getControl();
if (control.isDisposed()) {
return;
}
control.setRedraw(false);
Module module = getModule();
if (getTreeViewer().getInput() == module) {
getTreeViewer().refresh();
getTreeViewer().expandToLevel(2);
} else {
getTreeViewer().setInput(getModule());
}
control.setRedraw(true);
}
Aggregations