// there is an import statement - apply computed replacementString
if (!proposalReplacementString.equals(replacementString)) {
String shortTypeName = replacementString;
if (valueConverter != null)
shortTypeName = valueConverter.toValue(replacementString, null);
QualifiedName shortQualifiedName = qualifiedNameConverter.toQualifiedName(shortTypeName);
if (shortQualifiedName.getSegmentCount() == 1) {
proposal.setCursorPosition(replacementString.length());
document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), replacementString);
return;
}
}
// we could create an import statement if there is no conflict
Model file = (Model) context.getContents().get(0);
ComponentDefinition clazz = file.getComponentDef();
QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(typeName);
if (qualifiedName.getSegmentCount() == 1) {
// type resides in default package - no need to hassle with imports
proposal.setCursorPosition(proposalReplacementString.length());
document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), proposalReplacementString);
return;
}
IEObjectDescription description = scope.getSingleElement(qualifiedName.skipFirst(qualifiedName.getSegmentCount() - 1));
if (description != null) {
// there exists a conflict - insert fully qualified name
proposal.setCursorPosition(proposalReplacementString.length());
document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(), proposalReplacementString);
return;
}
String fqnName = importConverter.toString(typeName);
boolean found = false;
for( Import i : file.getImports() ) {
if( i.getImportedNamespace().equals(fqnName) ) {
found = true;
}
}
// Import does not introduce ambiguities - add import and insert short name
String shortName = qualifiedName.getLastSegment();
int topPixel = -1;
// store the pixel coordinates to prevent the ui from flickering
StyledText widget = viewer.getTextWidget();
if (widget != null)
topPixel = widget.getTopPixel();