Java Code Examples for org.eclipse.jdt.core.IType#getField()

The following examples show how to use org.eclipse.jdt.core.IType#getField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenameFieldProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private RefactoringStatus checkEnclosingHierarchy() {
	IType current= fField.getDeclaringType();
	if (Checks.isTopLevel(current)) {
		return null;
	}
	RefactoringStatus result= new RefactoringStatus();
	while (current != null){
		IField otherField= current.getField(getNewElementName());
		if (otherField.exists()){
			String msg= Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_hiding2,
			 	new String[]{ BasicElementLabels.getJavaElementName(getNewElementName()), BasicElementLabels.getJavaElementName(current.getFullyQualifiedName('.')), BasicElementLabels.getJavaElementName(otherField.getElementName())});
			result.addWarning(msg, JavaStatusContext.create(otherField));
		}
		current= current.getDeclaringType();
	}
	return result;
}
 
Example 2
Source File: RenameFieldProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkEnclosingHierarchy() {
	IType current= fField.getDeclaringType();
	if (Checks.isTopLevel(current))
		return null;
	RefactoringStatus result= new RefactoringStatus();
	while (current != null){
		IField otherField= current.getField(getNewElementName());
		if (otherField.exists()){
			String msg= Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_hiding2,
			 	new String[]{ BasicElementLabels.getJavaElementName(getNewElementName()), BasicElementLabels.getJavaElementName(current.getFullyQualifiedName('.')), BasicElementLabels.getJavaElementName(otherField.getElementName())});
			result.addWarning(msg, JavaStatusContext.create(otherField));
		}
		current= current.getDeclaringType();
	}
	return result;
}
 
Example 3
Source File: MethodContentGenerations.java    From jenerate with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a transient field with a certain name and type in the {@link IType} objectClass. It checks first if the
 * cache property allows this field to be created. If the field with the same name exists, it is deleted prior to
 * the new field creation.
 * 
 * @param objectClass the {@link IType} where the field will be created
 * @param data the data used for the code generation
 * @param cacheProperty {@code true} if the field caching is allowed, {@code false} otherwise.
 * @param cachingFieldName the name of the field to be created
 * @param cachingFieldType the type of the field to be created
 * @return {@code true} if the field was created, {@code false} otherwise
 * @throws JavaModelException if a problem occurs during the code generation.
 */
public static boolean createField(IType objectClass, MethodGenerationData data, boolean cacheProperty,
        String cachingFieldName, Class<?> cachingFieldType) throws JavaModelException {
    IField field = objectClass.getField(cachingFieldName);
    if (field.exists()) {
        field.delete(true, null);
    }
    boolean isCacheable = cacheProperty && areAllFinalFields(data.getCheckedFields());
    if (isCacheable) {
        IJavaElement currentPosition = data.getElementPosition();
        String fieldSrc = "private transient " + cachingFieldType.getSimpleName() + " " + cachingFieldName
                + ";\n\n";
        objectClass.createField(fieldSrc, currentPosition, true, null);
    }
    return isCacheable;
}
 
Example 4
Source File: FieldProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves the member described by the receiver and returns it if found.
 * Returns <code>null</code> if no corresponding member can be found.
 *
 * @return the resolved member or <code>null</code> if none is found
 * @throws JavaModelException if accessing the java model fails
 */
@Override
protected IMember resolveMember() throws JavaModelException {
	char[] declarationSignature= fProposal.getDeclarationSignature();
	// for synthetic fields on arrays, declaration signatures may be null
	// TODO remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=84690 gets fixed
	if (declarationSignature == null)
		return null;
	String typeName= SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature));
	IType type= fJavaProject.findType(typeName);
	if (type != null) {
		String name= String.valueOf(fProposal.getName());
		IField field= type.getField(name);
		if (field.exists())
			return field;
	}

	return null;
}
 
