use of org.eclipse.jdt.core.IField in project che by eclipse.
the class JavaElementToDtoConverter method getFields.
private List<Field> getFields(Object parent) throws JavaModelException {
List<Field> result = new ArrayList<>();
Set<Object> objects = childrens.get(parent);
if (objects == null) {
return result;
}
for (Object object : objects) {
if (object instanceof IField) {
IField iField = (IField) object;
Field field = DtoFactory.newDto(Field.class);
field.setElementName(iField.getElementName());
field.setHandleIdentifier(iField.getHandleIdentifier());
field.setFlags(iField.getFlags());
field.setLabel(JavaElementLabels.getElementLabel(iField, JavaElementLabels.ALL_DEFAULT));
result.add(field);
}
}
return result;
}
use of org.eclipse.jdt.core.IField in project che by eclipse.
the class JavadocUrlTest method binaryFieldUri.
@Test
public void binaryFieldUri() throws JavaModelException, URISyntaxException, UnsupportedEncodingException {
IType type = project.findType("java.util.ArrayList");
IField field = type.getField("size");
String uri = JavaElementLinks.createURI(urlPart, field);
String handle = uri.substring(urlPart.length());
handle = URLDecoder.decode(handle, "UTF-8");
IJavaElement element = JavaElementLinks.parseURI(handle, project);
assertThat(element).isNotNull().isEqualTo(field);
}
use of org.eclipse.jdt.core.IField in project che by eclipse.
the class StubCreator method appendEnumConstants.
protected void appendEnumConstants(final IType type) throws JavaModelException {
final IField[] fields = type.getFields();
final List<IField> list = new ArrayList<IField>(fields.length);
for (int index = 0; index < fields.length; index++) {
final IField field = fields[index];
if (Flags.isEnum(field.getFlags()))
list.add(field);
}
for (int index = 0; index < list.size(); index++) {
if (index > 0)
//$NON-NLS-1$
fBuffer.append(",");
fBuffer.append(list.get(index).getElementName());
}
//$NON-NLS-1$
fBuffer.append(";");
}
use of org.eclipse.jdt.core.IField in project che by eclipse.
the class StubCreator method appendMembers.
protected void appendMembers(final IType type, final IProgressMonitor monitor) throws JavaModelException {
try {
monitor.beginTask(RefactoringCoreMessages.StubCreationOperation_creating_type_stubs, 1);
final IJavaElement[] children = type.getChildren();
for (int index = 0; index < children.length; index++) {
final IMember child = (IMember) children[index];
final int flags = child.getFlags();
final boolean isPrivate = Flags.isPrivate(flags);
final boolean isDefault = !Flags.isPublic(flags) && !Flags.isProtected(flags) && !isPrivate;
final boolean stub = fStubInvisible || (!isPrivate && !isDefault);
if (child instanceof IType) {
if (stub)
appendTypeDeclaration((IType) child, new SubProgressMonitor(monitor, 1));
} else if (child instanceof IField) {
if (stub && !Flags.isEnum(flags) && !Flags.isSynthetic(flags))
appendFieldDeclaration((IField) child);
} else if (child instanceof IMethod) {
final IMethod method = (IMethod) child;
final String name = method.getElementName();
if (method.getDeclaringType().isEnum()) {
final int count = method.getNumberOfParameters();
if (//$NON-NLS-1$
count == 0 && "values".equals(name))
continue;
if (//$NON-NLS-1$ //$NON-NLS-2$
count == 1 && "valueOf".equals(name) && "Ljava.lang.String;".equals(method.getParameterTypes()[0]))
continue;
if (method.isConstructor())
continue;
}
//$NON-NLS-1$
boolean skip = !stub || name.equals("<clinit>");
if (method.isConstructor())
skip = false;
skip = skip || Flags.isSynthetic(flags) || Flags.isBridge(flags);
if (!skip)
appendMethodDeclaration(method);
}
//$NON-NLS-1$
fBuffer.append("\n");
}
} finally {
monitor.done();
}
}
use of org.eclipse.jdt.core.IField in project che by eclipse.
the class MemberVisibilityAdjustor method adjustIncomingVisibility.
/**
* Adjusts the visibility of the specified member.
*
* @param element the "source" point from which to calculate the visibility
* @param referencedMovedElement the moved element which may be adjusted in visibility
* @param monitor the progress monitor to use
* @throws JavaModelException if the visibility adjustment could not be computed
*/
private void adjustIncomingVisibility(final IJavaElement element, IMember referencedMovedElement, final IProgressMonitor monitor) throws JavaModelException {
final ModifierKeyword threshold = getVisibilityThreshold(element, referencedMovedElement, monitor);
int flags = referencedMovedElement.getFlags();
IType declaring = referencedMovedElement.getDeclaringType();
if (declaring != null && declaring.isInterface() || referencedMovedElement instanceof IField && Flags.isEnum(referencedMovedElement.getFlags()))
return;
if (hasLowerVisibility(flags, threshold == null ? Modifier.NONE : threshold.toFlagValue()) && needsVisibilityAdjustment(referencedMovedElement, threshold))
fAdjustments.put(referencedMovedElement, new IncomingMemberVisibilityAdjustment(referencedMovedElement, threshold, RefactoringStatus.createStatus(fVisibilitySeverity, Messages.format(getMessage(referencedMovedElement), new String[] { getLabel(referencedMovedElement), getLabel(threshold) }), JavaStatusContext.create(referencedMovedElement), null, RefactoringStatusEntry.NO_CODE, null)));
}
Aggregations