use of com.intellij.lang.javascript.psi.stubs.impl.JSElementIndexingDataImpl in project intellij-plugins by JetBrains.
the class AngularJS2IndexingHandler method addImplicitElement.
private static JSElementIndexingDataImpl addImplicitElement(PsiElement element, JSElementIndexingDataImpl outData, String selector) {
if (selector == null)
return outData;
selector = selector.replace("\\n", "\n");
final MultiMap<String, String> attributesToElements = MultiMap.createSet();
PsiFile cssFile = PsiFileFactory.getInstance(element.getProject()).createFileFromText(JQueryCssLanguage.INSTANCE, selector);
CssSelectorList selectorList = PsiTreeUtil.findChildOfType(cssFile, CssSelectorList.class);
if (selectorList == null)
return outData;
for (CssSelector cssSelector : selectorList.getSelectors()) {
for (CssSimpleSelector simpleSelector : cssSelector.getSimpleSelectors()) {
String elementName = simpleSelector.getElementName();
boolean seenAttribute = false;
for (CssSelectorSuffix suffix : simpleSelector.getSelectorSuffixes()) {
if (!(suffix instanceof CssAttribute))
continue;
String name = ((CssAttribute) suffix).getAttributeName();
if (!StringUtil.isEmpty(name)) {
if (seenAttribute)
name = "[" + name + "]";
attributesToElements.putValue(name, elementName);
}
seenAttribute = true;
}
if (!seenAttribute)
attributesToElements.putValue("", elementName);
}
}
Set<String> added = new HashSet<>();
boolean template = isTemplate(element);
for (String elementName : attributesToElements.get("")) {
if (!added.add(elementName))
continue;
JSImplicitElementImpl.Builder elementBuilder = new JSImplicitElementImpl.Builder(elementName, element).setType(JSImplicitElement.Type.Class);
if (!attributesToElements.containsKey(elementName)) {
elementBuilder.setTypeString("E;;;");
} else {
Collection<String> elements = attributesToElements.get(elementName);
elementBuilder.setTypeString("AE;" + StringUtil.join(elements, ",") + ";;");
}
elementBuilder.setUserString(ANGULAR_DIRECTIVES_INDEX_USER_STRING);
if (outData == null)
outData = new JSElementIndexingDataImpl();
outData.addImplicitElement(elementBuilder.toImplicitElement());
}
for (Map.Entry<String, Collection<String>> entry : attributesToElements.entrySet()) {
JSImplicitElementImpl.Builder elementBuilder;
String attributeName = entry.getKey();
if (attributeName.isEmpty()) {
continue;
}
if (!added.add(attributeName))
continue;
if (outData == null)
outData = new JSElementIndexingDataImpl();
String elements = StringUtil.join(entry.getValue(), ",");
if (template && elements.isEmpty()) {
elementBuilder = new JSImplicitElementImpl.Builder(attributeName, element).setType(JSImplicitElement.Type.Class).setTypeString("A;template,ng-template;;");
elementBuilder.setUserString(ANGULAR_DIRECTIVES_INDEX_USER_STRING);
outData.addImplicitElement(elementBuilder.toImplicitElement());
}
final String prefix = isTemplate(element) && !attributeName.startsWith("[") ? "*" : "";
final String attr = prefix + attributeName;
elementBuilder = new JSImplicitElementImpl.Builder(attr, element).setType(JSImplicitElement.Type.Class).setTypeString("A;" + elements + ";;");
elementBuilder.setUserString(ANGULAR_DIRECTIVES_INDEX_USER_STRING);
outData.addImplicitElement(elementBuilder.toImplicitElement());
}
return outData;
}
use of com.intellij.lang.javascript.psi.stubs.impl.JSElementIndexingDataImpl in project intellij-plugins by JetBrains.
the class AngularJSIndexingHandler method processAnyProperty.
@Nullable
@Override
public JSElementIndexingData processAnyProperty(@NotNull JSProperty property, @Nullable JSElementIndexingData outData) {
final String name = property.getName();
if (name == null)
return outData;
final Pair<JSCallExpression, Integer> pair = findImmediatelyWrappingCall(property);
if (pair == null)
return outData;
final JSCallExpression callExpression = pair.getFirst();
final int level = pair.getSecond();
final JSExpression methodExpression = callExpression.getMethodExpression();
if (!(methodExpression instanceof JSReferenceExpression) || ((JSReferenceExpression) methodExpression).getQualifier() == null) {
return outData;
}
final String command = ((JSReferenceExpression) methodExpression).getReferenceName();
final PairProcessor<JSProperty, JSElementIndexingData> customProcessor = CUSTOM_PROPERTY_PROCESSORS.get(command);
JSElementIndexingData localOutData;
if (customProcessor != null && customProcessor.process(property, (localOutData = (outData == null ? new JSElementIndexingDataImpl() : outData)))) {
return localOutData;
}
// for 'standard' properties, keep indexing only for properties - immediate children of function calls parameters
if (level > 1)
return outData;
final PsiElement parent = property.getParent();
final StubIndexKey<String, JSImplicitElementProvider> index = INDEXERS.get(command);
if (index == null)
return outData;
if (callExpression.getArguments()[0] != parent)
return outData;
if (outData == null)
outData = new JSElementIndexingDataImpl();
addImplicitElements(property, command, index, name, null, outData);
return outData;
}
use of com.intellij.lang.javascript.psi.stubs.impl.JSElementIndexingDataImpl in project intellij-plugins by JetBrains.
the class AngularJSIndexingHandler method processJSDocComment.
@Override
public JSElementIndexingData processJSDocComment(@NotNull final JSDocComment comment, @Nullable JSElementIndexingData outData) {
JSDocTag ngdocTag = null;
JSDocTag nameTag = null;
for (JSDocTag tag : comment.getTags()) {
if ("ngdoc".equals(tag.getName()))
ngdocTag = tag;
else if ("name".equals(tag.getName()))
nameTag = tag;
}
if (ngdocTag != null && nameTag != null) {
final JSDocTagValue nameValue = nameTag.getValue();
String name = nameValue != null ? nameValue.getText() : null;
if (name != null)
name = name.substring(name.indexOf(':') + 1);
String ngdocValue = null;
PsiElement nextSibling = ngdocTag.getNextSibling();
if (nextSibling instanceof PsiWhiteSpace)
nextSibling = nextSibling.getNextSibling();
if (nextSibling != null && nextSibling.getNode().getElementType() == JSDocTokenTypes.DOC_COMMENT_DATA) {
ngdocValue = nextSibling.getText();
}
if (ngdocValue != null && name != null) {
final String[] commentLines = StringUtil.splitByLines(comment.getText());
final boolean directive = ngdocValue.contains(DIRECTIVE);
final boolean component = ngdocValue.contains(COMPONENT);
if (directive || component) {
final String restrictions = calculateRestrictions(commentLines, directive ? DEFAULT_RESTRICTIONS : "E");
if (outData == null)
outData = new JSElementIndexingDataImpl();
addImplicitElements(comment, directive ? DIRECTIVE : COMPONENT, AngularDirectivesDocIndex.KEY, name, restrictions, outData);
} else if (ngdocValue.contains(FILTER)) {
if (outData == null)
outData = new JSElementIndexingDataImpl();
addImplicitElements(comment, FILTER, AngularFilterIndex.KEY, name, null, outData);
}
}
}
return outData;
}
Aggregations