List of usage examples for org.eclipse.jdt.core IJavaElement getPath
IPath getPath();
From source file:org.limy.eclipse.qalab.common.LimyQalabEnvironment.java
License:Open Source License
/** * \?[XfBNg?B/* ww w . ja v a2s. com*/ * @param enableRef Q?v?WFNg? * @return \?[XfBNg * @throws JavaModelException JavafO */ private Collection<IPath> privateGetSourcePaths(boolean enableRef) throws JavaModelException { Collection<IPath> results = new ArrayList<IPath>(); IJavaProject project = getJavaProject(); for (IJavaElement element : getAllJavaElements(project)) { if (enableRef && getStore().getBoolean(LimyQalabConstants.ENABLE_REFPROJECT)) { results.add(element.getPath()); } else { // v?WFNgL?? if (element.getJavaProject().equals(project)) { results.add(element.getPath()); } } } return results; }
From source file:org.openlegacy.ide.eclipse.preview.AbstractEntityPreview.java
License:Open Source License
/** * Extract IJavaElement if current document is a java file * //from w ww .jav a2 s. c om * @return IJavaElement or null */ protected static IJavaElement getJavaInput() { IEditorPart activeEditor = getActiveEditor(); if (activeEditor != null) { if (!(activeEditor instanceof ITextEditor) && !(activeEditor instanceof IOpenLegacyEditor)) { return null; } final IJavaElement javaInput = getJavaInput(activeEditor); if (javaInput != null && javaInput.getPath().getFileExtension().equals("java")) { return javaInput; } } return null; }
From source file:org.openlegacy.ide.eclipse.preview.AbstractEntityPreview.java
License:Open Source License
private void doPartActivated() { if (isVisible) { IJavaElement javaInput = getJavaInput(); if (javaInput != null) { final AtomicBoolean isAccepted = new AtomicBoolean(false); String key = javaInput.getPath().toOSString(); if (!cacheJavaClassPropertiesContainer.containsKey(key)) { JavaClassProperties properties = getJavaClassProperties(key, javaInput); cacheJavaClassPropertiesContainer.put(key, properties); isAccepted.set(properties != null); } else { JavaClassProperties properties = cacheJavaClassPropertiesContainer.get(key); // if cached class is annotated then check if there is the latest version of image if (properties.isAnnotated()) { isAccepted.set(true); IFile sourceFile = null; sourceFile = properties.getSourceFile(); IFile newSourceFile = getSourceFile(javaInput.getPath()); if (sourceFile.getModificationStamp() != newSourceFile.getModificationStamp()) { sourceFile = newSourceFile; properties.setSourceFile(newSourceFile); }// www. j a va2 s . c om } } if (isAccepted.get()) { // add caret listener if (!getCacheStyledTextContainer().containsKey(key) || getCacheStyledTextContainer().get(key).isDisposed()) { IEditorPart activeEditor = getActiveEditor(); if (!(activeEditor instanceof IOpenLegacyEditor)) { AbstractTextEditor editor = (AbstractTextEditor) activeEditor; StyledText styledText = ((StyledText) editor.getAdapter(Control.class)); styledText.addCaretListener(editorListener); styledText.addModifyListener(editorListener); getCacheStyledTextContainer().put(key, styledText); } } // show image if it exists showPreviewImage(javaInput, cacheJavaClassPropertiesContainer.get(key).getSourceFile()); lastActiveEditor = getActiveEditor(); return; } } } // keep last shown image - comfort during dev. // getImageComposite().setVisible(false); }
From source file:org.openlegacy.ide.eclipse.preview.screen.ScreenPreview.java
License:Open Source License
private void handleCaretMoved(int widgetCaretOffset) { IJavaElement javaInput = getJavaInput(); if (javaInput == null) { return;/* w w w .j ava 2s.c o m*/ } String key = javaInput.getPath().toOSString(); CompilationUnit cu = getCacheCompilationUnitContainer().get(key); if (cu == null) { return; } IEditorPart activeEditor = getActiveEditor(); final AtomicInteger offset = new AtomicInteger(0); ITextOperationTarget target = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class); if (target instanceof ITextViewer) { TextViewer textViewer = (TextViewer) target; offset.set(textViewer.widgetOffset2ModelOffset(widgetCaretOffset)); } final AtomicBoolean isAnnotationVisited = new AtomicBoolean(false); cu.accept(new ASTVisitor() { @Override public void endVisit(FieldDeclaration node) { super.endVisit(node); if (isAnnotationVisited.get()) { return; } if ((offset.get() < node.getStartPosition()) || (offset.get() > (node.getStartPosition() + node.getLength()))) { return; } List<ASTNode> modifiers = castList(ASTNode.class, node.modifiers()); for (ASTNode astNode : modifiers) { if (astNode instanceof NormalAnnotation) { ITypeBinding binding = ((NormalAnnotation) astNode).resolveTypeBinding(); // binding can be null, for example if user copy field with annotation if (binding == null) { continue; } if (binding.getQualifiedName().equals(SCREEN_FIELD_ANNOTATION)) { // retrieve rectangle from annotation attributes isAnnotationVisited.set(checkVisitedAnnotation((NormalAnnotation) astNode)); } } } } @Override public void endVisit(NormalAnnotation node) { super.endVisit(node); if (isAnnotationVisited.get()) { return; } if ((offset.get() < node.getStartPosition()) || (offset.get() > (node.getStartPosition() + node.getLength()))) { snapshotComposite.addDrawingRectangle(null); return; } ITypeBinding binding = node.resolveTypeBinding(); // binding can be null, for example if user copy field with annotation if (binding == null) { return; } if (binding.getQualifiedName().equals(IDENTIFIER_ANNOTATION) || binding.getQualifiedName().equals(SCREEN_FIELD_ANNOTATION)) { // retrieve rectangle from annotation attributes isAnnotationVisited.set(checkVisitedAnnotation(node)); } } }); }
From source file:org.openlegacy.ide.eclipse.preview.screen.ScreenPreview.java
License:Open Source License
@Override public void handleModifyText(ModifyEvent event) { IJavaElement javaInput = getJavaInput(); if (javaInput == null) { return;/* w w w . j a va2s .c om*/ } String key = javaInput.getPath().toOSString(); if (!getCacheCompilationUnitContainer().containsKey(key)) { return; } CompilationUnit cu = createParser((ICompilationUnit) javaInput); getCacheCompilationUnitContainer().put(key, cu); StyledText styledText = getCacheStyledTextContainer().get(key); if ((styledText != null) && !styledText.isDisposed()) { this.handleCaretMoved(styledText.getCaretOffset()); } }
From source file:org.seasar.dbflute.emecha.eclipse.plugin.dfassist.command.NewConcreteWizardCommand.java
License:Apache License
protected boolean executeSelection(ISelection selection) { if (selection instanceof StructuredSelection) { Object firstElement = ((StructuredSelection) selection).getFirstElement(); if (firstElement instanceof IFile) { NewConcreteClassWizard wizard = new NewConcreteClassWizard(); wizard.init(PlatformUI.getWorkbench(), (StructuredSelection) selection); this.getWorkbench(wizard); return true; }/*from ww w. ja va 2 s. c o m*/ if (firstElement instanceof FileEditorInput) { final IFile file = ((FileEditorInput) firstElement).getFile(); NewConcreteClassWizard wizard = new NewConcreteClassWizard(); wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(file)); this.getWorkbench(wizard); return true; } if (firstElement instanceof CompilationUnit) { IJavaElement javaElement = ((CompilationUnit) firstElement).getPrimaryElement(); if (javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) { final IFile file = javaElement.getJavaProject().getProject().getWorkspace().getRoot() .getFile(javaElement.getPath()); NewConcreteClassWizard wizard = new NewConcreteClassWizard(); wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(file)); this.getWorkbench(wizard); return true; } } if (firstElement instanceof SourceType) { IJavaElement primaryElement = ((SourceType) firstElement).getPrimaryElement(); if (primaryElement.getElementType() == IJavaElement.TYPE) { final IFile file = primaryElement.getJavaProject().getProject().getWorkspace().getRoot() .getFile(primaryElement.getPath()); NewConcreteClassWizard wizard = new NewConcreteClassWizard(); wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(file)); this.getWorkbench(wizard); return true; } } } return false; }
From source file:org.seasar.kijimuna.core.util.ProjectUtils.java
License:Apache License
public static String getResourceLoaderPath(IStorage storage) { IPath path = storage.getFullPath();/* www .j a v a 2 s .c o m*/ if (storage instanceof IFile) { IContainer folder = ((IFile) storage).getParent(); IJavaElement pack = JavaCore.create(folder); while (true) { if (pack instanceof IPackageFragmentRoot) { int depth = pack.getPath().segmentCount(); return path.removeFirstSegments(depth).toString(); } else if (pack instanceof IPackageFragment) { pack = pack.getParent(); if (pack == null) { break; } } else { break; } } } else { return path.toString(); } return path.removeFirstSegments(1).toString(); }
From source file:org.springframework.ide.eclipse.core.model.java.JavaModelSourceLocation.java
License:Open Source License
public Resource getResource() { try {//from w w w. j av a 2s .co m IJavaElement element = JdtUtils.getByHandle(handleIdentifier); if (element != null) { IResource resource = element.getUnderlyingResource(); if (resource != null) { return new FileResource(resource.getFullPath().toString()); } resource = element.getCorrespondingResource(); if (resource != null) { return new FileResource(resource.getFullPath().toString()); } resource = element.getResource(); if (resource != null) { return new FileResource(resource.getFullPath().toString()); } IPath path = element.getPath(); if (path != null && path.toFile().exists()) { if (path.isAbsolute()) { return new FileSystemResource(path.toFile()); } else { return new FileResource(path.toString()); } } } } catch (JavaModelException e) { } return null; }
From source file:sidecarviz.actions.StartSideCarAction.java
License:BSD License
/** * //from w w w .j a v a 2 s . c om */ private void traverseWorkspace() { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IJavaModel javaModel = JavaCore.create(workspace.getRoot()); try { IJavaProject[] javaProjects = javaModel.getJavaProjects(); for (IJavaProject proj : javaProjects) { int numClasses = 0; IPackageFragmentRoot[] roots = proj.getAllPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { IJavaElement[] children = root.getChildren(); for (IJavaElement elt : children) { IPackageFragment frag = (IPackageFragment) elt.getAdapter(IPackageFragment.class); if (frag == null) { continue; } // whittle it down to only the classes we care about... if (!frag.getElementName().startsWith("papertoolkit")) { continue; } DebugUtils.println(frag.getElementName()); IJavaElement[] fes = frag.getChildren(); for (IJavaElement classElt : fes) { String className = classElt.getElementName(); DebugUtils.println(className); DebugUtils.println("Path: " + classElt.getPath().toPortableString()); // DebugUtils.println(classElt.getPath().getClass()); numClasses++; } } } DebugUtils.println( "Classpath for Project " + proj.getElementName() + " contains " + numClasses + " classes."); } } catch (JavaModelException e) { e.printStackTrace(); } }
From source file:tarlog.eclipse.plugins.openwe.TreeSelectionAction.java
License:Apache License
private void handleJavaElement(IJavaElement javaElement) { IResource resource = javaElement.getResource(); if (resource != null) { handleResource(resource);//from w w w. j a v a 2 s. c o m } else { String path = javaElement.getPath().toOSString(); doAction(path); } }