use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.
the class XmlTextTest method testPhysicalToDisplayIfHasGaps2.
public void testPhysicalToDisplayIfHasGaps2() throws Exception {
String xml = "<div>&abc</div>";
XmlFile file = (XmlFile) PsiFileFactory.getInstance(getProject()).createFileFromText("foo.xml", xml);
XmlTag root = file.getDocument().getRootTag();
final XmlText text = root.getValue().getTextElements()[0];
assertEquals("&abc", text.getValue());
assertEquals(0, text.physicalToDisplay(0));
assertEquals(1, text.physicalToDisplay(5));
assertEquals(2, text.physicalToDisplay(6));
assertEquals(3, text.physicalToDisplay(7));
assertEquals(4, text.physicalToDisplay(8));
}
use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.
the class XmlTextTest method testDisplayToPhysical2.
public void testDisplayToPhysical2() throws Exception {
String xml = "<div><![CDATA[ ]]></div>";
XmlFile file = (XmlFile) PsiFileFactory.getInstance(getProject()).createFileFromText("foo.xml", xml);
XmlTag root = file.getDocument().getRootTag();
final XmlText text = root.getValue().getTextElements()[0];
assertEquals(" ", text.getValue());
assertEquals(9, text.displayToPhysical(0));
assertEquals(13, text.displayToPhysical(1));
}
use of com.intellij.psi.xml.XmlText in project intellij-plugins by JetBrains.
the class ActionScriptAnnotatingVisitor method visitJSPackageStatement.
public void visitJSPackageStatement(final JSPackageStatement packageStatement) {
final JSFile jsFile = PsiTreeUtil.getParentOfType(packageStatement, JSFile.class);
final PsiElement context = jsFile == null ? null : jsFile.getContext();
boolean injected = context instanceof XmlAttributeValue || context instanceof XmlText;
if (injected) {
myHolder.createErrorAnnotation(packageStatement.getFirstChild().getNode(), JSBundle.message("javascript.validation.message.nested.packages.are.not.allowed"));
return;
}
for (PsiElement el = packageStatement.getPrevSibling(); el != null; el = el.getPrevSibling()) {
if (!(el instanceof PsiWhiteSpace) && !(el instanceof PsiComment)) {
myHolder.createErrorAnnotation(packageStatement.getFirstChild().getNode(), JSBundle.message("javascript.validation.message.package.shouldbe.first.statement"));
break;
}
}
final ASTNode node = packageStatement.findNameIdentifier();
if (node == null)
checkPackageStatement(packageStatement);
}
use of com.intellij.psi.xml.XmlText in project android by JetBrains.
the class TypographyQuickFix method apply.
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
final XmlTag tag = PsiTreeUtil.getParentOfType(startElement, XmlTag.class);
if (tag == null) {
return;
}
for (PsiElement child : tag.getChildren()) {
if (child instanceof XmlText) {
final XmlText xmlText = (XmlText) child;
final String value = xmlText.getValue();
if (value != null) {
final List<TypographyDetector.ReplaceEdit> edits = TypographyDetector.getEdits(myIssue.getId(), myMessage, value);
final StringBuilder builder = new StringBuilder(value);
for (TypographyDetector.ReplaceEdit edit : edits) {
String with = edit.replaceWith;
if (ApplicationManager.getApplication().isUnitTestMode()) {
with = with.replace('–', '~').replace('‘', '{').replace('’', '}');
}
builder.replace(edit.offset, edit.offset + edit.length, with);
}
final String newValue = builder.toString();
if (!newValue.equals(value)) {
xmlText.setValue(newValue);
}
}
}
}
}
use of com.intellij.psi.xml.XmlText in project intellij-plugins by JetBrains.
the class ActionScriptAnnotatingVisitor method visitJSReferenceExpression.
@Override
public void visitJSReferenceExpression(JSReferenceExpression node) {
super.visitJSReferenceExpression(node);
final PsiElement parent = node.getParent();
if (node.getQualifier() == null) {
String nodeText = node.getText();
if (!(parent instanceof JSCallExpression) && JSResolveUtil.isExprInStrictTypeContext(node) && JSCommonTypeNames.VECTOR_CLASS_NAME.equals(nodeText)) {
myHolder.createWarningAnnotation(node, JSBundle.message("javascript.validation.message.vector.without.parameters"));
} else if (parent instanceof JSNewExpression && JSCommonTypeNames.VECTOR_CLASS_NAME.equals(nodeText)) {
myHolder.createWarningAnnotation(node, JSBundle.message("javascript.validation.message.vector.without.parameters2"));
}
}
if (parent instanceof JSNamedElement) {
JSNamedElement namedElement = (JSNamedElement) parent;
final ASTNode nameIdentifier = namedElement.findNameIdentifier();
if (nameIdentifier != null && nameIdentifier.getPsi() == node) {
if (parent instanceof JSPackageStatement) {
checkPackageStatement((JSPackageStatement) parent);
} else if (!(parent instanceof JSImportStatement) && parent.getParent() instanceof JSPackageStatement) {
checkNamedObjectIsInCorrespondingFile(namedElement);
} else if (parent instanceof JSVariable) {
if (parent.getParent().getParent() instanceof JSPackageStatement) {
checkNamedObjectIsInCorrespondingFile((JSVariable) parent);
}
} else if (parent instanceof JSNamespaceDeclaration) {
DuplicatesCheckUtil.checkDuplicates((JSNamespaceDeclaration) parent, myProblemReporter);
}
if (parent instanceof JSClass) {
final JSClass jsClass = (JSClass) parent;
final JSFunction constructor = jsClass.getConstructor();
if (constructor == null)
createConstructorChecker().checkMissedConstructor(jsClass);
PsiElement clazzParent = jsClass.getParent();
final PsiElement context = clazzParent.getContext();
boolean clazzParentIsInjectedJsFile = clazzParent instanceof JSFile && (context instanceof XmlAttributeValue || context instanceof XmlText) && !XmlBackedJSClassImpl.isImplementsAttribute((JSFile) clazzParent);
if (PsiTreeUtil.getParentOfType(jsClass, JSFunction.class, JSClass.class) != null || clazzParentIsInjectedJsFile) {
myHolder.createErrorAnnotation(node, JSBundle.message("javascript.validation.message.nested.classes.are.not.allowed"));
}
checkClass(jsClass);
}
}
}
JSFunction fun;
if (JSSymbolUtil.isAccurateReferenceExpressionName(node, JSFunction.ARGUMENTS_VAR_NAME) && (fun = PsiTreeUtil.getParentOfType(node, JSFunction.class)) != null && node.resolve() instanceof ImplicitJSVariableImpl) {
JSParameterList parameterList = fun.getParameterList();
if (parameterList != null) {
for (JSParameter p : parameterList.getParameterVariables()) {
if (p.isRest()) {
myHolder.createErrorAnnotation(node, JSBundle.message("javascript.validation.message.arguments.with.rest.parameter"));
}
}
}
}
}
Aggregations