Example 5
Source File: RenameTypeWizardSimilarElementsPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IStatus validateSettings() {
	final String name= fNameField.getText();
	if (name.length() == 0) {
		return new StatusInfo(IStatus.ERROR, RefactoringMessages.RenameTypeWizardSimilarElementsPage_name_empty);
	}
	IStatus status= JavaConventionsUtil.validateIdentifier(name, fElementToEdit);
	if (status.matches(IStatus.ERROR))
		return status;
	if (!Checks.startsWithLowerCase(name))
		return new StatusInfo(IStatus.WARNING, RefactoringMessages.RenameTypeWizardSimilarElementsPage_name_should_start_lowercase);

	if (fElementToEdit instanceof IMember && ((IMember) fElementToEdit).getDeclaringType() != null) {
		IType type= ((IMember) fElementToEdit).getDeclaringType();
		if (fElementToEdit instanceof IField) {
			final IField f= type.getField(name);
			if (f.exists())
				return new StatusInfo(IStatus.ERROR, RefactoringMessages.RenameTypeWizardSimilarElementsPage_field_exists);
		}
		if (fElementToEdit instanceof IMethod) {
			final IMethod m= type.getMethod(name, ((IMethod) fElementToEdit).getParameterTypes());
			if (m.exists())
				return new StatusInfo(IStatus.ERROR, RefactoringMessages.RenameTypeWizardSimilarElementsPage_method_exists);
		}
	}

	// cannot check local variables; no .getLocalVariable(String) in IMember

	return StatusInfo.OK_STATUS;
}
 
Example 6
Source File: Binding2JavaModel.java    From lapse-plus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts the given <code>IVariableBinding</code> into a <code>IField</code>
 * using the classpath defined by the given Java project. Returns <code>null</code>
 * if the conversion isn't possible.
 */
public static IField find(IVariableBinding field, IJavaProject in) throws JavaModelException {
    IType declaringClass = find(field.getDeclaringClass(), in);
    if (declaringClass == null)
        return null;
    IField foundField= declaringClass.getField(field.getName());
    if (! foundField.exists())
        return null;
    return foundField;
}
 
Example 7
Source File: RenameFieldProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IField getFieldInWorkingCopy(ICompilationUnit newWorkingCopyOfDeclaringCu, String elementName) {
	IType type= fField.getDeclaringType();
	IType typeWc= (IType) JavaModelUtil.findInCompilationUnit(newWorkingCopyOfDeclaringCu, type);
	if (typeWc == null)
		return null;

	return typeWc.getField(elementName);
}
 
Example 8
Source File: PotentialProgrammingProblemsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void collectChildrenWithMissingSerialVersionId(IJavaElement[] children, IType serializable, List<IType> result) throws JavaModelException {
	for (int i= 0; i < children.length; i++) {
		IJavaElement child= children[i];
		if (child instanceof IType) {
			IType type= (IType)child;

			if (type.isClass()) {
  					IField field= type.getField(NAME_FIELD);
  					if (!field.exists()) {
  						ITypeHierarchy hierarchy= type.newSupertypeHierarchy(new NullProgressMonitor());
  						IType[] interfaces= hierarchy.getAllSuperInterfaces(type);
  						for (int j= 0; j < interfaces.length; j++) {
  							if (interfaces[j].equals(serializable)) {
  								result.add(type);
  								break;
  							}
  						}
				}
			}

			collectChildrenWithMissingSerialVersionId(type.getChildren(), serializable, result);
		} else if (child instanceof IMethod) {
			collectChildrenWithMissingSerialVersionId(((IMethod)child).getChildren(), serializable, result);
		} else if (child instanceof IField) {
			collectChildrenWithMissingSerialVersionId(((IField)child).getChildren(), serializable, result);
		}
	}
}
 
