use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class Undefined_LowerIdentifier_Value method getAsReference.
/**
* Returns the reference form of the lower identifier value.
* <p>
* Almost the same as steel_ttcn_ref_base.
*
* @return the reference created from the identifier.
*/
public Reference getAsReference() {
if (asReference != null) {
return asReference;
}
asReference = new Reference(null);
asReference.addSubReference(new FieldSubReference(identifier));
asReference.setLocation(getLocation());
asReference.setFullNameParent(this);
asReference.setMyScope(myScope);
return asReference;
}
use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class ContentAssistProcessor method computeCompletionProposals.
// FIXME add semantic check guard on project level.
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
if (editor == null) {
return new ICompletionProposal[] {};
}
IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
return new ICompletionProposal[] {};
}
IDocument doc = viewer.getDocument();
TTCN3ReferenceParser refParser = new TTCN3ReferenceParser(true);
Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
if (ref == null || ref.getSubreferences().isEmpty()) {
return new ICompletionProposal[] {};
}
Scope scope = null;
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
Module tempModule = projectSourceParser.containedModule(file);
String moduleName = null;
if (tempModule != null) {
moduleName = tempModule.getName();
scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
ref.setMyScope(scope);
ref.detectModid();
}
IPreferencesService prefs = Platform.getPreferencesService();
if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
TITANDebugConsole.println("parsed the reference: " + ref);
}
TemplateContextType contextType = new TemplateContextType(TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, TTCN3CodeSkeletons.CONTEXT_NAME);
ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
propCollector.setProjectParser(projectSourceParser);
if (moduleName == null) {
// rootless behavior
if (ref.getModuleIdentifier() == null) {
Set<String> moduleNames = projectSourceParser.getKnownModuleNames();
Module module;
for (String name : moduleNames) {
module = projectSourceParser.getModuleByName(name);
if (module != null) {
propCollector.addProposal(name, name, ImageCache.getImage("ttcn.gif"), TTCN3Module.MODULE);
module.getAssignments().addProposal(propCollector);
}
}
} else {
Module module = projectSourceParser.getModuleByName(ref.getModuleIdentifier().getName());
if (module != null) {
module.getAssignments().addProposal(propCollector);
}
}
} else {
/*
* search for the best scope in the module's scope
* hierarchy and call proposal adding function on the
* found scope instead of what can be found here
*/
if (scope != null) {
scope.addProposal(propCollector);
}
}
propCollector.sortTillMarked();
propCollector.markPosition();
if (ref.getSubreferences().size() != 1) {
if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
propCollector.sortAll();
}
return propCollector.getCompletitions();
}
Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
for (String knownModuleName : knownModuleNames) {
Identifier tempIdentifier = new Identifier(Identifier_type.ID_NAME, knownModuleName);
Module tempModule2 = projectSourceParser.getModuleByName(knownModuleName);
propCollector.addProposal(tempIdentifier, ImageCache.getImage(tempModule2.getOutlineIcon()), "module");
}
propCollector.sortTillMarked();
propCollector.markPosition();
if (ref.getModuleIdentifier() == null) {
if (scope == null) {
TTCN3CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
} else {
scope.addSkeletonProposal(propCollector);
}
propCollector.addTemplateProposal("refers", new Template("refers( function/altstep/testcase name )", "", propCollector.getContextIdentifier(), "refers( ${fatName} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("derefers", new Template("derefers( function/altstep/testcase name )(parameters)", "", propCollector.getContextIdentifier(), "derefers( ${fatName} ) ( ${parameters} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.sortTillMarked();
propCollector.markPosition();
TTCN3CodeSkeletons.addPredefinedSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
if (scope == null) {
TTCN3Keywords.addKeywordProposals(propCollector);
} else {
scope.addKeywordProposal(propCollector);
}
propCollector.sortTillMarked();
propCollector.markPosition();
} else {
if (scope == null || !(scope instanceof StatementBlock)) {
if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
propCollector.sortAll();
}
return propCollector.getCompletitions();
}
String fakeModule = ref.getModuleIdentifier().getName();
if ("any component".equals(fakeModule) || "all component".equals(fakeModule)) {
Component_Type.addAnyorAllProposal(propCollector, 0);
} else if ("any port".equals(fakeModule) || "all port".equals(fakeModule)) {
PortTypeBody.addAnyorAllProposal(propCollector, 0);
} else if ("any timer".equals(fakeModule) || "all timer".equals(fakeModule)) {
Timer.addAnyorAllProposal(propCollector, 0);
}
}
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 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.Reference in project titan.EclipsePlug-ins by eclipse.
the class TTCN3ReferenceParser method findReferenceForCompletion.
@Override
public 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) {
return reference;
}
GeneralPairMatcher pairMatcher = new TTCN3ReferencePairMatcher();
int tempOfs = referenceStartOffset(ofs, document, pairMatcher);
if (-1 == tempOfs) {
return reference;
}
if (tempOfs > 3) {
if ("any ".equals(document.get(tempOfs - 2, 4)) || "all ".equals(document.get(tempOfs - 2, 4))) {
tempOfs -= 3;
}
}
ofs = tempOfs;
// the last character where the loop stopped is not part
// of the reference
ofs++;
String toBeParsed = document.get(ofs, offset - ofs);
TTCN3ReferenceAnalyzer refAnalyzer = new TTCN3ReferenceAnalyzer();
reference = refAnalyzer.parseForCompletion(file, toBeParsed);
} 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 TTCN3ReferenceParser method findReferenceForOpening.
@Override
public Reference findReferenceForOpening(final IFile file, final int offset, final IDocument document) {
Reference reference = null;
ofs = offset - 1;
int endoffset = offset;
if (-1 == ofs) {
return reference;
}
try {
GeneralPairMatcher pairMatcher = new TTCN3ReferencePairMatcher();
ofs = referenceStartOffset(ofs, document, pairMatcher);
if (-1 == ofs) {
return reference;
}
// the last character where the loop stopped is not part
// of the reference
ofs++;
if (endoffset >= document.getLength()) {
return reference;
}
char currentChar = document.getChar(endoffset);
while (endoffset < document.getLength() && (Character.isLetterOrDigit(currentChar) || currentChar == '(' || currentChar == '_')) {
if (currentChar == '(') {
break;
}
endoffset++;
if (endoffset >= document.getLength()) {
return reference;
}
currentChar = document.getChar(endoffset);
}
String toBeParsed = document.get(ofs, endoffset - ofs);
if (toBeParsed.trim().length() == 0) {
return reference;
}
TTCN3ReferenceAnalyzer refAnalyzer = new TTCN3ReferenceAnalyzer();
reference = refAnalyzer.parse(file, toBeParsed, reportErrors, document.getLineOfOffset(ofs) + 1, ofs);
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
return reference;
}
Aggregations