本文整理汇总了Java中org.eclipse.jdt.core.IField.getDeclaringType方法的典型用法代码示例。如果您正苦于以下问题:Java IField.getDeclaringType方法的具体用法?Java IField.getDeclaringType怎么用?Java IField.getDeclaringType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IField
的用法示例。
在下文中一共展示了IField.getDeclaringType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateObjectTree
import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private void validateObjectTree(ExpressionReference e, IncludedObject object) throws JavaModelException, ExpressionLanguageException {
IType type = object.getFieldType();
int currentSegment = 1;
if (type != null) {
while (currentSegment < e.getSegmentCount()) {
String name = e.getSegment(currentSegment++);
IField field = type.getField(name);
if (field == null) {
throw new ExpressionLanguageException(name + " not included in " +
controller.getName(), expression.getLocation());
} else {
type = field.getDeclaringType();
}
}
}
}
示例2: getFieldByName
import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public IType getFieldByName(String name) throws JavaModelException {
for (IField field : element.getFields()) {
if (field.getElementName().equals(name)) {
return field.getDeclaringType();
}
}
return null;
}
示例3: adjustOutgoingVisibility
import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
/**
* 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 <code>null</code> 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);
}
示例4: getSetterStub
import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
/**
* Create a stub for a getter of the given field using getter/setter
* templates. The resulting code has to be formatted and indented.
*
* @param field
* The field to create a getter for
* @param setterName
* The chosen name for the setter
* @param addComments
* If <code>true</code>, comments will be added.
* @param flags
* The flags signaling visibility, if static, synchronized or
* final
* @return Returns the generated stub.
* @throws CoreException
* when stub creation failed
*/
public static String getSetterStub(IField field, String setterName, boolean addComments, int flags) throws CoreException {
String fieldName = field.getElementName();
IType parentType = field.getDeclaringType();
String returnSig = field.getTypeSignature();
String typeName = Signature.toString(returnSig);
IJavaProject project = field.getJavaProject();
String accessorName = StubUtility.getBaseName(field);
String argname = StubUtility.suggestArgumentName(project, accessorName, EMPTY);
boolean isStatic = Flags.isStatic(flags);
boolean isSync = Flags.isSynchronized(flags);
boolean isFinal = Flags.isFinal(flags);
String lineDelim = "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$
StringBuffer buf = new StringBuffer();
if (addComments) {
String comment = CodeGeneration.getSetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, field.getElementName(), typeName, argname, accessorName, lineDelim);
if (comment != null) {
buf.append(comment);
}
}
buf.append(JdtFlags.getVisibilityString(flags));
buf.append(' ');
if (isStatic) {
buf.append("static "); //$NON-NLS-1$
}
if (isSync) {
buf.append("synchronized "); //$NON-NLS-1$
}
if (isFinal) {
buf.append("final "); //$NON-NLS-1$
}
buf.append("void "); //$NON-NLS-1$
buf.append(setterName);
buf.append('(');
buf.append(typeName);
buf.append(' ');
buf.append(argname);
buf.append(") {"); //$NON-NLS-1$
buf.append(lineDelim);
if (argname.equals(fieldName) || !isStatic) {
if (isStatic) {
fieldName = parentType.getElementName() + '.' + fieldName;
} else {
fieldName = "this." + fieldName; //$NON-NLS-1$
}
}
String body = CodeGeneration.getSetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, fieldName, argname, lineDelim);
if (body != null) {
buf.append(body);
}
buf.append("}"); //$NON-NLS-1$
return buf.toString();
}
示例5: getGetterStub
import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
/**
* Create a stub for a getter of the given field using getter/setter
* templates. The resulting code has to be formatted and indented.
*
* @param field
* The field to create a getter for
* @param getterName
* The chosen name for the getter
* @param addComments
* If <code>true</code>, comments will be added.
* @param flags
* The flags signaling visibility, if static, synchronized or
* final
* @return Returns the generated stub.
* @throws CoreException
* when stub creation failed
*/
public static String getGetterStub(IField field, String getterName, boolean addComments, int flags) throws CoreException {
String fieldName = field.getElementName();
IType parentType = field.getDeclaringType();
boolean isStatic = Flags.isStatic(flags);
boolean isSync = Flags.isSynchronized(flags);
boolean isFinal = Flags.isFinal(flags);
String typeName = Signature.toString(field.getTypeSignature());
String accessorName = StubUtility.getBaseName(field);
String lineDelim = "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$
StringBuffer buf = new StringBuffer();
if (addComments) {
String comment = CodeGeneration.getGetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, field.getElementName(), typeName, accessorName, lineDelim);
if (comment != null) {
buf.append(comment);
}
}
buf.append(JdtFlags.getVisibilityString(flags));
buf.append(' ');
if (isStatic) {
buf.append("static "); //$NON-NLS-1$
}
if (isSync) {
buf.append("synchronized "); //$NON-NLS-1$
}
if (isFinal) {
buf.append("final "); //$NON-NLS-1$
}
buf.append(typeName);
buf.append(' ');
buf.append(getterName);
buf.append("() {"); //$NON-NLS-1$
buf.append(lineDelim);
String body = CodeGeneration.getGetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, fieldName, lineDelim);
if (body != null) {
buf.append(body);
}
buf.append("}"); //$NON-NLS-1$
return buf.toString();
}
示例6: getGetterStub
import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
/**
* Create a stub for a getter of the given field using getter/setter templates. The resulting code
* has to be formatted and indented.
*
* @param field The field to create a getter for
* @param getterName The chosen name for the getter
* @param addComments If <code>true</code>, comments will be added.
* @param flags The flags signaling visibility, if static, synchronized or final
* @return Returns the generated stub.
* @throws CoreException when stub creation failed
*/
public static String getGetterStub(
IField field, String getterName, boolean addComments, int flags) throws CoreException {
String fieldName = field.getElementName();
IType parentType = field.getDeclaringType();
boolean isStatic = Flags.isStatic(flags);
boolean isSync = Flags.isSynchronized(flags);
boolean isFinal = Flags.isFinal(flags);
String typeName = Signature.toString(field.getTypeSignature());
String accessorName = StubUtility.getBaseName(field);
String lineDelim =
"\n"; // Use default line delimiter, as generated stub has to be formatted anyway
// //$NON-NLS-1$
StringBuffer buf = new StringBuffer();
if (addComments) {
String comment =
CodeGeneration.getGetterComment(
field.getCompilationUnit(),
parentType.getTypeQualifiedName('.'),
getterName,
field.getElementName(),
typeName,
accessorName,
lineDelim);
if (comment != null) {
buf.append(comment);
buf.append(lineDelim);
}
}
buf.append(JdtFlags.getVisibilityString(flags));
buf.append(' ');
if (isStatic) buf.append("static "); // $NON-NLS-1$
if (isSync) buf.append("synchronized "); // $NON-NLS-1$
if (isFinal) buf.append("final "); // $NON-NLS-1$
buf.append(typeName);
buf.append(' ');
buf.append(getterName);
buf.append("() {"); // $NON-NLS-1$
buf.append(lineDelim);
boolean useThis = StubUtility.useThisForFieldAccess(field.getJavaProject());
if (useThis && !isStatic) {
fieldName = "this." + fieldName; // $NON-NLS-1$
}
String body =
CodeGeneration.getGetterMethodBodyContent(
field.getCompilationUnit(),
parentType.getTypeQualifiedName('.'),
getterName,
fieldName,
lineDelim);
if (body != null) {
buf.append(body);
}
buf.append("}"); // $NON-NLS-1$
buf.append(lineDelim);
return buf.toString();
}
示例7: createRefactoringDescriptor
import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
@Override
protected RenameJavaElementDescriptor createRefactoringDescriptor() {
final IField field = getField();
String project = null;
IJavaProject javaProject = field.getJavaProject();
if (javaProject != null) project = javaProject.getElementName();
int flags =
JavaRefactoringDescriptor.JAR_MIGRATION
| JavaRefactoringDescriptor.JAR_REFACTORING
| RefactoringDescriptor.STRUCTURAL_CHANGE;
final IType declaring = field.getDeclaringType();
try {
if (!Flags.isPrivate(declaring.getFlags())) flags |= RefactoringDescriptor.MULTI_CHANGE;
if (declaring.isAnonymous() || declaring.isLocal())
flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final String description =
Messages.format(
RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description_short,
BasicElementLabels.getJavaElementName(fField.getElementName()));
final String header =
Messages.format(
RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description,
new String[] {
BasicElementLabels.getJavaElementName(field.getElementName()),
JavaElementLabels.getElementLabel(
field.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED),
BasicElementLabels.getJavaElementName(getNewElementName())
});
final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
final RenameJavaElementDescriptor descriptor =
RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
IJavaRefactorings.RENAME_ENUM_CONSTANT);
descriptor.setProject(project);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(flags);
descriptor.setJavaElement(field);
descriptor.setNewName(getNewElementName());
descriptor.setUpdateReferences(fUpdateReferences);
descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
return descriptor;
}
示例8: findParent
import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
private TreeElement<IJavaElement, ?> findParent(IField field) {
IType declaringType = field.getDeclaringType();
TreeElement<IJavaElement, ?> parentElt = searchRoot.find(declaringType);
return parentElt;
}