Example 9
Source File: ExtractClassRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
	RefactoringStatus result= new RefactoringStatus();
	pm.beginTask(RefactoringCoreMessages.ExtractClassRefactoring_progress_msg_check_initial_condition, 5);
	try {
		result.merge(fDescriptor.validateDescriptor());
		if (!result.isOK())
			return result;
		IType type= fDescriptor.getType();
		result.merge(Checks.checkAvailability(type));
		if (!result.isOK())
			return result;
		pm.worked(1);
		Field[] fields= ExtractClassDescriptor.getFields(fDescriptor.getType());
		pm.worked(1);
		if (pm.isCanceled())
			throw new OperationCanceledException();
		fVariables= new LinkedHashMap<String, FieldInfo>();
		if (fields.length == 0) {
			result.addFatalError(RefactoringCoreMessages.ExtractClassRefactoring_error_no_usable_fields, JavaStatusContext.create(type));
			return result;
		}
		for (int i= 0; i < fields.length; i++) {
			Field field= fields[i];
			String fieldName= field.getFieldName();
			IField declField= type.getField(fieldName);
			ParameterInfo info= new ParameterInfo(Signature.toString(declField.getTypeSignature()), fieldName, i);
			fVariables.put(fieldName, new FieldInfo(info, declField));
			if (pm.isCanceled())
				throw new OperationCanceledException();
		}
		pm.worked(3);
	} finally {
		pm.done();
	}
	return result;
}
 
Example 10
Source File: GWTMemberRefactoringSupportTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void testGetEditDescriptionForField() {
  GWTMemberRefactoringSupport support = new GWTMemberRefactoringSupport();

  IType refactorTest = refactorTestClass.getCompilationUnit().getType(
      "RefactorTest");
  IField field = refactorTest.getField("counter");
  support.setOldElement(field);
  assertEquals("Update field reference", support.getEditDescription());
}
 
Example 11
Source File: JavaQueryParticipantTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void testElementSearch() throws CoreException {
  IType cu1Type = getTestType1();
  IJavaElement element;

  // Search for type references
  element = cu1Type;
  Match[] expected = new Match[] {
      createWindowsTestMatch(665, 41), createWindowsTestMatch(735, 41),
      createWindowsTestMatch(840, 41), createWindowsTestMatch(947, 41),
      createWindowsTestMatch(1125, 41), createWindowsTestMatch(1207, 41),
      createWindowsTestMatch(1297, 41), createWindowsTestMatch(1419, 41),
      createWindowsTestMatch(1545, 41), createWindowsTestMatch(1619, 41)};
  assertSearchMatches(expected, createQuery(element));

  // Search for field references
  element = cu1Type.getField("keith");
  assertSearchMatch(createWindowsTestMatch(990, 5), createQuery(element));

  // Search for method references
  element = cu1Type.getMethod("getNumber", NO_PARAMS);
  assertSearchMatch(createWindowsTestMatch(1588, 9), createQuery(element));

  // Search for constructor references
  element = cu1Type.getType("InnerSub").getMethod("InnerSub",
      new String[] {"QString;"});
  assertSearchMatch(createWindowsTestMatch(892, 3), createQuery(element));

  // Search for package references (unsupported)
  element = cu1Type.getPackageFragment();
  assertSearchMatches(NO_MATCHES, createQuery(element));
}
 
Example 12
Source File: PotentialProgrammingProblemsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addTypes(IType[] allSubtypes, HashSet<ICompilationUnit> cus, List<IType> types) throws JavaModelException {
	for (int i= 0; i < allSubtypes.length; i++) {
		IType type= allSubtypes[i];

		IField field= type.getField(NAME_FIELD);
		if (!field.exists()) {
			if (type.isClass() && cus.contains(type.getCompilationUnit())){
				types.add(type);
			}
		}
	}
}
 
Example 13
Source File: SourceMapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see ISourceElementRequestor
 */
