use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexRenameTest method testRenameFlexClassReferencedInCss.
public void testRenameFlexClassReferencedInCss() throws Exception {
final String name = getTestName(false);
doTest(name + "Renamed", name + "_after.css", name + ".css", name + ".as");
final PsiReference newReference = myFile.findReferenceAt(myEditor.getCaretModel().getOffset());
final PsiElement newResolve = newReference == null ? null : newReference.resolve();
assertTrue(newResolve instanceof JSClass && "bar.RenameFlexClassReferencedInCssRenamed".equals(((JSClass) newResolve).getQualifiedName()));
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexValue method computeChildren.
@Override
public void computeChildren(@NotNull final XCompositeNode node) {
final int i = myResult.indexOf(OBJECT_MARKER);
if (i == -1)
super.computeChildren(node);
final String typeFromFlexValueResult = getTypeAndAdditionalInfo(myResult).first;
final String expression;
try {
expression = referenceObjectBase(i, OBJECT_MARKER);
} catch (StringIndexOutOfBoundsException e) {
FlexDebugProcess.log(new Exception(myResult, e));
node.addChildren(XValueChildrenList.EMPTY, true);
return;
}
final FlexStackFrame.EvaluateCommand command = myFlexStackFrame.new EvaluateCommand(expression, null) {
@Override
CommandOutputProcessingMode doOnTextAvailable(@NonNls final String resultS) {
StringTokenizer tokenizer = new StringTokenizer(resultS, "\r\n");
// skip first token; it contains $-prefix followed by myResult: $6 = [Object 30860193, class='__AS3__.vec::Vector.<String>']
tokenizer.nextToken();
final LinkedHashMap<String, FlexValue> fieldNameToFlexValueMap = new LinkedHashMap<>(tokenizer.countTokens());
final NodeClassInfo nodeClassInfo = DumbService.getInstance(myDebugProcess.getSession().getProject()).runReadActionInSmartMode(() -> {
final Project project = myDebugProcess.getSession().getProject();
final JSClass jsClass = mySourcePosition == null ? null : findJSClass(project, ModuleUtilCore.findModuleForFile(mySourcePosition.getFile(), project), typeFromFlexValueResult);
return jsClass == null ? null : NodeClassInfo.getNodeClassInfo(jsClass);
});
while (tokenizer.hasMoreElements()) {
final String s = tokenizer.nextToken().trim();
if (s.length() == 0)
continue;
final int delimIndex = s.indexOf(FlexStackFrame.DELIM);
if (delimIndex == -1) {
FlexDebugProcess.log("Unrecognized string:" + s);
continue;
}
final String fieldName = s.substring(0, delimIndex);
final String result = s.substring(delimIndex + FlexStackFrame.DELIM.length());
if (result.startsWith("[Setter ")) {
// [Setter 78]
continue;
}
String evaluatedPath = myExpression;
if (fieldName.length() > 0 && Character.isDigit(fieldName.charAt(0))) {
evaluatedPath += "[\"" + fieldName + "\"]";
} else {
evaluatedPath += "." + fieldName;
}
// either parameter of static function from scopechain or a field. Static functions from scopechain look like following:
// // [Object 52571545, class='Main$/staticFunction']
final ValueType valueType = typeFromFlexValueResult != null && typeFromFlexValueResult.indexOf('/') > -1 ? ValueType.Parameter : ValueType.Field;
final FlexValue flexValue = new FlexValue(myFlexStackFrame, myDebugProcess, mySourcePosition, fieldName, evaluatedPath, result, FlexValue.this.myResult, valueType);
addValueCheckingDuplicates(flexValue, fieldNameToFlexValueMap);
}
addChildren(node, fieldNameToFlexValueMap, nodeClassInfo);
return CommandOutputProcessingMode.DONE;
}
};
myDebugProcess.sendCommand(command);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexValue method computeTypeSourcePosition.
public void computeTypeSourcePosition(@NotNull final XNavigatable navigatable) {
if (mySourcePosition == null) {
navigatable.setSourcePosition(null);
return;
}
final boolean isObject = myResult.contains(OBJECT_MARKER);
if (isObject) {
final Pair<String, String> typeAndAdditionalInfo = getTypeAndAdditionalInfo(myResult);
final String typeFromFlexValueResult = typeAndAdditionalInfo.first;
if (typeFromFlexValueResult != null) {
final Project project = myDebugProcess.getSession().getProject();
final JSClass jsClass = findJSClass(project, ModuleUtilCore.findModuleForFile(mySourcePosition.getFile(), project), typeFromFlexValueResult);
navigatable.setSourcePosition(DebuggerSupportUtils.calcSourcePosition(jsClass));
return;
}
}
navigatable.setSourcePosition(null);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexQualifiedNameLocationProvider method findElement.
@Nullable
private static JSElement findElement(String link, Project project) {
String moduleName = link.substring(0, link.indexOf(":"));
Module module = ModuleManager.getInstance(project).findModuleByName(moduleName);
link = link.substring(link.indexOf(":") + 1);
final JavaScriptIndex index = JavaScriptIndex.getInstance(project);
PsiElement element = ActionScriptClassResolver.findClassByQName(link, index, module);
if (element instanceof JSClass) {
return (JSElement) element;
}
if (element == null && link.contains(".") && link.endsWith("()")) {
String qname = link.substring(0, link.lastIndexOf('.'));
element = ActionScriptClassResolver.findClassByQName(qname, index, module);
if (element instanceof JSClass) {
String methodName = link.substring(link.lastIndexOf('.') + 1, link.length() - 2);
return ((JSClass) element).findFunctionByNameAndKind(methodName, JSFunction.FunctionKind.SIMPLE);
}
}
return null;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlexValue method computeSourcePosition.
@Override
public void computeSourcePosition(@NotNull final XNavigatable navigatable) {
if (mySourcePosition == null) {
navigatable.setSourcePosition(null);
return;
}
XSourcePosition result = null;
final Project project = myDebugProcess.getSession().getProject();
if (myValueType == ValueType.Variable) {
final PsiElement contextElement = XDebuggerUtil.getInstance().findContextElement(mySourcePosition.getFile(), mySourcePosition.getOffset(), project, true);
final JSFunction jsFunction = PsiTreeUtil.getParentOfType(contextElement, JSFunction.class);
if (jsFunction != null) {
final Ref<JSVariable> varRef = new Ref<>();
jsFunction.accept(new JSElementVisitor() {
@Override
public void visitJSElement(final JSElement node) {
if (varRef.isNull()) {
node.acceptChildren(this);
}
}
@Override
public void visitJSVariable(final JSVariable node) {
if (myName.equals(node.getName())) {
varRef.set(node);
}
super.visitJSVariable(node);
}
});
if (!varRef.isNull()) {
result = DebuggerSupportUtils.calcSourcePosition(varRef.get());
}
}
} else if (myValueType == ValueType.Parameter) {
final PsiElement contextElement = XDebuggerUtil.getInstance().findContextElement(mySourcePosition.getFile(), mySourcePosition.getOffset(), project, true);
final JSFunction jsFunction = PsiTreeUtil.getParentOfType(contextElement, JSFunction.class);
final JSParameter[] parameters = jsFunction == null ? JSParameter.EMPTY_ARRAY : jsFunction.getParameterVariables();
for (final JSParameter parameter : parameters) {
if (myName.equals(parameter.getName())) {
result = DebuggerSupportUtils.calcSourcePosition(parameter);
break;
}
}
} else if (myValueType == ValueType.Field && myParentResult != null) {
final String typeFromFlexValueResult = getTypeAndAdditionalInfo(myParentResult).first;
final JSClass jsClass = findJSClass(project, ModuleUtilCore.findModuleForFile(mySourcePosition.getFile(), project), typeFromFlexValueResult);
if (jsClass != null) {
final Ref<PsiElement> fieldRef = new Ref<>();
fieldRef.set(JSInheritanceUtil.findMember(myName, jsClass, JSInheritanceUtil.SearchedMemberType.FieldsAndMethods, JSFunction.FunctionKind.GETTER, true));
if (fieldRef.isNull() && jsClass instanceof MxmlJSClass) {
final PsiFile file = jsClass.getContainingFile();
final XmlFile xmlFile = file instanceof XmlFile ? (XmlFile) file : null;
final XmlTag rootTag = xmlFile == null ? null : xmlFile.getRootTag();
if (rootTag != null) {
NodeClassInfo.processSubtagsRecursively(rootTag, tag -> {
final XmlAttribute idAttr = tag.getAttribute("id");
final String id = idAttr == null ? null : idAttr.getValue();
if (id != null && id.equals(myName)) {
fieldRef.set(idAttr);
}
return !MxmlJSClass.isTagThatAllowsAnyXmlContent(tag);
});
}
}
result = DebuggerSupportUtils.calcSourcePosition(fieldRef.get());
}
}
navigatable.setSourcePosition(result);
}
Aggregations