use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class ProjectSourceSyntacticAnalyzer method removeTTCNPPFilesIndirectlyModifiedByTTCNINFiles.
void removeTTCNPPFilesIndirectlyModifiedByTTCNINFiles() {
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
Set<String> moduleNames = projectSourceParser.getKnownModuleNames();
for (String moduleName : moduleNames) {
Module module = projectSourceParser.getModuleByName(moduleName);
if (module == null || !(module instanceof TTCN3Module)) {
continue;
}
TTCN3Module ttcnppModule = (TTCN3Module) module;
Set<IFile> includedFiles = ttcnppModule.getIncludedFiles();
if (includedFiles == null || includedFiles.isEmpty()) {
continue;
}
boolean isTTCNPPupToDate = true;
for (IFile f : includedFiles) {
if (!uptodateFiles.containsKey(f)) {
isTTCNPPupToDate = false;
break;
}
}
if (!isTTCNPPupToDate) {
uptodateFiles.remove(ttcnppModule.getLocation().getFile());
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class PortTypeBody method checkAttributes.
/**
* Does the semantic checking of the attributes assigned to the port type having this body.
*
* @param timestamp the time stamp of the actual semantic check cycle.
* @param withAttributesPath the withAttributesPath assigned to the port type.
*/
public void checkAttributes(final CompilationTimeStamp timestamp, final WithAttributesPath withAttributesPath) {
if (lastTimeAttributesChecked != null && !lastTimeAttributesChecked.isLess(timestamp)) {
return;
}
lastTimeAttributesChecked = lastTimeChecked;
final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
SingleWithAttribute attribute;
List<AttributeSpecification> specifications = null;
for (int i = 0; i < realAttributes.size(); i++) {
attribute = realAttributes.get(i);
if (Attribute_Type.Extension_Attribute.equals(attribute.getAttributeType())) {
final Qualifiers qualifiers = attribute.getQualifiers();
if (qualifiers == null || qualifiers.getNofQualifiers() == 0) {
if (specifications == null) {
specifications = new ArrayList<AttributeSpecification>();
}
final AttributeSpecification specification = attribute.getAttributeSpecification();
if (specification.getSpecification() != null) {
// there is nothing to parse if specification string is null,
// anyway it would cause NPE in ExtensionAttributeAnalyzer.parse()
specifications.add(specification);
}
}
}
}
if (specifications == null) {
return;
}
final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
AttributeSpecification specification;
for (int i = 0; i < specifications.size(); i++) {
specification = specifications.get(i);
final ExtensionAttributeAnalyzer analyzer = new ExtensionAttributeAnalyzer();
analyzer.parse(specification);
final List<ExtensionAttribute> temp = analyzer.getAttributes();
if (temp != null) {
attributes.addAll(temp);
}
}
if (attributes.isEmpty()) {
return;
}
// clear the old attributes
testportType = TestPortAPI_type.TP_REGULAR;
portType = PortType_type.PT_REGULAR;
// check the new attributes
for (int i = 0; i < attributes.size(); i++) {
final ExtensionAttribute extensionAttribute = attributes.get(i);
if (ExtensionAttribute_type.PORTTYPE.equals(extensionAttribute.getAttributeType())) {
final PortTypeAttribute portAttribute = (PortTypeAttribute) extensionAttribute;
switch(portAttribute.getPortTypeType()) {
case INTERNAL:
switch(testportType) {
case TP_REGULAR:
break;
case TP_INTERNAL:
extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `internal'");
break;
case TP_ADDRESS:
extensionAttribute.getLocation().reportSemanticError("Attributes `address' and `internal' cannot be used at the same time");
break;
default:
break;
}
testportType = TestPortAPI_type.TP_INTERNAL;
break;
case ADDRESS:
switch(testportType) {
case TP_REGULAR:
break;
case TP_INTERNAL:
extensionAttribute.getLocation().reportSemanticError("Attributes `address' and `internal' cannot be used at the same time");
break;
case TP_ADDRESS:
extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `address'");
break;
default:
break;
}
testportType = TestPortAPI_type.TP_ADDRESS;
break;
case PROVIDER:
switch(portType) {
case PT_REGULAR:
break;
case PT_PROVIDER:
extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `provider'");
break;
case PT_USER:
extensionAttribute.getLocation().reportSemanticError("Attributes `user' and `provider' cannot be used at the same time");
break;
default:
break;
}
addProviderAttribute();
break;
case USER:
switch(portType) {
case PT_REGULAR:
break;
case PT_PROVIDER:
extensionAttribute.getLocation().reportSemanticError("Attributes `provider' and `user' cannot be used at the same time");
break;
case PT_USER:
extensionAttribute.getLocation().reportSemanticError("Duplicate attribute `user'");
break;
default:
break;
}
final UserPortTypeAttribute user = (UserPortTypeAttribute) portAttribute;
addUserAttribute(user.getReference(), user.getInMappings(), user.getOutMappings());
break;
default:
break;
}
}
}
if (PortType_type.PT_USER.equals(portType)) {
checkUserAttribute(timestamp);
} else if (TestPortAPI_type.TP_ADDRESS.equals(testportType)) {
final TTCN3Module module = (TTCN3Module) myType.getMyScope().getModuleScope();
if (module.getAddressType(timestamp) == null) {
location.reportSemanticError(MessageFormat.format("Type `address'' is not defined in module `{0}''", module.getIdentifier().getDisplayName()));
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class ImportSelectionDialog method organizeImportsEdit.
/**
* Organize the imports according to the global preferences. If set,
* <ul>
* <li>Add imports necessary for missing references,</li>
* <li>Remove unused imports,</li>
* <li>Sort the import statements.</li>
* </ul>
* <p>
* These changes are not applied in the function, just collected in a
* <link>MultiTextEdit</link>, which is then returned.
* </p>
* TODO: notice and handle ambiguous references
*
* @param module
* The module which import statements are to organize.
* @param document
* The document that contains the module.
*
* @return The edit, which contains the proper changes.
*/
private static MultiTextEdit organizeImportsEdit(final TTCN3Module module, final IDocument document) throws BadLocationException {
final IProject prj = module.getProject();
final String doc = document.get();
final MultiTextEdit insertEdit = new MultiTextEdit();
final MultiTextEdit removeEdit = new MultiTextEdit();
final List<ImportText> newImports = new ArrayList<ImportText>();
final List<ImportText> importsKept = new ArrayList<ImportText>();
boolean needSorting = false;
if (addImports) {
// register the new needed imports
final Set<String> importNamesAdded = new HashSet<String>();
for (final Reference ref : module.getMissingReferences()) {
final Location missLoc = findReferenceInProject(ref, prj);
if (missLoc != null) {
final IFile file = (IFile) missLoc.getFile();
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
final Module addMod = parser.containedModule(file);
final String importName = addMod.getIdentifier().getTtcnName();
if (!importNamesAdded.contains(importName)) {
final StringBuilder impText = new StringBuilder("import from ").append(importName).append(" all;");
if (importChangeMethod.equals(OrganizeImportPreferencePage.COMMENT_THEM)) {
impText.append(" // Added automatically to resolve ").append(ref.getDisplayName());
}
newImports.add(new ImportText(importName, impText.toString() + NEWLINE));
importNamesAdded.add(importName);
if (reportDebug) {
final StringBuilder sb = new StringBuilder("For ").append(ref.getDisplayName()).append(": ");
sb.append(impText.toString());
TITANDebugConsole.println(sb.toString());
}
}
}
}
if (sortImports && !newImports.isEmpty()) {
needSorting = true;
}
}
if (!needSorting && sortImports) {
// are the imports already sorted ?
final List<ImportModule> oldImports = module.getImports();
for (int size = oldImports.size(), i = 0; i < size - 1 && !needSorting; i++) {
if (oldImports.get(i).getName().compareTo(oldImports.get(i + 1).getName()) > 0) {
needSorting = true;
}
if (oldImports.get(i).getLocation().getOffset() > oldImports.get(i + 1).getLocation().getOffset()) {
needSorting = true;
}
}
if (!needSorting && oldImports.size() > 1) {
// are the import strictly before the definitions ?
final int lastImportOffset = oldImports.get(oldImports.size() - 1).getLocation().getOffset();
final Definitions defs = module.getAssignmentsScope();
if (defs.getNofAssignments() > 0 && !oldImports.isEmpty()) {
for (int i = 0, size = defs.getNofAssignments(); i < size; ++i) {
final int temp = defs.getAssignmentByIndex(i).getLocation().getOffset();
if (temp < lastImportOffset) {
needSorting = true;
}
}
}
}
}
if (needSorting || removeImports) {
// remove the imports not needed, or every if sorting is required
for (final ImportModule m : module.getImports()) {
final Location delImp = m.getLocation();
final IRegion startLineRegion = document.getLineInformationOfOffset(delImp.getOffset());
final IRegion endLineRegion = document.getLineInformationOfOffset(delImp.getEndOffset());
final String delimeter = document.getLineDelimiter(document.getLineOfOffset(delImp.getEndOffset()));
final int delLength = delimeter == null ? 0 : delimeter.length();
if (needSorting || (removeImports && !m.getUsedForImportation())) {
if (reportDebug) {
final MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
TITANDebugConsole.println("Removing " + "'" + doc.substring(startLineRegion.getOffset(), endLineRegion.getOffset() + endLineRegion.getLength() + delLength) + "'", stream);
TITANDebugConsole.println("From " + startLineRegion.getOffset() + " till " + ((endLineRegion.getOffset() - startLineRegion.getOffset()) + endLineRegion.getLength() + delLength), stream);
}
if (importChangeMethod.equals(OrganizeImportPreferencePage.COMMENT_THEM)) {
removeEdit.addChild(new InsertEdit(m.getLocation().getOffset(), "/*"));
// hack to handle the semicolon
removeEdit.addChild(new InsertEdit(m.getLocation().getEndOffset() + 1, "*/"));
} else {
removeEdit.addChild(new DeleteEdit(startLineRegion.getOffset(), (endLineRegion.getOffset() - startLineRegion.getOffset()) + endLineRegion.getLength() + delLength));
}
}
if (needSorting && (!removeImports || m.getUsedForImportation())) {
importsKept.add(new ImportText(m.getName(), doc.substring(startLineRegion.getOffset(), endLineRegion.getOffset() + endLineRegion.getLength() + delLength)));
}
}
}
if (!newImports.isEmpty() || (sortImports && needSorting)) {
// always insert at the beginning of the file
final int line = document.getLineOfOffset(module.getAssignmentsScope().getLocation().getOffset());
final IRegion lineRegion = document.getLineInformation(line);
final String delimeter = document.getLineDelimiter(line);
final int delimeterLength = delimeter == null ? 0 : delimeter.length();
final int startPos = lineRegion.getOffset() + lineRegion.getLength() + delimeterLength;
if (sortImports) {
if (needSorting || !newImports.isEmpty()) {
final List<ImportText> results = new ArrayList<ImportText>();
results.addAll(importsKept);
results.addAll(newImports);
Collections.sort(results);
for (final ImportText i : results) {
insertEdit.addChild(new InsertEdit(startPos, i.getText()));
}
}
} else {
Collections.sort(newImports);
for (final ImportText i : newImports) {
insertEdit.addChild(new InsertEdit(startPos, i.getText()));
}
}
}
final MultiTextEdit resultEdit = new MultiTextEdit();
resultEdit.addChild(insertEdit);
resultEdit.addChild(removeEdit);
return resultEdit;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class ImportSelectionDialog method organizeImportsChange.
/**
* Organize the import statements of a file. The necessary changes are
* collected and returned in a <code>TextFileChange</code> object.
*
* @param file
* The file to organize.
* @return The change to perform.
* @throws CoreException
* when document associated with the file can't be acquired.
*/
public static TextFileChange organizeImportsChange(final IFile file) throws CoreException {
sortImports = Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, PreferenceConstants.ORG_IMPORT_SORT, true, null);
addImports = Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, PreferenceConstants.ORG_IMPORT_ADD, true, null);
removeImports = Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, PreferenceConstants.ORG_IMPORT_REMOVE, true, null);
importChangeMethod = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PreferenceConstants.ORG_IMPORT_METHOD, OrganizeImportPreferencePage.JUST_CHANGE, null);
final String designerId = ProductConstants.PRODUCT_ID_DESIGNER;
final String displayDebugInfo = org.eclipse.titan.designer.preferences.PreferenceConstants.DISPLAYDEBUGINFORMATION;
reportDebug = Platform.getPreferencesService().getBoolean(designerId, displayDebugInfo, false, null);
final TextFileChange change = new TextFileChange(file.getName(), file);
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module actualModule = projectSourceParser.containedModule(file);
if (!(actualModule instanceof TTCN3Module)) {
ErrorReporter.logError("The module is not a TTCN-3 module");
return change;
}
final TTCN3Module module = (TTCN3Module) actualModule;
final IDocument doc = change.getCurrentDocument(null);
try {
change.setEdit(organizeImportsEdit(module, doc));
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace("Error while organizing imports", e);
}
return change;
}
Aggregations