public void enterField(FieldInfo fieldInfo) {
	if (this.typeDepth >= 0) {
		this.memberDeclarationStart[this.typeDepth] = fieldInfo.declarationStart;
		this.memberNameRange[this.typeDepth] =
			new SourceRange(fieldInfo.nameSourceStart, fieldInfo.nameSourceEnd - fieldInfo.nameSourceStart + 1);
		String fieldName = new String(fieldInfo.name);
		this.memberName[this.typeDepth] = fieldName;

		// categories
		IType currentType = this.types[this.typeDepth];
		IField field = currentType.getField(fieldName);
		addCategories(field, fieldInfo.categories);
	}
}
 
Example 14
Source File: RenameFieldProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private IField getFieldInWorkingCopy(ICompilationUnit newWorkingCopyOfDeclaringCu, String elementName) {
	IType type= fField.getDeclaringType();
	IType typeWc= (IType) JavaModelUtil.findInCompilationUnit(newWorkingCopyOfDeclaringCu, type);
	if (typeWc == null) {
		return null;
	}

	return typeWc.getField(elementName);
}
 
Example 15
Source File: JavaElementFinder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IJavaElement caseJvmField(JvmField object) {
	IJavaElement parent = getDeclaringTypeElement(object);
	if (parent instanceof IType) {
		IType type = (IType) parent;
		IField result = type.getField(object.getSimpleName());
		if (result != null)
			return result;
	}
	return (isExactMatchOnly) ? null : parent;
}
 
Example 16
Source File: HandleFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create handle by adding child to parent obtained by recursing into parent scopes.
 */
public IJavaElement createElement(Scope scope, int elementPosition, ICompilationUnit unit, HashSet existingElements, HashMap knownScopes) {
	IJavaElement newElement = (IJavaElement)knownScopes.get(scope);
	if (newElement != null) return newElement;

	switch(scope.kind) {
		case Scope.COMPILATION_UNIT_SCOPE :
			newElement = unit;
			break;
		case Scope.CLASS_SCOPE :
			IJavaElement parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
			switch (parentElement.getElementType()) {
				case IJavaElement.COMPILATION_UNIT :
					newElement = ((ICompilationUnit)parentElement).getType(new String(scope.enclosingSourceType().sourceName));
					break;
				case IJavaElement.TYPE :
					newElement = ((IType)parentElement).getType(new String(scope.enclosingSourceType().sourceName));
					break;
				case IJavaElement.FIELD :
				case IJavaElement.INITIALIZER :
				case IJavaElement.METHOD :
				    IMember member = (IMember)parentElement;
				    if (member.isBinary()) {
				        return null;
				    } else {
						newElement = member.getType(new String(scope.enclosingSourceType().sourceName), 1);
						// increment occurrence count if collision is detected
						if (newElement != null) {
							while (!existingElements.add(newElement)) ((SourceRefElement)newElement).occurrenceCount++;
						}
				    }
					break;
			}
			if (newElement != null) {
				knownScopes.put(scope, newElement);
			}
			break;
		case Scope.METHOD_SCOPE :
			if (scope.isLambdaScope()) {
				parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
				LambdaExpression expression = (LambdaExpression) scope.originalReferenceContext();
				if (expression.resolvedType != null && expression.resolvedType.isValidBinding() && 
						!(expression.descriptor instanceof ProblemMethodBinding)) { // chain in lambda element only if resolved properly.
					//newElement = new org.eclipse.jdt.internal.core.SourceLambdaExpression((JavaElement) parentElement, expression).getMethod();
					newElement = LambdaFactory.createLambdaExpression((JavaElement) parentElement, expression).getMethod();
					knownScopes.put(scope, newElement);
					return newElement;
				}
				return parentElement;
			}
			IType parentType = (IType) createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
			MethodScope methodScope = (MethodScope) scope;
			if (methodScope.isInsideInitializer()) {
				// inside field or initializer, must find proper one
				TypeDeclaration type = methodScope.referenceType();
				int occurenceCount = 1;
				int length = type.fields == null ? 0 : type.fields.length;
				for (int i = 0; i < length; i++) {
					FieldDeclaration field = type.fields[i];
					if (field.declarationSourceStart <= elementPosition && elementPosition <= field.declarationSourceEnd) {
						switch (field.getKind()) {
							case AbstractVariableDeclaration.FIELD :
							case AbstractVariableDeclaration.ENUM_CONSTANT :
								newElement = parentType.getField(new String(field.name));
								break;
							case AbstractVariableDeclaration.INITIALIZER :
								newElement = parentType.getInitializer(occurenceCount);
								break;
						}
						break;
					} else if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) {
						occurenceCount++;
					}
				}
			} else {
				// method element
				AbstractMethodDeclaration method = methodScope.referenceMethod();
				newElement = parentType.getMethod(new String(method.selector), Util.typeParameterSignatures(method));
				if (newElement != null) {
					knownScopes.put(scope, newElement);
				}
			}
			break;
		case Scope.BLOCK_SCOPE :
			// standard block, no element per se
			newElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
			break;
	}
	return newElement;
}
 
