本文整理了Java中org.eclipse.jdt.core.IField
类的一些代码示例,展示了IField
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IField
类的具体详情如下:
包路径:org.eclipse.jdt.core.IField
类名称:IField
[英]Represents a field declared in a type.
[中]表示在类型中声明的字段。
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core
private FieldDeclaration convert(IField field, IType type) throws JavaModelException {
TypeReference typeReference = createTypeReference(field.getTypeSignature());
if (typeReference == null) return null;
FieldDeclaration fieldDeclaration = new FieldDeclaration();
fieldDeclaration.name = field.getElementName().toCharArray();
fieldDeclaration.type = typeReference;
fieldDeclaration.modifiers = field.getFlags();
return fieldDeclaration;
}
代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui
/**
* Adjusts the visibility of the referenced field found in a compilation unit.
*
* @param field the referenced field to adjust
* @param threshold the visibility threshold, or null
for default visibility
* @throws JavaModelException if an error occurs
*/
private void adjustOutgoingVisibility(final IField field, final ModifierKeyword threshold) throws JavaModelException {
Assert.isTrue(!field.isBinary() && !field.isReadOnly());
//bug 100555 (moving inner class to top level class; taking private fields with you)
final IType declaring= field.getDeclaringType();
if (declaring != null && declaring.equals(fReferenced)) return;
if (hasLowerVisibility(field.getFlags(), keywordToVisibility(threshold)) && needsVisibilityAdjustment(field, threshold))
adjustOutgoingVisibility(field, threshold, RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_field_warning);
}
代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui
public static boolean isDelegateCreationAvailable(final IField field) throws JavaModelException {
return field.exists() && (Flags.isStatic(field.getFlags()) && Flags.isFinal(field.getFlags()) /*
* &&
* hasInitializer(field)
*/);
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core.manipulation
public static String getSetterName(IField field, String[] excludedNames) throws JavaModelException {
if (excludedNames == null) {
excludedNames= EMPTY;
}
return getSetterName(field.getJavaProject(), field.getElementName(), field.getFlags(), JavaModelUtil.isBoolean(field), excludedNames);
}
代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.jdt.core
IType type = (IType) res;
IField field= type.getField(new String(fieldBinding.name));
if (field.exists()) {
char[] uniqueKey = fieldBinding.computeUniqueKey();
if(field.isBinary()) {
ResolvedBinaryField resolvedField = new ResolvedBinaryField(
(JavaElement)field.getParent(),
field.getElementName(),
new String(uniqueKey));
resolvedField.occurrenceCount = field.getOccurrenceCount();
field = resolvedField;
} else {
ResolvedSourceField resolvedField = new ResolvedSourceField(
(JavaElement)field.getParent(),
field.getElementName(),
new String(uniqueKey));
resolvedField.occurrenceCount = field.getOccurrenceCount();
field = resolvedField;
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
protected String getKey(IField field, boolean forceOpen) throws JavaModelException {
StringBuffer key = new StringBuffer();
// declaring class
String declaringKey = getKey((IType) field.getParent(), forceOpen);
key.append(declaringKey);
// field name
key.append('.');
key.append(field.getElementName());
return key.toString();
}
代码示例来源:origin: eclipse/eclipse.jdt.ls
try {
if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) {
if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) {
appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags);
} else {
appendTypeSignatureLabel(field, field.getTypeSignature(), flags);
appendTypeLabel(field.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
fBuilder.append('.');
if (getFlag(flags, JavaElementLabels.F_APP_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) {
fBuilder.append(JavaElementLabels.DECL_STRING);
if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) {
appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags);
} else {
appendTypeSignatureLabel(field, field.getTypeSignature(), flags);
appendTypeLabel(field.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
代码示例来源:origin: eclipse/eclipse.jdt.ls
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
if (fVisibility <0) {
fVisibility = (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate));
}
RefactoringStatus result = new RefactoringStatus();
result.merge(Checks.checkAvailability(fField));
if (result.hasFatalError()) {
return result;
}
fRoot = new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(fField.getCompilationUnit(), true, pm);
ISourceRange sourceRange = fField.getNameRange();
ASTNode node = NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength());
if (node == null) {
return mappingErrorFound(result, node);
}
fFieldDeclaration = ASTNodes.getParent(node, VariableDeclarationFragment.class);
if (fFieldDeclaration == null) {
return mappingErrorFound(result, node);
}
if (fFieldDeclaration.resolveBinding() == null) {
if (!processCompilerError(result, node)) {
result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable);
}
return result;
}
computeUsedNames();
return result;
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
/**
* Generates a new setter method for the specified field
*
* @param field the field
* @param astRewrite the AST rewrite to use
* @param rewrite the list rewrite to use
* @throws CoreException if an error occurs
* @throws OperationCanceledException if the operation has been cancelled
*/
private void generateSetterMethod(final IField field, ASTRewrite astRewrite, final ListRewrite rewrite) throws CoreException, OperationCanceledException {
final IType type= field.getDeclaringType();
final String name= GetterSetterUtil.getSetterName(field, null);
final IMethod existing= JavaModelUtil.findMethod(name, new String[] { field.getTypeSignature()}, false, type);
if (existing == null || !querySkipExistingMethods(existing)) {
IJavaElement sibling= null;
if (existing != null) {
sibling= StubUtility.findNextSibling(existing);
removeExistingAccessor(existing, rewrite);
} else
sibling= fInsert;
ASTNode insertion= StubUtility2Core.getNodeToInsertBefore(rewrite, sibling);
addNewAccessor(type, field, GetterSetterUtil.getSetterStub(field, name, fSettings.createComments, fVisibility | (field.getFlags() & Flags.AccStatic)), rewrite, insertion);
if (Flags.isFinal(field.getFlags())) {
FieldDeclaration fieldDecl= ASTNodes.getParent(NodeFinder.perform(fASTRoot, field.getNameRange()), FieldDeclaration.class);
if (fieldDecl != null) {
ModifierRewrite.create(astRewrite, fieldDecl).setModifiers(0, Modifier.FINAL, null);
}
}
}
}
代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui
public String getNewGetterName() throws CoreException {
IMethod primaryGetterCandidate= JavaModelUtil.findMethod(GetterSetterUtil.getGetterName(fField, new String[0]), new String[0], false, fField.getDeclaringType());
if (! JavaModelUtil.isBoolean(fField) || (primaryGetterCandidate != null && primaryGetterCandidate.exists()))
return GetterSetterUtil.getGetterName(fField.getJavaProject(), getNewElementName(), fField.getFlags(), JavaModelUtil.isBoolean(fField), null);
//bug 30906 describes why we need to look for other alternatives here
return GetterSetterUtil.getGetterName(fField.getJavaProject(), getNewElementName(), fField.getFlags(), false, null);
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core.manipulation
/**
* Creates {@link Field} objects for all instance fields of the type
*
* @param type the type declaring the field that will be moved to the extracted class
* @return an instance of {@link Field} for every field declared in type that is not static
* @throws JavaModelException if the type does not exist or if an exception occurs while accessing its corresponding resource.
*/
public static Field[] getFields(IType type) throws JavaModelException {
IField[] fields= type.getFields();
ArrayList
for (int i= 0; i
if (!Flags.isStatic(field.getFlags()) && !field.isEnumConstant())
result.add(new Field(field.getElementName()));
}
return result.toArray(new Field[result.size()]);
}
代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui
private static void checkFieldInType(IType destinationType, RefactoringStatus result, IField field) throws JavaModelException {
IField destinatiOnTypeField= destinationType.getField(field.getElementName());
if (! destinationTypeField.exists())
return;
String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_field_exists,
new String[]{field.getElementName(), JavaModelUtil.getFullyQualifiedName(destinationType)});
RefactoringStatusContext cOntext= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationTypeField.getSourceRange());
result.addError(message, context);
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
private void addDeclarationUpdate() throws CoreException {
ISourceRange nameRange= fField.getNameRange();
TextEdit textEdit= new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName());
ICompilationUnit cu= fField.getCompilationUnit();
String groupName= RefactoringCoreMessages.RenameFieldRefactoring_Update_field_declaration;
addTextEdit(fChangeManager.get(cu), groupName, textEdit);
}
代码示例来源:origin: org.eclipse.recommenders.completion.rcp/calls
@JavaSelectionSubscriber(METHOD_BODY)
public Status onFieldSelection(final IField var, final JavaSelectionEvent event, final Composite parent)
throws JavaModelException {
return handle(var, var.getElementName(), var.getTypeSignature(), event, parent);
}
代码示例来源:origin: org.eclipse.recommenders.completion/rcp
@Override
public Optional
final IJavaElement enclosing = getEnclosingElement().orNull();
if (enclosing instanceof IType) {
return of((IType) enclosing);
} else if (enclosing instanceof IField) {
return of(((IField) enclosing).getDeclaringType());
} else {
return absent();
}
}
代码示例来源:origin: eclipse/eclipse.jdt.ls
private void checkArgName() {
String fieldName = fField.getElementName();
boolean isStatic = true;
try {
isStatic = JdtFlags.isStatic(fField);
} catch (JavaModelException e) {
JavaLanguageServerPlugin.log(e);
}
if ((isStatic && fArgName.equals(fieldName) && fieldName.equals(fField.getDeclaringType().getElementName())) || JavaConventionsUtil.validateIdentifier(fArgName, fField).getSeverity() == IStatus.ERROR) {
fArgName = "_" + fArgName; //$NON-NLS-1$
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
private FieldInfo(ParameterInfo parameterInfo, IField ifield) {
super();
this.pi= parameterInfo;
this.ifield= ifield;
this.name= ifield.getElementName();
}
}
代码示例来源:origin: eclipse/eclipse.jdt.ls
@Override
public RefactoringStatus checkNewElementName(String newName) throws CoreException {
RefactoringStatus result= Checks.checkEnumConstantName(newName, getField());
if (Checks.isAlreadyNamed(getField(), newName)) {
result.addFatalError(RefactoringCoreMessages.RenameEnumConstRefactoring_another_name);
}
if (getField().getDeclaringType().getField(newName).exists()) {
result.addFatalError(RefactoringCoreMessages.RenameEnumConstRefactoring_const_already_defined);
}
return result;
}
代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui
/**
* Checks if the field is boolean.
*/
public static boolean isBoolean(IField field) throws JavaModelException{
return field.getTypeSignature().equals(Signature.SIG_BOOLEAN);
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
private boolean isEnumConstant(IMember member) throws JavaModelException {
return (member.getElementType() == IJavaElement.FIELD) && ((IField)member).isEnumConstant();
}
}