use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Integer_Type method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (null != myScope) {
final Module module = myScope.getModuleScope();
if (null != module) {
if (module.getSkippedFromSemanticChecking()) {
return;
}
}
}
isErroneous = false;
if (null == namedNumbers) {
parseBlockInt();
}
if (isErroneous || null == namedNumbers) {
return;
}
/* check named numbers */
final Map<String, Identifier> nameMap = new HashMap<String, Identifier>();
for (int i = 0, size = namedNumbers.getSize(); i < size; i++) {
final NamedValue namedValue = namedNumbers.getNamedValueByIndex(i);
final Identifier identifier = namedValue.getName();
if (nameMap.containsKey(identifier.getName())) {
final Location tempLocation = nameMap.get(identifier.getName()).getLocation();
tempLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
identifier.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
} else {
nameMap.put(identifier.getName(), identifier);
}
}
final Map<Integer, NamedValue> valueMap = new HashMap<Integer, NamedValue>();
for (int i = 0, size = namedNumbers.getSize(); i < size; i++) {
final NamedValue namedValue = namedNumbers.getNamedValueByIndex(i);
final IValue value = namedValue.getValue();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (last.getIsErroneous(timestamp)) {
continue;
}
switch(last.getValuetype()) {
case INTEGER_VALUE:
{
final Integer_Value integerValue = (Integer_Value) last;
if (integerValue.isNative()) {
final Integer intValue = Integer.valueOf(integerValue.intValue());
if (valueMap.containsKey(intValue)) {
value.getLocation().reportSemanticError(MessageFormat.format("Duplicate number {0} for name `{1}''", intValue, namedValue.getName().getDisplayName()));
final NamedValue temp = valueMap.get(intValue);
temp.getLocation().reportSemanticError(MessageFormat.format("Number {0} is already assigned to name `{1}''", intValue, temp.getName().getDisplayName()));
} else {
valueMap.put(intValue, namedValue);
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("Integer value `{0}'' is too big to be used as a named number", integerValue.getValueValue()));
value.setIsErroneous(true);
}
break;
}
default:
namedValue.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for named number `{0}''", namedValue.getName().getDisplayName()));
value.setIsErroneous(true);
break;
}
}
nameMap.clear();
if (null != constraints) {
constraints.check(timestamp);
}
if (myScope != null) {
checkEncode(timestamp);
checkVariants(timestamp);
}
}
use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class SubType method getParsedLocation.
/**
* get the location of the subtype constraints parsed for this type, or
* return the owner type location if none were parsed
*/
public Location getParsedLocation() {
if ((parsedRestrictions == null) || parsedRestrictions.isEmpty()) {
return myOwner.getLocation();
}
if (parsedRestrictions.size() == 1) {
final Location loc = parsedRestrictions.get(0).getLocation();
return (loc == null) ? myOwner.getLocation() : loc;
}
final Location startLoc = parsedRestrictions.get(0).getLocation();
final Location endLoc = parsedRestrictions.get(parsedRestrictions.size() - 1).getLocation();
if ((startLoc == null) || (endLoc == null)) {
return myOwner.getLocation();
}
return Location.interval(startLoc, endLoc);
}
use of org.eclipse.titan.designer.AST.Location 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);
int ofs = findWordStart(offset, doc);
String incompleteString = "";
try {
if (doc != null && offset >= ofs) {
incompleteString = doc.get(ofs, offset - ofs);
}
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
String[] reference = incompleteString.trim().split(REFERENCE_SPLITTER, -1);
Reference ref = new Reference(null);
ref.setLocation(new Location(file, 0, 0, offset - ofs));
FieldSubReference subref = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, reference[0]));
subref.setLocation(new Location(file, 0, 0, reference[0].length()));
ref.addSubReference(subref);
if (reference.length > 1) {
subref = new FieldSubReference(new Identifier(Identifier_type.ID_TTCN, reference[1]));
subref.setLocation(new Location(file, 0, reference[0].length() + 1, offset - ofs));
ref.addSubReference(subref);
}
TemplateContextType contextType = new TemplateContextType(TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, TTCN3CodeSkeletons.CONTEXT_NAME);
ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, ofs);
TTCN3CodeSkeletons.addSkeletonProposals(doc, offset, propCollector);
TTCN3Keywords.addKeywordProposals(propCollector);
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.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class Symbols method checkUniqueness.
/**
* Checks the uniqueness of the symbols, and also builds a hashmap of
* them to speed up further searches.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
*/
public void checkUniqueness(final CompilationTimeStamp timestamp) {
if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
return;
}
symbols_map.clear();
symbols_v.trimToSize();
for (Identifier id : symbols_v) {
final String name = id.getName();
if (symbols_map.containsKey(name)) {
final Location location = symbols_map.get(name).getLocation();
location.reportSingularSemanticError(MessageFormat.format(DUPLICATESYMBOLFIRST, id.getDisplayName()));
id.getLocation().reportSemanticError(MessageFormat.format(DUPLICATESYMBOLREPEATED, id.getDisplayName()));
} else {
symbols_map.put(name, id);
}
}
lastTimeChecked = timestamp;
}
use of org.eclipse.titan.designer.AST.Location in project titan.EclipsePlug-ins by eclipse.
the class ASN1_BitString_Type method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (null != myScope) {
final Module module = myScope.getModuleScope();
if (null != module) {
if (module.getSkippedFromSemanticChecking()) {
return;
}
}
}
isErroneous = false;
if (null == namedValues) {
parseBlockBitstring();
}
if (isErroneous || null == namedValues) {
return;
}
/* check named bits */
final Map<String, Identifier> nameMap = new HashMap<String, Identifier>();
for (int i = 0, size = namedValues.getSize(); i < size; i++) {
final NamedValue namedValue = namedValues.getNamedValueByIndex(i);
final Identifier identifier = namedValue.getName();
if (nameMap.containsKey(identifier.getName())) {
final Location tempLocation = nameMap.get(identifier.getName()).getLocation();
tempLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
identifier.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
} else {
nameMap.put(identifier.getName(), identifier);
}
}
final Map<Integer, NamedValue> valueMap = new HashMap<Integer, NamedValue>();
for (int i = 0, size = namedValues.getSize(); i < size; i++) {
final NamedValue namedValue = namedValues.getNamedValueByIndex(i);
final IValue value = namedValue.getValue();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (last.getIsErroneous(timestamp)) {
continue;
}
switch(last.getValuetype()) {
case INTEGER_VALUE:
{
final Integer_Value integerValue = (Integer_Value) last;
if (integerValue.isNative()) {
final int intValue = integerValue.intValue();
final Integer intValueObject = Integer.valueOf(intValue);
if (intValue < 0) {
value.getLocation().reportSemanticError(MessageFormat.format("A non-negative INTEGER value was expected for named bit `{0}'' instead of {1}", namedValue.getName().getDisplayName(), intValueObject));
value.setIsErroneous(true);
continue;
}
if (valueMap.containsKey(intValueObject)) {
value.getLocation().reportSemanticError(MessageFormat.format("Duplicate value {0} for named bit `{1}''", intValueObject, namedValue.getName().getDisplayName()));
value.setIsErroneous(true);
final NamedValue temp = valueMap.get(intValueObject);
temp.getLocation().reportSemanticError(MessageFormat.format("Bit {0} is already assigned to name `{1}''", intValueObject, temp.getName().getDisplayName()));
} else {
valueMap.put(intValueObject, namedValue);
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value `{0}'' is too big to be used as a named bit", integerValue.getValueValue()));
value.setIsErroneous(true);
}
break;
}
default:
namedValue.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for named bit `{0}''", namedValue.getName().getDisplayName()));
break;
}
}
nameMap.clear();
if (null != constraints) {
constraints.check(timestamp);
}
if (myScope != null) {
checkEncode(timestamp);
checkVariants(timestamp);
}
}
Aggregations