本文整理汇总了Java中com.jetbrains.php.lang.psi.PhpPsiElementFactory.createFromText方法的典型用法代码示例。如果您正苦于以下问题:Java PhpPsiElementFactory.createFromText方法的具体用法?Java PhpPsiElementFactory.createFromText怎么用?Java PhpPsiElementFactory.createFromText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jetbrains.php.lang.psi.PhpPsiElementFactory
的用法示例。
在下文中一共展示了PhpPsiElementFactory.createFromText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyFix
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
PsiElement element = problemDescriptor.getPsiElement();
if ( ! (element instanceof PhpClass)) {
return;
}
PsiFile containingFile = element.getContainingFile();
PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
Document document = manager.getDocument(containingFile);
PhpClass phpClass = (PhpClass) element;
PsiElement abstractKeyword = PhpPsiElementFactory.createFromText(project, LeafPsiElement.class, "abstract");
if (abstractKeyword == null) {
return;
}
phpClass.addBefore(abstractKeyword, phpClass.getFirstChild());
if (document != null) {
manager.doPostponedOperationsAndUnblockDocument(document);
TextRange reformatRange = abstractKeyword.getTextRange();
CodeStyleManager.getInstance(project).reformatText(containingFile, reformatRange.getStartOffset(), reformatRange.getEndOffset());
}
}
示例2: invoke
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
/**
* The intent is invoked. Do magic.
*
* @param project Current project.
* @param editor Current editor.
* @param element Element selected by the caret.
*/
public void invoke (@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException
{
String class_name = getUnquotedString(element.getText());
if (class_name == null)
{
return;
}
ClassConstantReference ref = PhpPsiElementFactory.createFromText(project, ClassConstantReference.class, class_name + "::class");
PsiElement container = element.getParent();
if (ref != null && container instanceof StringLiteralExpression)
{
// Replace the string container with the class constant reference.
container.replace(ref);
}
}
示例3: invoke
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile psiFile) throws IncorrectOperationException
{
int primaryCaretOffset = editor.getCaretModel().getPrimaryCaret().getOffset();
PsiElement currentPsiElement = psiFile.findElementAt(primaryCaretOffset);
PsiElement statement = PsiTreeUtil.getParentOfType(currentPsiElement, Statement.class);
if (statement == null) {
return;
}
String commentStart = "/** @ContentType IDENTIFIER ";
String commentContent = commentStart + currentPsiElement.getText() + "*/";
PhpDocComment comment = PhpPsiElementFactory.createFromText(project, PhpDocComment.class, commentContent);
if (comment == null) {
return;
}
PsiElement result = statement.addBefore(comment, statement.getFirstChild());
editor.getCaretModel().getPrimaryCaret().moveToOffset(result.getTextOffset() + commentStart.length() - 1);
editor.getCaretModel().getPrimaryCaret().selectWordAtCaret(true);
}
示例4: testGetUseImportMap
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetUseImportMap() {
PhpDocTag phpDocTag = PhpPsiElementFactory.createFromText(getProject(), PhpDocTag.class, "<?php\n" +
"use Foobar;\n" +
"use Bar as MyFoo" +
"\n" +
"/**\n" +
" * @Foo()\n" +
" **/\n" +
"class Foo() {}\n"
);
Map<String, String> propertyForEnum = AnnotationUtil.getUseImportMap(phpDocTag);
assertEquals("\\Foobar", propertyForEnum.get("Foobar"));
assertEquals("\\Bar", propertyForEnum.get("MyFoo"));
}
示例5: testGetClassAnnotationAsUnknown
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetClassAnnotationAsUnknown() {
Collection<Object[]> dataProvider = new ArrayList<Object[]>() {{
add(new Object[] {"@Target()", AnnotationTarget.UNKNOWN});
add(new Object[] {"@Target", AnnotationTarget.UNKNOWN});
add(new Object[] {"", AnnotationTarget.UNDEFINED});
}};
for (Object[] objects: dataProvider) {
PhpClass phpClass = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
"/**\n" +
"* @Annotation\n" +
"* "+ objects[0] +"\n" +
"*/\n" +
"class Foo {}\n"
);
PhpAnnotation classAnnotation = AnnotationUtil.getClassAnnotation(phpClass);
List<AnnotationTarget> targets = classAnnotation.getTargets();
assertContainsElements(targets, objects[1]);
}
}
示例6: getPostRenameCallback
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
@Nullable
@Override
public Runnable getPostRenameCallback(PsiElement psiElement, String s, RefactoringElementListener refactoringElementListener) {
return () -> {
for (PsiElement render : renders) {
StringLiteralExpression element = (StringLiteralExpression) ((ParameterList) render).getParameters()[0];
final PsiElement parent = element.getParent();
String fileName = element.getContents();
if (Objects.equals(parent.getUserData(WITH_EXT), false)) {
if (Objects.equals(fileName.substring(fileName.lastIndexOf('.')), parent.getUserData(OLD_EXT))) {
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
}
}
parent.putUserData(WITH_EXT, null);
parent.putUserData(OLD_EXT, null);
if (parent.getUserData(RELATIVE_PATH) != null) {
fileName = parent.getUserData(RELATIVE_PATH) + fileName;
parent.putUserData(RELATIVE_PATH, null);
}
fileName = element.isSingleQuote() ? "'" + fileName + "'" : "\"" + fileName + "\"";
PsiElement newValue = PhpPsiElementFactory.createFromText(psiElement.getProject(), StringLiteralExpression.class, fileName);
if (newValue != null) {
element.replace(newValue);
}
}
};
}
示例7: applyFix
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement expression = descriptor.getPsiElement();
if (null != expression && expression.getParent() instanceof ArrayCreationExpression) {
final ArrayCreationExpression container = (ArrayCreationExpression) expression.getParent();
final PsiElement closingBracket = container.getLastChild();
if (null == closingBracket) {
return;
}
for (String translation : missing) {
/* reach or create a comma */
PsiElement last = closingBracket.getPrevSibling();
if (last instanceof PsiWhiteSpace) {
last = last.getPrevSibling();
}
if (null != last && PhpTokenTypes.opCOMMA != last.getNode().getElementType()) {
last.getParent().addAfter(PhpPsiElementFactory.createComma(project), last);
last = last.getNextSibling();
}
/* add a new translation */
final String escaped = PhpStringUtil.escapeText(translation, true, '\n', '\t');
final String pairPattern = "array('%s%' => '%s%')".replace("%s%", escaped).replace("%s%", escaped);
final ArrayCreationExpression array = PhpPsiElementFactory.createFromText(project, ArrayCreationExpression.class, pairPattern);
final PhpPsiElement pair = null == array ? null : array.getHashElements().iterator().next();
final PsiWhiteSpace space = PhpPsiElementFactory.createFromText(project, PsiWhiteSpace.class, " ");
if (null == last || null == pair || null == space) {
continue;
}
last.getParent().addAfter(pair, last);
last.getParent().addAfter(space, last);
}
}
}
示例8: ArrayElement
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
ArrayElement(
final PsiElement arrayElement,
final AtomicInteger elementIndex
) {
if (arrayElement instanceof ArrayHashElement) {
key = ((ArrayHashElement) arrayElement).getKey();
value = ((ArrayHashElement) arrayElement).getValue();
}
else {
key = PhpPsiElementFactory.createFromText(arrayElement.getProject(), LeafPsiElement.class, String.valueOf(elementIndex.get()));
value = ((PhpPsiElement) arrayElement).getFirstPsiChild();
isIndexed = true;
elementIndex.incrementAndGet();
}
}
示例9: updateDocBlock
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void updateDocBlock(PhpClass phpClass, Project project) throws Exception {
String fqClassName = phpClass.getFQN();
ClassDefinitionInterface classDefinition = this.classTypeMatcher.matchClassType(fqClassName);
String bundleName = this.classTypeMatcher.matchBundleNameFromFQName(classDefinition, fqClassName);
PhpDocComment oldComment = phpClass.getDocComment();
List<DocBlockItem> docBlockItems = docBlockGenerator.getDocBlockItems(classDefinition.getDocBlockClasses(), bundleName);
PhpDocComment comment = PhpPsiElementFactory.createFromText(
project,
PhpDocComment.class,
this.phpRenderer.renderDocBlock(docBlockItems)
);
if (comment == null) {
return;
}
if (oldComment == null) {
phpClass.addBefore(comment, phpClass.getFirstChild());
} else {
oldComment.replace(comment);
}
}
示例10: performRefactoring
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
@Override
void performRefactoring(String newKey) {
if (refactor) {
PsiElement element = getElement();
PsiElement psiElement = PhpPsiElementFactory.createFromText(element.getProject(), PhpElementTypes.STRING, "'" + newKey + "'");
element.replace(psiElement);
}
}
示例11: performRefactoring
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
@Override
void performRefactoring(String newKey) {
if (parentChanged(newKey)) {
ArrayHashElement element = getArrayHashElement();
final PsiElement elementToRemove = TranslationRemoveUtils.findElementToRemove(element);
PsiUtils.deleteArrayElement(elementToRemove);
} else {
PsiElement keyElement = getArrayHashElement().getKey();
String key = TranslationUtils.getLastKeyPart(newKey);
PsiElement psiElement = PhpPsiElementFactory.createFromText(keyElement.getProject(), PhpElementTypes.STRING, "'" + key + "'");
keyElement.replace(psiElement);
}
}
示例12: testGetFormExtendedType
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetFormExtendedType() {
PhpClass phpClass = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
"class Foobar\n" +
"{\n" +
" public function getExtendedType()\n" +
" {\n" +
" return true ? 'foobar' : Foobar::class;" +
" }\n" +
"}\n"
);
assertContainsElements(FormUtil.getFormExtendedType(phpClass), "foobar", "Foobar");
phpClass = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
"namespace Car {\n" +
" class Foo {}\n" +
"}" +
"" +
"namespace Bar {\n" +
" use Car\n" +
" \n" +
" class Foobar\n" +
" {\n" +
" public function getExtendedType()\n" +
" {\n" +
" return Foo::class;" +
" }\n" +
" }\n" +
"}"
);
assertContainsElements(FormUtil.getFormExtendedType(phpClass), "Bar\\Foo");
}
示例13: createMethod
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
@NotNull
private Method createMethod(@NotNull String method) {
return PhpPsiElementFactory.createFromText(
getProject(),
Method.class,
"<?php interface F { function " + method + "(); }"
);
}
示例14: testGetConstructorArgumentByName
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
/**
* @see fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil#getConstructorArgumentByName
*/
public void testGetConstructorArgumentByName() {
PhpClass phpClass = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php class Foobar { function __construct($foo, $foobar) {} };\n ");
assertEquals(0, PhpElementsUtil.getConstructorArgumentByName(phpClass, "foo"));
assertEquals(1, PhpElementsUtil.getConstructorArgumentByName(phpClass, "foobar"));
assertEquals(-1, PhpElementsUtil.getConstructorArgumentByName(phpClass, "UNKNOWN"));
}
示例15: testGetClassAnnotation
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; //导入方法依赖的package包/类
public void testGetClassAnnotation() {
PhpClass phpClass = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
"/**\n" +
"* @Annotation\n" +
"* @Target(\"PROPERTY\")\n" +
"*/\n" +
"class Foo {}\n"
);
PhpAnnotation classAnnotation = AnnotationUtil.getClassAnnotation(phpClass);
List<AnnotationTarget> targets = classAnnotation.getTargets();
assertContainsElements(targets, AnnotationTarget.PROPERTY);
}