本文整理汇总了Java中org.eclipse.jdt.core.IField.getJavaProject方法的典型用法代码示例。如果您正苦于以下问题:Java IField.getJavaProject方法的具体用法?Java IField.getJavaProject怎么用?Java IField.getJavaProject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IField
的用法示例。
在下文中一共展示了IField.getJavaProject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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;
}