Example 17
Source File: GenerateGetterAndSetterTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Test generation for more than one field
 * @throws Exception
 */
@Test
public void test5() throws Exception {
	createNewType("q.Other");
	/* @formatter:off */
	ICompilationUnit b= fPackageP.createCompilationUnit("B.java", "package p;\r\n" +
			"\r\n" +
			"import q.Other;\r\n" +
			"\r\n" +
			"public class B {\r\n" +
			"\r\n" +
			"	private String a;\r\n" +
			"	private String b;\r\n" +
			"	protected Other c;\r\n" +
			"	public String d;\r\n" +
			"}", true, null);
	/* @formatter:on */

	IType classB= b.getType("B");
	IField field1= classB.getField("a");
	IField field2= classB.getField("b");
	IField field3= classB.getField("c");
	IField field4= classB.getField("d");
	runAndApplyOperation(classB);

	/* @formatter:off */
	String expected= "public class B {\r\n" +
					"\r\n" +
					"	private String a;\r\n" +
					"	private String b;\r\n" +
					"	protected Other c;\r\n" +
					"	public String d;\r\n" +
					"	/**\r\n" +
					"	 * @return Returns the a.\r\n" +
					"	 */\r\n" +
					"	public String getA() {\r\n" +
					"		return a;\r\n" +
					"	}\r\n" +
					"	/**\r\n" +
					"	 * @param a The a to set.\r\n" +
					"	 */\r\n" +
					"	public void setA(String a) {\r\n" +
					"		this.a = a;\r\n" +
					"	}\r\n" +
					"	/**\r\n" +
					"	 * @return Returns the b.\r\n" +
					"	 */\r\n" +
					"	public String getB() {\r\n" +
					"		return b;\r\n" +
					"	}\r\n" +
					"	/**\r\n" +
					"	 * @param b The b to set.\r\n" +
					"	 */\r\n" +
					"	public void setB(String b) {\r\n" +
					"		this.b = b;\r\n" +
					"	}\r\n" +
					"	/**\r\n" +
					"	 * @return Returns the c.\r\n" +
					"	 */\r\n" +
					"	public Other getC() {\r\n" +
					"		return c;\r\n" +
					"	}\r\n" +
					"	/**\r\n" +
					"	 * @param c The c to set.\r\n" +
					"	 */\r\n" +
					"	public void setC(Other c) {\r\n" +
					"		this.c = c;\r\n" +
					"	}\r\n" +
					"	/**\r\n" +
					"	 * @return Returns the d.\r\n" +
					"	 */\r\n" +
					"	public String getD() {\r\n" +
					"		return d;\r\n" +
					"	}\r\n" +
					"	/**\r\n" +
					"	 * @param d The d to set.\r\n" +
					"	 */\r\n" +
					"	public void setD(String d) {\r\n" +
					"		this.d = d;\r\n" +
					"	}\r\n" +
					"}";
	/* @formatter:on */

	compareSource(expected, classB.getSource());
}
 
