use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class JavaNavigation method getAllProjectsAndPackages.
public List<JavaProject> getAllProjectsAndPackages(boolean includePackages) throws JavaModelException {
JavaModel javaModel = JavaModelManager.getJavaModelManager().getJavaModel();
IJavaProject[] javaProjects = javaModel.getJavaProjects();
List<JavaProject> result = new ArrayList<>();
for (IJavaProject javaProject : javaProjects) {
if (javaProject.exists()) {
JavaProject project = DtoFactory.newDto(JavaProject.class);
project.setName(javaProject.getElementName());
project.setPath(javaProject.getPath().toOSString());
project.setPackageFragmentRoots(toPackageRoots(javaProject, includePackages));
result.add(project);
}
}
return result;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class WorkspaceTest method testWsShouldAddSourceFolderFromBuildHelperPlugin.
@Test
public void testWsShouldAddSourceFolderFromBuildHelperPlugin() throws Exception {
String pom = "<groupId>test</groupId>\n" + "<artifactId>testArtifact</artifactId>\n" + "<version>42</version>\n" + "<properties>\n" + " <dto-generator-out-directory>${project.build.directory}/generated-sources/dto/</dto-generator-out-directory>\n" + "</properties>\n" + "<dependencies>\n" + " <dependency>\n" + " <groupId>junit</groupId>\n" + " <artifactId>junit</artifactId>\n" + " <version>4.12</version>\n" + " </dependency>\n" + "</dependencies>\n" + "<build>\n" + " <plugins>\n" + " <plugin>\n" + " <groupId>org.codehaus.mojo</groupId>\n" + " <artifactId>build-helper-maven-plugin</artifactId>\n" + " <executions>\n" + " <execution>\n" + " <id>add-source</id>\n" + " <phase>process-sources</phase>\n" + " <goals>\n" + " <goal>add-source</goal>\n" + " </goals>\n" + " <configuration>\n" + " <sources>\n" + " <source>${dto-generator-out-directory}</source>\n" + " </sources>\n" + " </configuration>\n" + " </execution>\n" + " <execution>\n" + " <id>add-test-source</id>\n" + " <phase>generate-sources</phase>\n" + " <goals>\n" + " <goal>add-test-source</goal>\n" + " </goals>\n" + " <configuration>\n" + " <sources>\n" + " <source>${dto-generator-out-directory}src-gen/test/java</source>\n" + " </sources>\n" + " </configuration>\n" + " </execution>" + " </executions>\n" + " </plugin>\n" + " </plugins>\n" + "</build>";
createTestProject("test", pom);
IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
mavenWorkspace.update(Collections.singletonList(test));
mavenWorkspace.waitForUpdate();
IJavaProject javaProject = JavaCore.create(test);
IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
assertThat(rawClasspath).onProperty("path").contains(new Path("/test/target/generated-sources/dto/"));
//attributes should be updated
List<String> sourceFolders = projectRegistry.getProject("test").getAttributes().get(Constants.SOURCE_FOLDER);
List<String> testSourceFolders = projectRegistry.getProject("test").getAttributes().get(TEST_SOURCE_FOLDER);
assertEquals(2, sourceFolders.size());
assertThat(sourceFolders, hasItems("src/main/java", "target/generated-sources/dto/"));
assertEquals(2, testSourceFolders.size());
assertThat(testSourceFolders, hasItems("src/test/java", "target/generated-sources/dto/src-gen/test/java"));
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class JavaDebuggerUtils method findFqnByPosition.
/**
* Return nested class fqn if line with number {@code lineNumber} contains such element, otherwise return outer class fqn.
*
* @param projectPath
* project path which contains class with {@code outerClassFqn}
* @param outerClassFqn
* fqn outer class
* @param lineNumber
* line position to search
* @throws DebuggerException
*/
public String findFqnByPosition(String projectPath, String outerClassFqn, int lineNumber) throws DebuggerException {
if (projectPath == null) {
return outerClassFqn;
}
IJavaProject project = MODEL.getJavaProject(projectPath);
IType outerClass;
IMember iMember;
try {
outerClass = project.findType(outerClassFqn);
if (outerClass == null) {
return outerClassFqn;
}
String source;
if (outerClass.isBinary()) {
IClassFile classFile = outerClass.getClassFile();
source = classFile.getSource();
} else {
ICompilationUnit unit = outerClass.getCompilationUnit();
source = unit.getSource();
}
Document document = new Document(source);
IRegion region = document.getLineInformation(lineNumber);
int start = region.getOffset();
int end = start + region.getLength();
iMember = binSearch(outerClass, start, end);
} catch (JavaModelException e) {
throw new DebuggerException(format("Unable to find source for class with fqn '%s' in the project '%s'", outerClassFqn, project), e);
} catch (BadLocationException e) {
throw new DebuggerException("Unable to calculate breakpoint location", e);
}
if (iMember instanceof IType) {
return ((IType) iMember).getFullyQualifiedName();
}
if (iMember != null) {
return iMember.getDeclaringType().getFullyQualifiedName();
}
return outerClassFqn;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class ChangeSignatureProcessor method createDescriptor.
public JavaRefactoringDescriptor createDescriptor() {
final Map<String, String> arguments = new HashMap<String, String>();
String project = null;
IJavaProject javaProject = fMethod.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
ChangeMethodSignatureDescriptor descriptor = null;
try {
final String description = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fMethod.getElementName()));
final String header = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_descriptor_description, new String[] { getOldMethodSignature(), getNewMethodSignature() });
final JDTRefactoringDescriptorComment comment = createComment(project, header);
descriptor = RefactoringSignatureDescriptorFactory.createChangeMethodSignatureDescriptor(project, description, comment.asString(), arguments, getDescriptorFlags());
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fMethod));
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fMethodName);
arguments.put(ATTRIBUTE_DELEGATE, Boolean.valueOf(fDelegateUpdating).toString());
arguments.put(ATTRIBUTE_DEPRECATE, Boolean.valueOf(fDelegateDeprecation).toString());
if (fReturnTypeInfo.isTypeNameChanged())
arguments.put(ATTRIBUTE_RETURN, fReturnTypeInfo.getNewTypeName());
try {
if (!isVisibilitySameAsInitial())
arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
int count = 1;
for (final Iterator<ParameterInfo> iterator = fParameterInfos.iterator(); iterator.hasNext(); ) {
final ParameterInfo info = iterator.next();
final StringBuffer buffer = new StringBuffer(64);
if (info.isAdded())
//$NON-NLS-1$
buffer.append("{added}");
else
buffer.append(info.getOldTypeName());
//$NON-NLS-1$
buffer.append(" ");
if (info.isAdded())
//$NON-NLS-1$
buffer.append("{added}");
else
buffer.append(info.getOldName());
//$NON-NLS-1$
buffer.append(" ");
buffer.append(info.getOldIndex());
//$NON-NLS-1$
buffer.append(" ");
if (info.isDeleted())
//$NON-NLS-1$
buffer.append("{deleted}");
else
//$NON-NLS-1$//$NON-NLS-2$
buffer.append(info.getNewTypeName().replaceAll(" ", ""));
//$NON-NLS-1$
buffer.append(" ");
if (info.isDeleted())
//$NON-NLS-1$
buffer.append("{deleted}");
else
buffer.append(info.getNewName());
//$NON-NLS-1$
buffer.append(" ");
buffer.append(info.isDeleted());
arguments.put(ATTRIBUTE_PARAMETER + count, buffer.toString());
final String value = info.getDefaultValue();
if (//$NON-NLS-1$
value != null && !"".equals(value))
arguments.put(ATTRIBUTE_DEFAULT + count, value);
count++;
}
count = 1;
for (final Iterator<ExceptionInfo> iterator = fExceptionInfos.iterator(); iterator.hasNext(); ) {
final ExceptionInfo info = iterator.next();
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count, JavaRefactoringDescriptorUtil.elementToHandle(project, info.getElement()));
arguments.put(ATTRIBUTE_KIND + count, new Integer(info.getKind()).toString());
count++;
}
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
return null;
}
return descriptor;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class SelfEncapsulateFieldRefactoring method createChange.
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
final Map<String, String> arguments = new HashMap<String, String>();
String project = null;
IJavaProject javaProject = fField.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
final IType declaring = fField.getDeclaringType();
try {
if (declaring.isAnonymous() || declaring.isLocal())
flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final String description = Messages.format(RefactoringCoreMessages.SelfEncapsulateField_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
final String header = Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED) });
final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_original_pattern, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED)));
comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_getter_pattern, BasicElementLabels.getJavaElementName(fGetterName)));
comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_setter_pattern, BasicElementLabels.getJavaElementName(fSetterName)));
String visibility = JdtFlags.getVisibilityString(fVisibility);
if (//$NON-NLS-1$
"".equals(visibility))
visibility = RefactoringCoreMessages.SelfEncapsulateField_default_visibility;
comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_visibility_pattern, visibility));
if (fEncapsulateDeclaringClass)
comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_use_accessors);
else
comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_do_not_use_accessors);
if (fGenerateJavadoc)
comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_generate_comments);
final EncapsulateFieldDescriptor descriptor = RefactoringSignatureDescriptorFactory.createEncapsulateFieldDescriptor(project, description, comment.asString(), arguments, flags);
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fField));
arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
arguments.put(ATTRIBUTE_INSERTION, new Integer(fInsertionIndex).toString());
arguments.put(ATTRIBUTE_SETTER, fSetterName);
arguments.put(ATTRIBUTE_GETTER, fGetterName);
arguments.put(ATTRIBUTE_COMMENTS, Boolean.valueOf(fGenerateJavadoc).toString());
arguments.put(ATTRIBUTE_DECLARING, Boolean.valueOf(fEncapsulateDeclaringClass).toString());
final DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, getName());
TextChange[] changes = fChangeManager.getAllChanges();
pm.beginTask(NO_NAME, changes.length);
pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_create_changes);
for (int i = 0; i < changes.length; i++) {
result.add(changes[i]);
pm.worked(1);
}
pm.done();
return result;
}
Aggregations