use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class FindOwnedMemberBenchmarkTest method setup.
/**
*/
@Before
public void setup() {
@SuppressWarnings("hiding") TClass type = TypesFactory.eINSTANCE.createTClass();
@SuppressWarnings("hiding") List<String> names = Lists.newArrayList();
for (int i = 0; i < members; i++) {
// Member();
TMember member = TypesFactory.eINSTANCE.createTField();
member.setName("member" + i);
names.add(member.getName());
type.getOwnedMembers().add(member);
}
this.type = type;
this.names = names;
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class JSDocCompletionProposalComputer method exec.
@SuppressWarnings("unchecked")
@Override
public ICompletionProposal[] exec(XtextResource xtextResource) throws Exception {
ContentAssistContext[] contexts = processor.getContextFactory().create(viewer, offset, xtextResource);
if (contexts.length > 0) {
ArrayList<ICompletionProposal> proposals = new ArrayList<>();
ContentAssistContext contentAssistContext = contexts[contexts.length - 1];
INode currentNode = contentAssistContext.getCurrentNode();
String content = currentNode.getText();
int offsetInNode = contentAssistContext.getOffset() - currentNode.getOffset() - contentAssistContext.getPrefix().length();
// String textInFront = content.substring(0, offsetInNode);
// System.out.println(textInFront);
N4JSDocletParser docletParser = processor.getDocletParser();
Doclet doclet = docletParser.parse(content);
Optional<String> lineTagPrefix = getLineTagTitlePrefix(content, offsetInNode);
if (lineTagPrefix.isPresent()) {
createLineTagProposal(lineTagPrefix.get(), docletParser, proposals);
}
Tag tag = JSDocletUtils.getTagAtOffset(doclet, offsetInNode);
if (tag != null) {
ITagDefinition tagDef = tag.getTagDefinition();
JSDocCharScanner scanner = new JSDocCharScanner(content);
ScannerState state = scanner.saveState();
scanner.setNextOffset(offsetInNode);
JSDocCompletionHint completionHint = tagDef.completionHint(scanner);
scanner.restoreState(state);
if (completionHint.kind != NOCOMPLETION) {
int replacementOffset = offset - completionHint.prefix.length();
if (completionHint.isTypeModelRef()) {
// get reference as far as it can be parsed:
FullMemberReference ref = completionHint.nodeAsFullMemberReference();
IContentAssistScopeProvider scopeProvider = (IContentAssistScopeProvider) processor.getScopeProvider();
IScope moduleSpecScope = scopeProvider.getScopeForContentAssist(// context for finding modules
xtextResource.getContents().get(0), N4JSPackage.Literals.IMPORT_DECLARATION__MODULE);
// complete module or type
if (!completionHint.isModuleNameCompleted()) {
for (IEObjectDescription moduleDescr : moduleSpecScope.getAllElements()) {
String moduleSpec = moduleDescr.getName().toString("/");
String moduleSimpleName = moduleDescr.getName().getLastSegment();
if (!moduleSpec.startsWith("#")) {
if (moduleSpec.startsWith(completionHint.prefix) || moduleSimpleName.startsWith(completionHint.prefix)) {
if (moduleSpec.length() == completionHint.prefix.length()) {
int replacementLength = 0;
int cursorPosition = 1;
ICompletionProposal proposal = new CompletionProposal(".", replacementOffset + completionHint.prefix.length(), replacementLength, cursorPosition);
proposals.add(proposal);
} else {
int replacementLength = completionHint.prefix.length();
int cursorPosition = moduleSpec.length();
ICompletionProposal proposal = new CompletionProposal(moduleSpec, replacementOffset, replacementLength, cursorPosition);
proposals.add(proposal);
}
}
}
}
} else {
QualifiedName moduleQN = QualifiedName.create(ref.getModuleName().split("/"));
IEObjectDescription descr = moduleSpecScope.getSingleElement(moduleQN);
if (descr != null && descr.getEObjectOrProxy() instanceof TModule) {
TModule module = (TModule) descr.getEObjectOrProxy();
if (module.eIsProxy())
module = (TModule) EcoreUtil.resolve(module, xtextResource);
if (!completionHint.isTypeNameCompleted(false) && completionHint.kind != MODULESPEC) {
String typePrefix = ref.getTypeName();
for (Type t : module.getTopLevelTypes()) {
String typeName = t.getName();
if (typeName.startsWith(typePrefix)) {
String completion = module.getModuleSpecifier() + "." + typeName;
int replacementLength = completionHint.prefix.length();
int cursorPosition = completion.length();
ICompletionProposal proposal = new CompletionProposal(completion, replacementOffset, replacementLength, cursorPosition);
proposals.add(proposal);
}
}
} else {
// completionHint.kind == MEMBER
Optional<Type> optType = module.getTopLevelTypes().stream().filter(t -> t.getName().equals(ref.getTypeName())).findAny();
if (optType.isPresent()) {
Type t = optType.get();
if (t instanceof ContainerType) {
String memberPrefix = ref.getMemberName();
for (TMember m : ((ContainerType<? extends TMember>) t).getOwnedMembers()) {
String memberName = m.getName();
if (memberName.startsWith(memberPrefix)) {
String completion = LineTagWithFullElementReference.createReferenceFromType(m).toString();
int replacementLength = completionHint.prefix.length();
int cursorPosition = completion.length();
ICompletionProposal proposal = new CompletionProposal(completion, replacementOffset, replacementLength, cursorPosition);
proposals.add(proposal);
}
}
}
}
}
}
}
}
}
}
ICompletionProposal[] result = new ICompletionProposal[proposals.size()];
proposals.toArray(result);
return result;
}
return null;
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class VisibilityAwareMemberScope method isAccepted.
@Override
protected boolean isAccepted(IEObjectDescription description) {
EObject proxyOrInstance = description.getEObjectOrProxy();
if (proxyOrInstance != null && !proxyOrInstance.eIsProxy()) {
if (proxyOrInstance instanceof TMember) {
TMember member = (TMember) proxyOrInstance;
MemberVisibility result = checker.isVisible(context, receiverType, member);
if (!result.visibility)
this.accessModifierSuggestionStore.put(description.getEObjectURI().toString(), result.accessModifierSuggestion);
return result.visibility;
} else if (proxyOrInstance instanceof TEnumLiteral) {
return checker.isEnumLiteralVisible(context, receiverType);
}
}
return true;
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class N4JSScopingConsumableMethodsDiagnosis method diagnose.
@Override
DiagnosticMessage diagnose(QualifiedName name, ParameterizedPropertyAccessExpression propertyAccess) {
// determine containing member declaration and classifier definition
N4MemberDeclaration containingMemberDeclaration = EcoreUtil2.getContainerOfType(propertyAccess, N4MemberDeclaration.class);
N4ClassifierDefinition classifierDefinition = EcoreUtil2.getContainerOfType(containingMemberDeclaration, N4ClassifierDefinition.class);
// if ancestors present and non-static context (no super in static context)
if (containingMemberDeclaration != null && !containingMemberDeclaration.isStatic() && classifierDefinition != null) {
// Get candidate methods
MemberList<TMember>.MemberIterable<TMethod> methods = containerTypesHelper.fromContext(propertyAccess).membersOfImplementedInterfacesForConsumption((TClassifier) classifierDefinition.getDefinedType()).methods();
boolean hasMethod = methods.stream().filter(// Filter for non-static non-abstract methods
m -> !m.isHasNoBody() && !m.isStatic()).anyMatch(m -> m.getName().equals(name.toString()));
if (hasMethod) {
return createMessage(IssueCodes.CLF_CANNOT_REFER_TO_DEFAULT_METHOD_WITH_SUPER, IssueCodes.getMessageForCLF_CANNOT_REFER_TO_DEFAULT_METHOD_WITH_SUPER());
}
}
return null;
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class ComposedMemberInfo method handleValidationProblems.
private void handleValidationProblems() {
for (Pair<TMember, RuleEnvironment> pair : siblings) {
if (pair == null)
continue;
TMember member = pair.getKey();
if (member instanceof TMethod) {
TMethod tMethod = (TMethod) member;
for (int i = 0; i < tMethod.getFpars().size(); i++) {
TFormalParameter currFP = tMethod.getFpars().get(i);
if (currFP.isVariadic() && tMethod.getFpars().size() > i + 1) {
ComposedFParInfo currFPA = fParameters.get(i);
currFPA.hasValidationProblem = true;
return;
}
}
}
}
}
Aggregations