Java Code Examples for com.intellij.psi.PsiFile#navigate()

The following examples show how to use com.intellij.psi.PsiFile#navigate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PsiViewerDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void navigate() {
  final Object value = myRefs.getSelectedValue();
  if (value instanceof String) {
    final String fqn = (String)value;
    final PsiFile file = getContainingFileForClass(fqn);
    if (file != null) file.navigate(true);
  }
}
 
Example 2
Source File: StructureViewCompositeModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static StructureViewTreeElement createRootNode(@Nonnull PsiFile file, @Nonnull List<? extends StructureViewComposite.StructureViewDescriptor> views) {
  JBIterable<TreeElement> children = JBIterable.from(views).map(o -> createTreeElementFromView(file, o));
  return new StructureViewTreeElement() {
    @Override
    public Object getValue() {
      return file;
    }

    @Override
    public void navigate(boolean requestFocus) {
      file.navigate(requestFocus);
    }

    @Override
    public boolean canNavigate() {
      return file.canNavigate();
    }

    @Override
    public boolean canNavigateToSource() {
      return file.canNavigateToSource();
    }

    @Nonnull
    @Override
    public ItemPresentation getPresentation() {
      return file.getPresentation();
    }

    @Nonnull
    @Override
    public TreeElement[] getChildren() {
      List<TreeElement> elements = children.toList();
      return elements.toArray(TreeElement.EMPTY_ARRAY);
    }
  };
}
 
Example 3
Source File: PsiFakeModule.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@Override
public void navigate(boolean requestFocus) {
    PsiFile file = getContainingFile();
    file.navigate(requestFocus);
}
 
Example 4
Source File: MsilElementWrapper.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
@RequiredUIAccess
public void navigate(boolean requestFocus)
{
	final Class<? extends PsiElement> navigationElementClass = getNavigationElementClass();

	Consumer<PsiFile> consumer = navigationElementClass == null ? MsilRepresentationNavigateUtil.DEFAULT_NAVIGATOR : new Consumer<PsiFile>()
	{
		@Override
		public void consume(PsiFile file)
		{
			final Ref<Navigatable> navigatableRef = Ref.create();
			file.accept(new PsiRecursiveElementWalkingVisitor()
			{
				@Override
				@RequiredReadAction
				public void visitElement(PsiElement element)
				{
					MsilElementWrapper<T> msilWrapper = MsilElementWrapper.this;
					if(navigationElementClass.isAssignableFrom(element.getClass()) && isEquivalentTo(element, msilWrapper))
					{
						PsiElement elementParent = element.getParent();
						PsiElement wrapperParent = msilWrapper.getParent();
						// check if parent type is equal to self type
						if(elementParent instanceof CSharpTypeDeclaration && wrapperParent instanceof CSharpTypeDeclaration)
						{
							if(!CSharpElementCompareUtil.isEqual(elementParent, wrapperParent, myOriginal))
							{
								return;
							}
						}
						navigatableRef.set((Navigatable) element);
						stopWalking();
						return;
					}
					super.visitElement(element);
				}
			});

			Navigatable navigatable = navigatableRef.get();
			if(navigatable != null)
			{
				navigatable.navigate(true);
			}

			file.navigate(true);
		}
	};

	MsilRepresentationNavigateUtil.navigateToRepresentation(myOriginal, CSharpFileType.INSTANCE, consumer);
}
 
Example 5
Source File: StructureViewCompositeModel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static TreeElement createTreeElementFromView(final PsiFile file, final StructureViewComposite.StructureViewDescriptor view) {
  return new StructureViewTreeElement() {
    @Override
    public Object getValue() {
      return view;
    }

    @Override
    public void navigate(boolean requestFocus) {
      file.navigate(requestFocus);
    }

    @Override
    public boolean canNavigate() {
      return file.canNavigate();
    }

    @Override
    public boolean canNavigateToSource() {
      return file.canNavigateToSource();
    }

    @Nonnull
    @Override
    public ItemPresentation getPresentation() {
      return new ItemPresentation() {
        @Nullable
        @Override
        public String getPresentableText() {
          return view.title;
        }

        @Nullable
        @Override
        public String getLocationString() {
          return null;
        }

        @Nullable
        @Override
        public Image getIcon(boolean unused) {
          return view.icon;
        }
      };
    }

    @Nonnull
    @Override
    public TreeElement[] getChildren() {
      return view.structureModel.getRoot().getChildren();
    }
  };
}