use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class ContentAssistProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
IDocument doc = viewer.getDocument();
IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
ASN1ReferenceParser refParser = new ASN1ReferenceParser();
Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
IPreferencesService prefs = Platform.getPreferencesService();
if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
TITANDebugConsole.println("parsed the reference: " + ref);
}
if (ref == null || ref.getSubreferences().isEmpty()) {
return new ICompletionProposal[] {};
}
Scope scope = null;
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
Module tempModule = projectSourceParser.containedModule(file);
if (tempModule != null) {
scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
ref.setMyScope(scope);
ref.detectModid();
}
TemplateContextType contextType = new TemplateContextType(ASN1CodeSkeletons.CONTEXT_IDENTIFIER, ASN1CodeSkeletons.CONTEXT_NAME);
ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_ASN, ASN1CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
if (scope != null) {
scope.addProposal(propCollector);
propCollector.sortTillMarked();
propCollector.markPosition();
}
if (ref.getSubreferences().size() != 1) {
return propCollector.getCompletitions();
}
if (scope == null) {
propCollector.addProposal(CodeScanner.TAGS, null, KEYWORD);
} else {
ASN1CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
}
propCollector.sortTillMarked();
propCollector.markPosition();
propCollector.addProposal(CodeScanner.VERBS, null, KEYWORD);
propCollector.addProposal(CodeScanner.COMPARE_TYPES, null, KEYWORD);
propCollector.addProposal(CodeScanner.STATUS_TYPE, null, KEYWORD);
propCollector.addProposal(CodeScanner.KEYWORDS, null, KEYWORD);
propCollector.addProposal(CodeScanner.STORAGE, null, KEYWORD);
propCollector.addProposal(CodeScanner.MODIFIER, null, KEYWORD);
propCollector.addProposal(CodeScanner.ACCESS_TYPE, null, KEYWORD);
propCollector.sortTillMarked();
String sortingpolicy = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CONTENTASSISTANT_PROPOSAL_SORTING);
if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
propCollector.sortAll();
}
return propCollector.getCompletitions();
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class UnusedGlobalDefinition method process.
@Override
protected void process(IProject project, Problems problems) {
TITANDebugConsole.println("Unused global definition");
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
final List<Module> modules = new ArrayList<Module>();
final Set<Assignment> unused = new HashSet<Assignment>();
for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
Module module = projectSourceParser.getModuleByName(moduleName);
modules.add(module);
final GlobalDefinitionCheck chek = new GlobalDefinitionCheck();
module.accept(chek);
unused.addAll(chek.getDefinitions());
}
for (Module module : modules) {
final GlobalUsedDefinitionCheck chekUsed = new GlobalUsedDefinitionCheck();
module.accept(chekUsed);
unused.removeAll(chekUsed.getDefinitions());
}
for (Assignment ass : unused) {
final String name = ass.getIdentifier().getDisplayName();
final String msg = MessageFormat.format("The {0} `{1}'' seems to be never used globally", ass.getAssignmentName(), name);
problems.report(ass.getIdentifier().getLocation(), msg);
}
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class UnusedImportsProject method process.
@Override
protected void process(final IProject project, final Problems problems) {
TITANDebugConsole.println("Unused import");
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
final List<Module> modules = new ArrayList<Module>();
for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
Module module = projectSourceParser.getModuleByName(moduleName);
modules.add(module);
}
final Set<Module> setOfImportedModules = new HashSet<Module>();
for (Module module : modules) {
setOfImportedModules.clear();
setOfImportedModules.addAll(module.getImportedModules());
ImportsCheck check = new ImportsCheck();
module.accept(check);
setOfImportedModules.removeAll(check.getModules());
if (module instanceof TTCN3Module) {
for (ImportModule mod : ((TTCN3Module) module).getImports()) {
for (Module m : setOfImportedModules) {
if (m.getIdentifier().equals(mod.getIdentifier())) {
problems.report(mod.getIdentifier().getLocation(), "Possibly unused importation");
}
}
}
} else {
ModuleImportsCheck importsCheck = new ModuleImportsCheck();
module.accept(importsCheck);
for (ModuleImportation im : importsCheck.getImports()) {
for (Module m : setOfImportedModules) {
if (m.getIdentifier().equals(im.getIdentifier())) {
problems.report(im.getIdentifier().getLocation(), "Possibly unused importation");
}
}
}
}
}
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class LanguageMixing method process.
@Override
protected void process(IProject project, Problems problems) {
TITANDebugConsole.println("Language mixing called");
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
final List<TTCN3Module> modules = new ArrayList<TTCN3Module>();
for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
Module module = projectSourceParser.getModuleByName(moduleName);
if (module instanceof TTCN3Module) {
modules.add((TTCN3Module) module);
}
}
Collections.sort(modules, new Comparator<TTCN3Module>() {
@Override
public int compare(final TTCN3Module o1, final TTCN3Module o2) {
return o1.getName().compareTo(o2.getName());
}
});
String lastLanguage = null;
TTCN3Module lastModule = null;
for (TTCN3Module module : modules) {
ArrayList<String> languageSpecifications = module.getLanguageSpecifictions();
if (languageSpecifications != null && languageSpecifications.size() > 0) {
String tempLanguage = languageSpecifications.get(0);
if (tempLanguage != null) {
if (lastLanguage == null) {
lastLanguage = tempLanguage;
lastModule = module;
} else if (!tempLanguage.equals(lastLanguage)) {
problems.report(module.getIdentifier().getLocation(), MessageFormat.format(ERR_MSG, project.getName(), module.getName(), tempLanguage, lastModule.getName(), lastLanguage));
}
}
}
}
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class MissingFriend method process.
@Override
public void process(final IVisitableNode node, final Problems problems) {
if (node instanceof FriendModule) {
final FriendModule s = (FriendModule) node;
final Identifier identifier = s.getIdentifier();
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(s.getProject());
if (parser != null && identifier != null) {
final Module referredModule = parser.getModuleByName(identifier.getName());
if (referredModule == null) {
final String msg = MessageFormat.format(MISSING_MODULE, identifier.getDisplayName());
problems.report(identifier.getLocation(), msg);
}
}
}
}
Aggregations