List of usage examples for org.eclipse.jdt.core IJavaElement getPath
IPath getPath();
From source file:com.legstar.eclipse.plugin.cixsmap.wizards.NewMappingFileWizardPage.java
License:Open Source License
/** {@inheritDoc} */ protected boolean validatePage() { setCanFinish(false);/*from w w w. j av a 2s . c o m*/ if (!super.validatePage()) { return false; } /* There must be a mapping file name */ if (getFileName() == null || getFileName().length() == 0) { setErrorMessage(NLS.bind(Messages.invalid_mapping_file_msg, getFileName())); return false; } /* There must be more than the mere mapping file name extension */ IPath path = new Path(getFileName()); IPath noExtensionPath = path.removeFileExtension(); if (noExtensionPath.isEmpty()) { setErrorMessage(NLS.bind(Messages.invalid_mapping_file_msg, getFileName())); return false; } /* Make sure the file name has the correct extension */ String extension = path.getFileExtension(); if (extension == null || !extension.equals(Messages.operations_mapping_file_suffix)) { setErrorMessage(NLS.bind(Messages.invalid_mapping_file_extension_msg, extension, Messages.operations_mapping_file_suffix)); return false; } /* Only Java projects are valid containers. */ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = root.findMember(getContainerFullPath()); IJavaProject jproject = JavaCore.create(resource.getProject()); try { /* Check that there are LegStar binding classes in this project */ IPackageFragmentRoot[] pkgRoots = jproject.getPackageFragmentRoots(); for (int j = 0; j < pkgRoots.length; j++) { IPackageFragmentRoot pkgRoot = pkgRoots[j]; if (pkgRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { for (int k = 0; k < pkgRoot.getChildren().length; k++) { IJavaElement el = pkgRoot.getChildren()[k]; if (el.getPath().lastSegment().compareTo(LegacyStructureDialog.BIND_FRAG) == 0) { setCanFinish(true); return true; } } } } setErrorMessage(NLS.bind(Messages.no_coxb_classes_in_project_msg, resource.getProject().getName())); return false; } catch (JavaModelException e) { setErrorMessage( NLS.bind(Messages.invalid_java_project_msg, resource.getProject().getName(), e.getMessage())); return false; } }
From source file:com.liferay.ide.hook.ui.wizard.PortalServiceSearchScope.java
License:Open Source License
public boolean encloses(IJavaElement element) { if (element != null) { IPath elementPath = element.getPath(); if (elementPath != null) { for (IPath enclosingJar : enclosingJars) { if (elementPath.lastSegment().equals(enclosingJar.lastSegment())) { return true; }// w w w . ja va 2 s .c o m } } } return false; }
From source file:com.microsoft.javapkgsrv.JavaParser.java
License:MIT License
public List<JavaElement> ProcessQuickInfoRequest(String fileParseContents, String typeRootId, int cursorPosition) throws Exception { if (ActiveTypeRoots.containsKey(typeRootId)) { ITypeRoot cu = ActiveTypeRoots.get(typeRootId); cu.getBuffer().setContents(fileParseContents.toCharArray()); IJavaElement[] elements = cu.codeSelect(cursorPosition, 0); List<JavaElement> ret = new ArrayList<JavaElement>(); long flags = JavaElementLabelComposer.ALL_FULLY_QUALIFIED | JavaElementLabelComposer.ALL_DEFAULT | JavaElementLabelComposer.M_PRE_RETURNTYPE | JavaElementLabelComposer.F_PRE_TYPE_SIGNATURE; for (IJavaElement element : elements) { StringBuffer buffer = new StringBuffer(); JavaElementLabelComposer composer = new JavaElementLabelComposer(buffer); composer.appendElementLabel(element, flags); System.out.println(element.getPath().toString()); JavaElement.Builder b = JavaElement.newBuilder().setDefinition(buffer.toString()); String javaDoc = null; try { javaDoc = element.getAttachedJavadoc(null); } catch (JavaModelException jme) { jme.printStackTrace();//from w w w . j av a2 s . c o m } if (javaDoc != null) b.setJavaDoc(javaDoc); ret.add(b.build()); } return ret; } return null; }
From source file:com.microsoft.javapkgsrv.JavaParser.java
License:MIT License
public List<FindDefinitionResponse.JavaElement> ProcessFindDefinintionRequest(String fileParseContents, String typeRootId, int cursorPosition) throws Exception { if (ActiveTypeRoots.containsKey(typeRootId)) { ITypeRoot cu = ActiveTypeRoots.get(typeRootId); cu.getBuffer().setContents(fileParseContents.toCharArray()); IJavaElement[] elements = cu.codeSelect(cursorPosition, 0); List<FindDefinitionResponse.JavaElement> ret = new ArrayList<FindDefinitionResponse.JavaElement>(); for (IJavaElement element : elements) { String definition = element.toString(); String path = element.getResource() != null ? element.getResource().getLocation().toOSString() : element.getPath().toOSString(); //String path = element.getPath().makeAbsolute().toOSString(); // element.getPath().toString(); boolean isAvailable = false; int posStart = -1; int posLength = 0; String contents = null; String classFileName = null; IClassFile classFileObj = null; ISourceReference srcRef = (ISourceReference) element; if (srcRef != null) { ISourceRange range = srcRef.getSourceRange(); if (SourceRange.isAvailable(range)) { isAvailable = true;/*from ww w .j av a 2 s. com*/ posStart = range.getOffset(); posLength = range.getLength(); //if (path.endsWith(".jar")) //{ IOpenable op = element.getOpenable(); if (op != null && op instanceof IClassFile) { IBuffer buff = op.getBuffer(); classFileObj = (IClassFile) op; classFileName = classFileObj.getElementName(); contents = buff.getContents(); } //} } } FindDefinitionResponse.JavaElement.Builder retItem = FindDefinitionResponse.JavaElement.newBuilder() .setDefinition(definition).setFilePath(path).setHasSource(isAvailable) .setPositionStart(posStart).setPositionLength(posLength); if (contents != null) { //int hashCode = classFileObj.hashCode(); String handle = classFileObj.getHandleIdentifier(); ActiveTypeRoots.put(handle, classFileObj); retItem.setFileName(classFileName); retItem.setTypeRootIdentifier(TypeRootIdentifier.newBuilder().setHandle(handle).build()); } System.out.println(retItem.toString()); if (contents != null) { retItem.setFileContents(contents); } ret.add(retItem.build()); } return ret; } return null; }
From source file:com.nitorcreations.robotframework.eclipseide.editors.ResourceManager.java
License:Apache License
@Override public Map<IFile, IPath> getJavaFiles(String fullyQualifiedName) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); Map<IFile, IPath> files = new LinkedHashMap<IFile, IPath>(); for (IProject project : root.getProjects()) { try {// w w w . ja va 2 s. c o m IJavaProject javaProject = JavaCore.create(project); IType type = javaProject.findType(fullyQualifiedName); if (type != null) { IFile file = root.getFile(type.getPath()); if (file.exists()) { IJavaElement ancestor = type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IPath path = ancestor != null ? ancestor.getPath() : type.getPath(); files.put(file, path); } } } catch (JavaModelException e) { // non-Java or unopened projects are simple skipped } } return files; }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.UnknownClassMirror.java
License:Open Source License
public JDTClass(ReferenceBinding klass, IType type) { this.type = type; bindingRef = new WeakReference<ReferenceBinding>(klass); pkg = new JDTPackage(klass.getPackage()); simpleName = new String(klass.sourceName()); qualifiedName = JDTUtils.getFullyQualifiedName(klass); isPublic = klass.isPublic();/*ww w .j a v a 2 s . c o m*/ isInterface = klass.isInterface(); isAbstract = klass.isAbstract(); isProtected = klass.isProtected(); isDefaultAccess = klass.isDefault(); isLocalType = klass.isLocalType(); isStatic = (klass.modifiers & ClassFileConstants.AccStatic) != 0; isFinal = klass.isFinal(); isEnum = klass.isEnum(); isBinary = klass.isBinaryBinding(); isAnonymous = klass.isAnonymousType(); isJavaSource = (klass instanceof SourceTypeBinding) && new String(((SourceTypeBinding) klass).getFileName()).endsWith(".java"); isAnnotationType = klass.isAnnotationType(); bindingKey = klass.computeUniqueKey(); char[] bindingFileName = klass.getFileName(); int start = CharOperation.lastIndexOf('/', bindingFileName) + 1; if (start == 0 || start < CharOperation.lastIndexOf('\\', bindingFileName)) start = CharOperation.lastIndexOf('\\', bindingFileName) + 1; fileName = new String(CharOperation.subarray(bindingFileName, start, -1)); int jarFileEntrySeparatorIndex = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR, bindingFileName); if (jarFileEntrySeparatorIndex > 0) { char[] jarPart = CharOperation.subarray(bindingFileName, 0, jarFileEntrySeparatorIndex); IJavaElement jarPackageFragmentRoot = JavaCore.create(new String(jarPart)); String jarPath = jarPackageFragmentRoot.getPath().toOSString(); char[] entryPart = CharOperation.subarray(bindingFileName, jarFileEntrySeparatorIndex + 1, bindingFileName.length); fullPath = new StringBuilder(jarPath).append("!/").append(entryPart).toString(); } else { fullPath = new String(bindingFileName); } ReferenceBinding sourceOrClass = klass; if (!klass.isBinaryBinding()) { sourceOrClass = klass.outermostEnclosingType(); } char[] classFullName = new char[0]; for (char[] part : sourceOrClass.compoundName) { classFullName = CharOperation.concat(classFullName, part, '/'); } char[][] temp = CharOperation.splitOn('.', sourceOrClass.getFileName()); String extension = temp.length > 1 ? "." + new String(temp[temp.length - 1]) : ""; javaModelPath = new String(classFullName) + extension; if (type == null) { annotations = new HashMap<>(); methods = Collections.emptyList(); interfaces = Collections.emptyList(); typeParams = Collections.emptyList(); fields = Collections.emptyList(); innerClasses = Collections.emptyList(); } }
From source file:de.hentschel.visualdbc.datasource.ui.test.testCase.swtbot.SWTBotFileOrResourceJavaPackageSettingControlTest.java
License:Open Source License
/** * {@inheritDoc} */ @Override protected Object getExpectedPackage(IJavaElement element) { return element.getPath(); }
From source file:de.ovgu.featureide.core.mpl.job.CreateFujiSignaturesJob.java
License:Open Source License
private static String getClassPaths(IFeatureProject featureProject) { String classpath = ""; String sep = System.getProperty("path.separator"); try {/* w w w . j a v a 2s . c o m*/ JavaProject proj = new JavaProject(featureProject.getProject(), null); IJavaElement[] elements = proj.getChildren(); for (IJavaElement e : elements) { String path = e.getPath().toOSString(); if (path.contains(":")) { classpath += sep + path; continue; } IResource resource = e.getResource(); if (resource != null && "jar".equals(resource.getFileExtension())) { classpath += sep + resource.getRawLocation().toOSString(); } } } catch (JavaModelException e) { } return classpath.length() > 0 ? classpath.substring(1) : classpath; }
From source file:de.ovgu.featureide.ui.actions.generator.ConfigurationBuilder.java
License:Open Source License
/** * Sets the java classPath for compiling. *///from ww w .j av a2 s . c om private void setClassPath() { String sep = System.getProperty("path.separator"); try { JavaProject proj = new JavaProject(featureProject.getProject(), null); IJavaElement[] elements = proj.getChildren(); for (IJavaElement e : elements) { String path = e.getPath().toOSString(); if (path.contains(":")) { classpath += sep + path; continue; } IResource resource = e.getResource(); if (resource != null && "jar".equals(resource.getFileExtension())) { classpath += sep + resource.getRawLocation().toOSString(); } } } catch (JavaModelException e) { } classpath = classpath.length() > 0 ? classpath.substring(1) : classpath; }
From source file:de.ovgu.featureide.ui.actions.generator.TestRunner.java
License:Open Source License
private URL[] getURLs() { ArrayList<URL> urls = new ArrayList<>(); try {//from w w w .ja v a 2 s . c om URL url = tmp.getLocationURI().toURL(); url = new URL(url.toString() + "/"); urls.add(url); JavaProject proj = new JavaProject(tmp.getProject(), null); IJavaElement[] elements = proj.getChildren(); for (IJavaElement e : elements) { String path = e.getPath().toOSString(); if (path.contains(":")) { continue; } IResource resource = e.getResource(); if (resource != null && "jar".equals(resource.getFileExtension())) { urls.add(resource.getRawLocationURI().toURL()); } } } catch (MalformedURLException | JavaModelException e) { UIPlugin.getDefault().logError(e); } return urls.toArray(new URL[urls.size()]); }