Example 18
Source File: PropertiesQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean getCreateFieldsInAccessorClassProposals(PropertiesAssistContext invocationContext, ArrayList<ICompletionProposal> resultingCollections)
		throws BadLocationException, BadPartitioningException {
	IDocument document= invocationContext.getDocument();
	int selectionOffset= invocationContext.getOffset();
	int selectionLength= invocationContext.getLength();
	List<String> fields= new ArrayList<String>();

	IType accessorClass= invocationContext.getAccessorType();
	if (accessorClass == null || !isEclipseNLSUsed(accessorClass))
		return false;

	List<String> keys= getKeysFromSelection(document, selectionOffset, selectionLength);
	if (keys == null || keys.size() == 0)
		return false;

	for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
		String key= iterator.next();
		if (!isValidJavaIdentifier(key))
			continue;
		IField field= accessorClass.getField(key);
		if (field.exists())
			continue;
		if (resultingCollections == null)
			return true;
		fields.add(key);
	}

	if (fields.size() == 0)
		return false;

	ICompilationUnit cu= accessorClass.getCompilationUnit();
	try {
		Change change= AccessorClassModifier.addFields(cu, fields);
		String name= Messages.format(fields.size() == 1 ? PropertiesFileEditorMessages.PropertiesCorrectionProcessor_create_field_in_accessor_label : PropertiesFileEditorMessages.PropertiesCorrectionProcessor_create_fields_in_accessor_label, BasicElementLabels.getFileName(cu));
		resultingCollections.add(new CUCorrectionProposal(name, cu, (TextChange) change, 5, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)));
	} catch (CoreException e) {
		JavaPlugin.log(e);
		return false;
	}
	return true;
}
 
Example 19
Source File: PropertiesQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean getRemovePropertiesProposals(PropertiesAssistContext invocationContext, ArrayList<ICompletionProposal> resultingCollections)
		throws BadLocationException, BadPartitioningException {
	IDocument document= invocationContext.getDocument();
	int selectionOffset= invocationContext.getOffset();
	int selectionLength= invocationContext.getLength();
	List<String> fields= new ArrayList<String>();

	IFile file= invocationContext.getFile();
	if (file == null)
		return false;

	IType accessorClass= invocationContext.getAccessorType();
	if (accessorClass == null || !isEclipseNLSUsed(accessorClass))
		return false;

	List<String> keys= getKeysFromSelection(document, selectionOffset, selectionLength);
	if (keys == null || keys.size() == 0)
		return false;
	if (resultingCollections == null)
		return true;

	for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
		String key= iterator.next();
		IField field= accessorClass.getField(key);
		if (field.exists())
			fields.add(key);
	}

	ICompilationUnit cu= accessorClass.getCompilationUnit();
	try {
		Change propertiesFileChange= NLSPropertyFileModifier.removeKeys(file.getFullPath(), keys);
		Change[] changes;
		if (fields.size() > 0) {
			Change accessorChange= AccessorClassModifier.removeFields(cu, fields);
			changes= new Change[] { propertiesFileChange, accessorChange };
		} else {
			changes= new Change[] { propertiesFileChange };
		}

		String name= (keys.size() == 1)
				? PropertiesFileEditorMessages.PropertiesCorrectionProcessor_remove_property_label
				: PropertiesFileEditorMessages.PropertiesCorrectionProcessor_remove_properties_label;
		resultingCollections.add(new RemovePropertiesProposal(name, 4, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE), changes));
	} catch (CoreException e) {
		JavaPlugin.log(e);
		return false;
	}
	return true;
}
 
Example 20
Source File: GenericRefactoringHandleTransplanter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected IField transplantHandle(IType parent, IField element) {
	return parent.getField(element.getElementName());
}