本文整理汇总了Java中com.intellij.psi.impl.source.tree.SharedImplUtil类的典型用法代码示例。如果您正苦于以下问题:Java SharedImplUtil类的具体用法?Java SharedImplUtil怎么用?Java SharedImplUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SharedImplUtil类属于com.intellij.psi.impl.source.tree包,在下文中一共展示了SharedImplUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getStubOrPsiChildren
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
/**
* @return children of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
*/
public <S extends StubElement, Psi extends PsiElement> Psi[] getStubOrPsiChildren(final IStubElementType<S, Psi> elementType, Psi[] array) {
T stub = myStub;
if (stub != null) {
//noinspection unchecked
return (Psi[])stub.getChildrenByType(elementType, array);
}
else {
final ASTNode[] nodes = SharedImplUtil.getChildrenOfType(getNode(), elementType);
//noinspection unchecked
Psi[] psiElements = (Psi[])Array.newInstance(array.getClass().getComponentType(), nodes.length);
for (int i = 0; i < nodes.length; i++) {
//noinspection unchecked
psiElements[i] = (Psi)nodes[i].getPsi();
}
return psiElements;
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:StubBasedPsiElementBase.java
示例2: getStubOrPsiChildren
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
/**
* @return children of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
*/
@Nonnull
public <S extends StubElement, Psi extends PsiElement> Psi[] getStubOrPsiChildren(@Nonnull IStubElementType<S, ? extends Psi> elementType, @Nonnull Psi[] array) {
T stub = getGreenStub();
if (stub != null) {
//noinspection unchecked
return (Psi[])stub.getChildrenByType(elementType, array);
}
else {
final ASTNode[] nodes = SharedImplUtil.getChildrenOfType(getNode(), elementType);
//noinspection unchecked
Psi[] psiElements = (Psi[])Array.newInstance(array.getClass().getComponentType(), nodes.length);
for (int i = 0; i < nodes.length; i++) {
//noinspection unchecked
psiElements[i] = (Psi)nodes[i].getPsi();
}
return psiElements;
}
}
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:StubBasedPsiElementBase.java
示例3: bindToTargetClass
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
@Override
public PsiImportStaticStatement bindToTargetClass(final PsiClass aClass) throws IncorrectOperationException {
final String qualifiedName = aClass.getQualifiedName();
if (qualifiedName == null) throw new IncorrectOperationException();
final PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(getProject()).getParserFacade();
final CompositeElement newRef = (CompositeElement)parserFacade.createReferenceFromText(qualifiedName, null).getNode();
if (getQualifier() != null) {
replaceChildInternal(findChildByRole(ChildRole.QUALIFIER), newRef);
return (PsiImportStaticStatement)getParent();
}
else {
final LeafElement dot = Factory.createSingleLeafElement(JavaTokenType.DOT, ".", 0, 1, SharedImplUtil.findCharTableByTree(newRef), getManager());
newRef.rawInsertAfterMe(dot);
final CompositeElement errorElement = Factory.createErrorElement(JavaErrorMessages.message("import.statement.identifier.or.asterisk.expected."));
dot.rawInsertAfterMe(errorElement);
final CompositeElement parentComposite = (CompositeElement)SourceTreeToPsiMap.psiElementToTree(getParent());
parentComposite.addInternal(newRef, errorElement, this, Boolean.TRUE);
parentComposite.deleteChildInternal(this);
return (PsiImportStaticStatement)SourceTreeToPsiMap.treeElementToPsi(parentComposite);
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:PsiImportStaticReferenceElementImpl.java
示例4: getDefinitionParent
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
protected PsiElement getDefinitionParent() {
final PsiElement candidate = getParentByStub();
if (candidate instanceof LuaPsiFile) {
return candidate;
}
return SharedImplUtil.getParent(getNode());
}
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:9,代码来源:LuaStubElementBase.java
示例5: getParent
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
@Override
public PsiElement getParent() {
final PsiClassStub stub = getStub();
if (stub != null) {
final StubElement parentStub = stub.getParentStub();
if (parentStub instanceof PsiFileStub || parentStub instanceof PsiClassStub
) {
return parentStub.getPsi();
}
}
return SharedImplUtil.getParent(getNode());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:PsiClassImpl.java
示例6: createBuilder
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
private static PsiBuilderImpl createBuilder(final String text, ASTNode originalTree) {
final Language lang = StdFileTypes.JAVA.getLanguage();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
assertNotNull(parserDefinition);
PsiFile psiFile = createFile("x.java", text);
return new PsiBuilderImpl(getProject(), psiFile, parserDefinition, JavaParserDefinition.createLexer(LanguageLevel.JDK_1_5),
SharedImplUtil.findCharTableByTree(psiFile.getNode()), text, originalTree, null);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:PsiBuilderTest.java
示例7: findChildrenByType
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
protected <T extends PsiElement> T[] findChildrenByType(IElementType elementType, Class<T> arrayClass) {
return ContainerUtil.map2Array(SharedImplUtil.getChildrenOfType(getNode(), elementType), arrayClass, new Function<ASTNode, T>() {
@Override
public T fun(final ASTNode s) {
return (T)s.getPsi();
}
});
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:ASTDelegatePsiElement.java
示例8: handleContentChange
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
public static <T extends PsiElement> T handleContentChange(T element,
TextRange range,
String newContent,
final IElementType tokenType) {
CheckUtil.checkWritable(element);
final CompositeElement attrNode = (CompositeElement)element.getNode();
final ASTNode valueNode = attrNode.findLeafElementAt(range.getStartOffset());
LOG.assertTrue(valueNode != null, "Leaf not found in " + attrNode + " at offset " + range.getStartOffset() + " in element " + element);
final PsiElement elementToReplace = valueNode.getPsi();
String text;
try {
text = elementToReplace.getText();
final int offsetInParent = elementToReplace.getStartOffsetInParent();
String textBeforeRange = text.substring(0, range.getStartOffset() - offsetInParent);
String textAfterRange = text.substring(range.getEndOffset()- offsetInParent, text.length());
newContent = element.getText().startsWith("'") || element.getText().endsWith("'") ?
newContent.replace("'", "'") : newContent.replace("\"", """);
text = textBeforeRange + newContent + textAfterRange;
} catch(StringIndexOutOfBoundsException e) {
LOG.error("Range: " + range + " in text: '" + element.getText() + "'", e);
throw e;
}
final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(attrNode);
final LeafElement newValueElement = Factory.createSingleLeafElement(tokenType, text, charTableByTree, element.getManager());
attrNode.replaceChildInternal(valueNode, newValueElement);
return element;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:XmlAttributeValueManipulator.java
示例9: encodeXmlTextContents
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
@Override
public ASTNode encodeXmlTextContents(String displayText, PsiElement text) {
final ASTNode firstChild = text.getNode().getFirstChildNode();
boolean textAlreadyHasCDATA = firstChild != null && firstChild.getElementType() == XmlElementType.XML_CDATA;
if ((textAlreadyHasCDATA || XmlUtil.toCode(displayText)) && !displayText.isEmpty()) {
final FileElement dummyParent = createCDATAElement(text.getManager(), SharedImplUtil.findCharTableByTree(text.getNode()), displayText);
return dummyParent.getFirstChildNode();
}
else {
return super.encodeXmlTextContents(displayText, text);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:CDATAOnAnyEncodedPolicy.java
示例10: multiResolve
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
@NotNull
@Override
public JavaResolveResult[] multiResolve(final boolean incompleteCode) {
FileElement fileElement = SharedImplUtil.findFileElement(this);
if (fileElement == null) {
LOG.error("fileElement == null!");
return JavaResolveResult.EMPTY_ARRAY;
}
final PsiManagerEx manager = fileElement.getManager();
if (manager == null) {
LOG.error("getManager() == null!");
return JavaResolveResult.EMPTY_ARRAY;
}
PsiFile file = SharedImplUtil.getContainingFile(fileElement);
boolean valid = file != null && file.isValid();
if (!valid) {
LOG.error("invalid!");
return JavaResolveResult.EMPTY_ARRAY;
}
final MethodReferenceResolver resolver = new MethodReferenceResolver();
final Map<PsiMethodReferenceExpression, PsiType> map = PsiMethodReferenceUtil.ourRefs.get();
if (map != null && map.containsKey(this)) {
return (JavaResolveResult[])resolver.resolve(this, incompleteCode);
}
ResolveResult[] results = ResolveCache.getInstance(getProject()).resolveWithCaching(this, resolver, true, incompleteCode,file);
return results.length == 0 ? JavaResolveResult.EMPTY_ARRAY : (JavaResolveResult[])results;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:28,代码来源:PsiMethodReferenceExpressionImpl.java
示例11: getParentByStub
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
protected final PsiElement getParentByStub() {
final StubElement<?> stub = getStub();
if (stub != null) {
return stub.getParentStub().getPsi();
}
return SharedImplUtil.getParent(getNode());
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:9,代码来源:StubBasedPsiElementBase.java
示例12: getStubOrPsiChildren
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
public <Stub extends StubElement, Psi extends PsiElement> Psi[] getStubOrPsiChildren(final IStubElementType<Stub, Psi> elementType, Psi[] array) {
T stub = myStub;
if (stub != null) {
//noinspection unchecked
return (Psi[])stub.getChildrenByType(elementType, array);
}
else {
final ASTNode[] nodes = SharedImplUtil.getChildrenOfType(getNode(), elementType);
Psi[] psiElements = (Psi[])Array.newInstance(array.getClass().getComponentType(), nodes.length);
for (int i = 0; i < nodes.length; i++) {
psiElements[i] = (Psi)nodes[i].getPsi();
}
return psiElements;
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:StubBasedPsiElementBase.java
示例13: encodeXmlTextContents
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
public ASTNode encodeXmlTextContents(String displayText, PsiElement text) {
final ASTNode firstChild = text.getNode().getFirstChildNode();
boolean textAlreadyHasCDATA = firstChild != null && firstChild.getElementType() == XmlElementType.XML_CDATA;
if ((textAlreadyHasCDATA || XmlUtil.toCode(displayText)) && displayText.length() > 0) {
final FileElement dummyParent = createCDATAElement(text.getManager(), SharedImplUtil.findCharTableByTree(text.getNode()), displayText);
return dummyParent.getFirstChildNode();
}
else {
return super.encodeXmlTextContents(displayText, text);
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:12,代码来源:CDATAOnAnyEncodedPolicy.java
示例14: handleContentChange
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
public static <T extends PsiElement> T handleContentChange(T element,
TextRange range,
String newContent,
final IElementType tokenType) {
CheckUtil.checkWritable(element);
final CompositeElement attrNode = (CompositeElement)element.getNode();
final ASTNode valueNode = attrNode.findLeafElementAt(range.getStartOffset());
LOG.assertTrue(valueNode != null, "Leaf not found in " + attrNode + " at offset " + range.getStartOffset() + " in element " + element);
final PsiElement elementToReplace = valueNode.getPsi();
String text;
try {
text = elementToReplace.getText();
final int offsetInParent = elementToReplace.getStartOffsetInParent();
String textBeforeRange = text.substring(0, range.getStartOffset() - offsetInParent);
String textAfterRange = text.substring(range.getEndOffset()- offsetInParent, text.length());
text = textBeforeRange + newContent + textAfterRange;
} catch(StringIndexOutOfBoundsException e) {
LOG.error("Range: " + range + " in text: '" + element.getText() + "'", e);
throw e;
}
final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(attrNode);
final LeafElement newValueElement = Factory.createSingleLeafElement(tokenType, text, charTableByTree, element.getManager());
attrNode.replaceChildInternal(valueNode, newValueElement);
return element;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:28,代码来源:XmlAttributeValueManipulator.java
示例15: HaxePsiBuilder
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
public HaxePsiBuilder(@NotNull Project project,
@NotNull ParserDefinition parserDefinition,
@NotNull Lexer lexer,
@NotNull ASTNode chameleon,
@NotNull CharSequence text) {
super(project, parserDefinition, lexer, chameleon, text);
psiFile = SharedImplUtil.getContainingFile(chameleon);
setupDebugTraces();
}
开发者ID:HaxeFoundation,项目名称:intellij-haxe,代码行数:10,代码来源:HaxePsiBuilder.java
示例16: getParentByStub
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
/**
* Please consider using {@link #getParent()} instead, because this method can return different results before and after AST is loaded.
* @return a PSI element taken from parent stub (if present) or parent AST node.
*/
protected final PsiElement getParentByStub() {
final StubElement<?> stub = getStub();
if (stub != null) {
return stub.getParentStub().getPsi();
}
return SharedImplUtil.getParent(getNode());
}
开发者ID:consulo,项目名称:consulo,代码行数:13,代码来源:StubBasedPsiElementBase.java
示例17: getParent
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
/**
* @return the parent of this element. Uses stub hierarchy if possible, but might cause an expensive switch to AST
* if the parent stub doesn't correspond to the parent AST node.
*/
@Override
public PsiElement getParent() {
T stub = getGreenStub();
if (stub != null && !((ObjectStubBase)stub).isDangling()) {
return stub.getParentStub().getPsi();
}
return SharedImplUtil.getParent(getNode());
}
开发者ID:consulo,项目名称:consulo,代码行数:14,代码来源:StubBasedPsiElementBase.java
示例18: setName
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
@Override
public PsiElement setName(@NotNull final String name) throws IncorrectOperationException
{
final PomModel model = PomManager.getModel(getProject());
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
model.runTransaction(new PomTransactionBase(this, aspect)
{
@Override
public PomModelEvent runInner() throws IncorrectOperationException
{
final String oldName = getName();
final XmlTagImpl dummyTag = (XmlTagImpl) XmlElementFactory.getInstance(getProject()).createTagFromText(XmlTagUtil.composeTagText(name, "aa"));
final XmlTagImpl tag = XmlTagImpl.this;
final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(tag);
ASTNode child = XmlChildRole.START_TAG_NAME_FINDER.findChild(tag);
LOG.assertTrue(child != null, "It seems '" + name + "' is not a valid tag name");
TreeElement tagElement = (TreeElement) XmlChildRole.START_TAG_NAME_FINDER.findChild(dummyTag);
LOG.assertTrue(tagElement != null, "What's wrong with it? '" + name + "'");
tag.replaceChild(child, ChangeUtil.copyElement(tagElement, charTableByTree));
final ASTNode childByRole = XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(tag);
if(childByRole != null)
{
final TreeElement treeElement = (TreeElement) XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(dummyTag);
if(treeElement != null)
{
tag.replaceChild(childByRole, ChangeUtil.copyElement(treeElement, charTableByTree));
}
}
return XmlTagNameChangedImpl.createXmlTagNameChanged(model, tag, oldName);
}
});
return this;
}
开发者ID:consulo,项目名称:consulo-xml,代码行数:35,代码来源:XmlTagImpl.java
示例19: setQualifierExpression
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
@Override
public void setQualifierExpression(@Nullable PsiExpression newQualifier) throws IncorrectOperationException
{
final PsiExpression oldQualifier = getQualifierExpression();
if(newQualifier == null)
{
if(oldQualifier != null)
{
deleteChildInternal(oldQualifier.getNode());
}
}
else
{
if(oldQualifier != null)
{
oldQualifier.replace(newQualifier);
}
else
{
final CharTable treeCharTab = SharedImplUtil.findCharTableByTree(this);
TreeElement dot = (TreeElement) findChildByRole(ChildRole.DOT);
if(dot == null)
{
dot = Factory.createSingleLeafElement(JavaTokenType.DOT, ".", 0, 1, treeCharTab, getManager());
dot = addInternal(dot, dot, getFirstChildNode(), Boolean.TRUE);
}
addBefore(newQualifier, dot.getPsi());
}
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:31,代码来源:PsiReferenceExpressionImpl.java
示例20: multiResolveImpl
import com.intellij.psi.impl.source.tree.SharedImplUtil; //导入依赖的package包/类
@NotNull
public static <T extends PsiJavaCodeReferenceElement> JavaResolveResult[] multiResolveImpl(@NotNull T element,
boolean incompleteCode,
@NotNull ResolveCache.PolyVariantContextResolver<? super T> resolver)
{
FileASTNode fileElement = SharedImplUtil.findFileElement(element.getNode());
if(fileElement == null)
{
PsiUtilCore.ensureValid(element);
LOG.error("fileElement == null!");
return JavaResolveResult.EMPTY_ARRAY;
}
PsiFile psiFile = SharedImplUtil.getContainingFile(fileElement);
PsiManager manager = psiFile == null ? null : psiFile.getManager();
if(manager == null)
{
PsiUtilCore.ensureValid(element);
LOG.error("getManager() == null!");
return JavaResolveResult.EMPTY_ARRAY;
}
boolean valid = psiFile.isValid();
if(!valid)
{
PsiUtilCore.ensureValid(element);
LOG.error("psiFile.isValid() == false!");
return JavaResolveResult.EMPTY_ARRAY;
}
if(element instanceof PsiMethodReferenceExpression)
{
// method refs: do not cache results during parent conflict resolving, acceptable checks, etc
final Map<PsiElement, PsiType> map = LambdaUtil.ourFunctionTypes.get();
if(map != null && map.containsKey(element))
{
return (JavaResolveResult[]) resolver.resolve(element, psiFile, incompleteCode);
}
}
return multiResolveImpl(manager.getProject(), psiFile, element, incompleteCode, resolver);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:40,代码来源:PsiImplUtil.java
注:本文中的com.intellij.psi.impl.source.tree.SharedImplUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论