use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class ASN1ReferenceParser method findReferenceForCompletion.
@Override
public final Reference findReferenceForCompletion(final IFile file, final int offset, final IDocument document) {
Reference reference = null;
ofs = offset - 1;
if (-1 == ofs) {
return reference;
}
try {
char currentChar = document.getChar(ofs);
if (']' == currentChar || ')' == currentChar || '}' == currentChar) {
return reference;
}
GeneralPairMatcher pairMatcher = new ASN1ReferencePairMatcher();
ofs = referenceStartOffset(ofs, document, pairMatcher);
if (-1 == ofs) {
return reference;
}
// the last character where the loop stopped is not part
// of the reference
ofs++;
String toBeParsed = document.get(ofs, offset - ofs);
ASN1ReferenceParser refAnalyzer = newInstance();
reference = refAnalyzer.parseReference(file, toBeParsed, document.getLineOfOffset(ofs) + 1, ofs);
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
return reference;
}
use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class ASN1ReferenceParser method parseReference.
private Reference parseReference(final IFile file, final String input, final int line, final int offset) {
Reference reference = null;
StringReader reader = new StringReader(input);
CharStream charStream = new UnbufferedCharStream(reader);
Asn1Lexer lexer = new Asn1Lexer(charStream);
lexer.setTokenFactory(new TokenWithIndexAndSubTokensFactory(true));
ASN1Listener lexerListener = new ASN1Listener();
// remove ConsoleErrorListener
lexer.removeErrorListeners();
lexer.addErrorListener(lexerListener);
ModuleLevelTokenStreamTracker tracker = new ModuleLevelTokenStreamTracker(lexer);
tracker.discard(Asn1Lexer.WS);
tracker.discard(Asn1Lexer.MULTILINECOMMENT);
tracker.discard(Asn1Lexer.SINGLELINECOMMENT);
Asn1Parser parser = new Asn1Parser(tracker);
parser.setProject(file.getProject());
parser.setActualFile(file);
parser.setLine(line);
parser.setOffset(offset);
parser.setBuildParseTree(false);
ASN1Listener parserListener = new ASN1Listener();
// remove ConsoleErrorListener
parser.removeErrorListeners();
parser.addErrorListener(parserListener);
reference = parser.pr_parseReference().reference;
return reference;
}
use of org.eclipse.titan.designer.AST.Reference 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.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class Anytype_Type method analyzeExtensionAttributes.
/**
* Convert and check the anytype attributes applied to the module of this type.
*
* @param timestamp
* the timestamp of the actual build cycle.
*/
private void analyzeExtensionAttributes(final CompilationTimeStamp timestamp) {
clear();
final TTCN3Module myModule = (TTCN3Module) getMyScope().getModuleScope();
final WithAttributesPath moduleAttributePath = myModule.getAttributePath();
if (moduleAttributePath == null) {
return;
}
final List<SingleWithAttribute> realAttributes = moduleAttributePath.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>();
}
specifications.add(attribute.getAttributeSpecification());
}
}
}
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);
}
}
final Scope definitionsScope = myModule.getDefinitions();
ExtensionAttribute extensionAttribute;
for (int i = 0; i < attributes.size(); i++) {
extensionAttribute = attributes.get(i);
if (ExtensionAttribute_type.ANYTYPE.equals(extensionAttribute.getAttributeType())) {
final AnytypeAttribute anytypeAttribute = (AnytypeAttribute) extensionAttribute;
for (int j = 0; j < anytypeAttribute.getNofTypes(); j++) {
final Type tempType = anytypeAttribute.getType(j);
String fieldName;
Identifier identifier = null;
if (Type_type.TYPE_REFERENCED.equals(tempType.getTypetype())) {
final Reference reference = ((Referenced_Type) tempType).getReference();
identifier = reference.getId();
fieldName = identifier.getTtcnName();
} else {
fieldName = tempType.getTypename();
identifier = new Identifier(Identifier_type.ID_TTCN, fieldName);
}
tempType.setMyScope(definitionsScope);
addComp(new CompField(identifier, tempType, false, null));
}
}
}
}
use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Choice_Type method checkCodingAttributes.
@Override
public /**
* {@inheritDoc}
*/
void checkCodingAttributes(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
// TODO can unions have length restriction?
if (rawAttribute != null) {
// TODO force_raw()
if (rawAttribute.taglist != null) {
for (int c = 0; c < rawAttribute.taglist.size(); c++) {
final rawAST_single_tag singleTag = rawAttribute.taglist.get(c);
final Identifier fieldname = singleTag.fieldName;
if (!hasComponentWithName(fieldname.getName())) {
fieldname.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter TAG for type `{1}''", fieldname.getDisplayName(), getTypename()));
continue;
}
if (singleTag.keyList != null) {
for (int a = 0; a < singleTag.keyList.size(); a++) {
final Reference reference = new Reference(null);
reference.addSubReference(new FieldSubReference(fieldname));
for (int b = 0; b < singleTag.keyList.get(a).keyField.names.size(); b++) {
reference.addSubReference(new FieldSubReference(singleTag.keyList.get(a).keyField.names.get(b)));
}
final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (t != null) {
final Value v = singleTag.keyList.get(a).v_value;
if (v != null) {
v.setMyScope(getMyScope());
v.setMyGovernor(t);
final IValue tempValue = t.checkThisValueRef(timestamp, v);
t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
}
}
}
}
}
}
}
if (refChain.contains(this)) {
return;
}
refChain.add(this);
refChain.markState();
for (int i = 0; i < getNofComponents(); i++) {
final CompField cf = getComponentByIndex(i);
cf.getType().checkCodingAttributes(timestamp, refChain);
}
refChain.previousState();
}
Aggregations