use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class T3Doc method getCommentStringBasedOnReference.
public static String getCommentStringBasedOnReference(final DeclarationCollector declarationCollector, final List<DeclarationCollectionHelper> collected, final IEditorPart targetEditor, final IRegion hoverRegion, final IReferenceParser referenceParser, final ITextViewer textViewer) {
if (!T3Doc.isT3DocEnable()) {
return null;
}
Reference ref = declarationCollector.getReference();
if (ref == null) {
return null;
}
if ((ref.getMyScope() instanceof NamedBridgeScope || ref.getMyScope() instanceof FormalParameterList) && !collected.isEmpty()) {
DeclarationCollectionHelper declaration = collected.get(0);
if (declaration.node instanceof TTCN3_Sequence_Type || declaration.node instanceof FormalParameter) {
final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module tempModule = projectSourceParser.containedModule(file);
Assignment ass = tempModule.getEnclosingAssignment(hoverRegion.getOffset());
if (ass != null) {
Reference reference = referenceParser.findReferenceForOpening(file, hoverRegion.getOffset(), textViewer.getDocument());
String str = reference.getDisplayName();
List<String> al = T3Doc.getCommentStrings(ass.getCommentLocation(), str);
if (!al.isEmpty()) {
final StringBuilder sb = new StringBuilder();
for (String string : al) {
sb.append(string);
}
return sb.toString();
}
}
}
}
return null;
}
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);
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);
}
ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, doc, ref, ofs);
propCollector.addProposal(CodeScanner.SECTION_TITLES, null, KEYWORD);
propCollector.addProposal(CodeScanner.KEYWORDS, null, KEYWORD);
propCollector.addProposal(CodeScanner.MASK_OPTIONS, null, KEYWORD);
propCollector.addProposal(CodeScanner.EXTERNAL_COMMAND_TYPES, null, KEYWORD);
propCollector.addProposal(CodeScanner.OPTIONS, null, KEYWORD);
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 Definition method checkErroneousAttributes.
protected void checkErroneousAttributes(final CompilationTimeStamp timestamp) {
erroneousAttributes = null;
if (withAttributesPath != null) {
final MultipleWithAttributes attribs = withAttributesPath.getAttributes();
if (attribs == null) {
return;
}
for (int i = 0; i < attribs.getNofElements(); i++) {
final SingleWithAttribute actualAttribute = attribs.getAttribute(i);
if (actualAttribute.getAttributeType() == Attribute_Type.Erroneous_Attribute) {
final int nofQualifiers = (actualAttribute.getQualifiers() == null) ? 0 : actualAttribute.getQualifiers().getNofQualifiers();
final List<IType> referencedTypeArray = new ArrayList<IType>(nofQualifiers);
final List<ArrayList<Integer>> subrefsArrayArray = new ArrayList<ArrayList<Integer>>(nofQualifiers);
final List<ArrayList<IType>> typeArrayArray = new ArrayList<ArrayList<IType>>(nofQualifiers);
if (nofQualifiers == 0) {
actualAttribute.getLocation().reportSemanticError("At least one qualifier must be specified for the `erroneous' attribute");
} else {
// existing fields
for (int qi = 0; qi < nofQualifiers; qi++) {
final Qualifier actualQualifier = actualAttribute.getQualifiers().getQualifierByIndex(qi);
final IType definitionType = getType(timestamp);
// construct a reference
final Reference reference = new Reference(null);
reference.addSubReference(new FieldSubReference(identifier));
for (int ri = 0; ri < actualQualifier.getNofSubReferences(); ri++) {
reference.addSubReference(actualQualifier.getSubReferenceByIndex(ri));
}
reference.setLocation(actualQualifier.getLocation());
reference.setMyScope(getMyScope());
IType fieldType = definitionType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
ArrayList<Integer> subrefsArray = null;
ArrayList<IType> typeArray = null;
if (fieldType != null) {
subrefsArray = new ArrayList<Integer>();
typeArray = new ArrayList<IType>();
final boolean validIndexes = definitionType.getSubrefsAsArray(timestamp, reference, 1, subrefsArray, typeArray);
if (!validIndexes) {
fieldType = null;
subrefsArray = null;
typeArray = null;
}
if (reference.refersToStringElement()) {
actualQualifier.getLocation().reportSemanticError("Reference to a string element cannot be used in this context");
fieldType = null;
subrefsArray = null;
typeArray = null;
}
}
referencedTypeArray.add(fieldType);
subrefsArrayArray.add(subrefsArray);
typeArrayArray.add(typeArray);
}
}
// parse the attr. spec.
final ErroneousAttributeSpecification errAttributeSpecification = parseErrAttrSpecString(actualAttribute.getAttributeSpecification());
if (errAttributeSpecification != null) {
if (erroneousAttributes == null) {
erroneousAttributes = new ErroneousAttributes(getType(timestamp));
}
erroneousAttributes.addSpecification(errAttributeSpecification);
errAttributeSpecification.check(timestamp, getMyScope());
// err.attr.spec. pairs
for (int qi = 0; qi < nofQualifiers; qi++) {
if (referencedTypeArray.get(qi) != null && errAttributeSpecification.getIndicator() != Indicator_Type.Invalid_Indicator) {
final Qualifier actualQualifier = actualAttribute.getQualifiers().getQualifierByIndex(qi);
erroneousAttributes.addFieldErr(actualQualifier, errAttributeSpecification, subrefsArrayArray.get(qi), typeArrayArray.get(qi));
}
}
}
}
}
if (erroneousAttributes != null) {
erroneousAttributes.check(timestamp);
}
}
}
use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class For_Loop_Definitions method checkUniqueness.
/**
* Checks the uniqueness of the definitions, and also builds a hashmap
* of them to speed up further searches.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
*/
protected void checkUniqueness(final CompilationTimeStamp timestamp) {
if (lastUniquenessCheckTimeStamp != null && !lastUniquenessCheckTimeStamp.isLess(timestamp)) {
return;
}
lastUniquenessCheckTimeStamp = timestamp;
if (definitionMap == null) {
definitionMap = new HashMap<String, Definition>(definitions.size());
}
definitionMap.clear();
String definitionName;
Definition definition;
for (int i = 0, size = definitions.size(); i < size; i++) {
definition = definitions.get(i);
final Identifier identifier = definition.getIdentifier();
definitionName = identifier.getName();
if (definitionMap.containsKey(definitionName)) {
final Location otherLocation = definitionMap.get(definitionName).getIdentifier().getLocation();
otherLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
identifier.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
} else {
definitionMap.put(definitionName, definition);
if (parentScope != null && definition.getLocation() != null) {
if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
definition.getLocation().reportSemanticError(MessageFormat.format(StatementBlock.HIDINGSCOPEELEMENT, identifier.getDisplayName()));
final List<ISubReference> subReferences = new ArrayList<ISubReference>();
subReferences.add(new FieldSubReference(identifier));
final Reference reference = new Reference(null, subReferences);
final Assignment assignment = parentScope.getAssBySRef(timestamp, reference);
if (assignment != null && assignment.getLocation() != null) {
assignment.getLocation().reportSingularSemanticError(MessageFormat.format(StatementBlock.HIDDENSCOPEELEMENT, identifier.getDisplayName()));
}
} else if (parentScope.isValidModuleId(identifier)) {
definition.getLocation().reportSemanticWarning(MessageFormat.format(StatementBlock.HIDINGMODULEIDENTIFIER, identifier.getDisplayName()));
}
}
}
}
}
use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class FormalParameter method checkActualParameterPort.
/**
* Checks if the actual parameter paired with this formal parameter is
* semantically correct as a port parameter.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param actualParameter
* the template instance assigned as actual parameter to
* this formal parameter
* @param expectedValue
* the value kind expected from the actual parameter.
*
* @return the actual parameter created from the value, or null if there
* was an error.
*/
private ActualParameter checkActualParameterPort(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter, final Expected_Value_type expectedValue) {
final Type parameterType = actualParameter.getType();
if (parameterType != null) {
parameterType.getLocation().reportSemanticWarning("Explicit type specification is useless for a port parameter");
actualParameter.checkType(timestamp, type);
}
final Reference derivedReference = actualParameter.getDerivedReference();
if (derivedReference != null) {
derivedReference.getLocation().reportSemanticError("An in-line modified temlate cannot be used as port parameter");
actualParameter.checkDerivedReference(timestamp, type);
}
final ITTCN3Template parameterTemplate = actualParameter.getTemplateBody();
if (!(parameterTemplate instanceof SpecificValue_Template) || !((SpecificValue_Template) parameterTemplate).isReference()) {
actualParameter.getLocation().reportSemanticError("Reference to a port or port parameter was expected for a port parameter");
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
final Reference reference = ((SpecificValue_Template) parameterTemplate).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
Type referredType;
switch(assignment.getAssignmentType()) {
case A_PORT:
final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
if (dimensions != null) {
dimensions.checkIndices(timestamp, reference, "port", false, expectedValue);
} else if (reference.getSubreferences().size() > 1) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR1, assignment.getDescription()));
}
referredType = ((Def_Port) assignment).getType(timestamp);
break;
case A_PAR_PORT:
if (reference.getSubreferences().size() > 1) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR3, assignment.getDescription()));
}
referredType = ((FormalParameter) assignment).getType(timestamp);
break;
default:
reference.getLocation().reportSemanticError(MessageFormat.format(PORTEXPECTED, assignment.getDescription()));
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
if (referredType != null && type != null && !type.isIdentical(timestamp, referredType)) {
reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH, type.getTypename(), referredType.getTypename()));
}
return new Referenced_ActualParameter(reference);
}
Aggregations