use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class HandleFactory method getJarPkgFragmentRoot.
private PackageFragmentRoot getJarPkgFragmentRoot(IPath jarPath, Object target, IJavaProject[] projects) {
for (int i = 0, projectCount = projects.length; i < projectCount; i++) {
try {
JavaProject javaProject = (JavaProject) projects[i];
IClasspathEntry classpathEnty = javaProject.getClasspathEntryFor(jarPath);
if (classpathEnty != null) {
if (target instanceof IFile) {
// internal jar
return (PackageFragmentRoot) javaProject.getPackageFragmentRoot((IFile) target);
} else {
// external jar
return (PackageFragmentRoot) javaProject.getPackageFragmentRoot0(jarPath);
}
}
} catch (JavaModelException e) {
// JavaModelException from getResolvedClasspath - a problem occurred while accessing project: nothing we can do, ignore
}
}
return null;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class HandleFactory method getPkgFragmentRoot.
/**
* Returns the package fragment root that contains the given resource path.
*/
private PackageFragmentRoot getPkgFragmentRoot(String pathString) {
IPath path = new Path(pathString);
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (int i = 0, max = projects.length; i < max; i++) {
try {
IProject project = projects[i];
if (!project.isAccessible() || !project.hasNature(JavaCore.NATURE_ID))
continue;
IJavaProject javaProject = this.javaModel.getJavaProject(project);
IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
for (int j = 0, rootCount = roots.length; j < rootCount; j++) {
PackageFragmentRoot root = (PackageFragmentRoot) roots[j];
if (root.internalPath().isPrefixOf(path) && !Util.isExcluded(path, root.fullInclusionPatternChars(), root.fullExclusionPatternChars(), false)) {
return root;
}
}
} catch (CoreException e) {
// CoreException from hasNature - should not happen since we check that the project is accessible
// JavaModelException from getPackageFragmentRoots - a problem occured while accessing project: nothing we can do, ignore
}
}
return null;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class ASTNodes method getNodeSource.
/**
* Returns the source of the given node from the location where it was parsed.
* @param node the node to get the source from
* @param extendedRange if set, the extended ranges of the nodes should ne used
* @param removeIndent if set, the indentation is removed.
* @return return the source for the given node or null if accessing the source failed.
*/
public static String getNodeSource(ASTNode node, boolean extendedRange, boolean removeIndent) {
ASTNode root = node.getRoot();
if (root instanceof CompilationUnit) {
CompilationUnit astRoot = (CompilationUnit) root;
ITypeRoot typeRoot = astRoot.getTypeRoot();
try {
if (typeRoot != null && typeRoot.getBuffer() != null) {
IBuffer buffer = typeRoot.getBuffer();
int offset = extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition();
int length = extendedRange ? astRoot.getExtendedLength(node) : node.getLength();
String str = buffer.getText(offset, length);
if (removeIndent) {
IJavaProject project = typeRoot.getJavaProject();
int indent = StubUtility.getIndentUsed(buffer, node.getStartPosition(), project);
str = Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
}
return str;
}
} catch (JavaModelException e) {
// ignore
}
}
return null;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class StubUtility method getFileComment.
/*
* Don't use this method directly, use CodeGeneration.
* @see org.eclipse.jdt.ui.CodeGeneration#getFileComment(ICompilationUnit, String)
*/
public static String getFileComment(ICompilationUnit cu, String lineDelimiter) throws CoreException {
Template template = getCodeTemplate(CodeTemplateContextType.FILECOMMENT_ID, cu.getJavaProject());
if (template == null) {
return null;
}
IJavaProject project = cu.getJavaProject();
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.TYPENAME, JavaCore.removeJavaLikeExtension(cu.getElementName()));
return evaluateTemplate(context, template);
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class RenameLocalVariableProcessor method createRefactoringDescriptor.
private RenameJavaElementDescriptor createRefactoringDescriptor() {
String project = null;
IJavaProject javaProject = fCu.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
final String header = Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fCurrentName), JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(fNewName) });
final String description = Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fCurrentName));
final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
descriptor.setProject(project);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(RefactoringDescriptor.NONE);
descriptor.setJavaElement(fLocalVariable);
descriptor.setNewName(getNewElementName());
descriptor.setUpdateReferences(fUpdateReferences);
return descriptor;
}
Aggregations