Java Code Examples for org.eclipse.jdt.core.dom.Modifier#isStatic()

The following examples show how to use org.eclipse.jdt.core.dom.Modifier#isStatic() . 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: ConstructorFromSuperclassProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private ITypeBinding getEnclosingInstance() {
	ITypeBinding currBinding= fTypeNode.resolveBinding();
	if (currBinding == null || Modifier.isStatic(currBinding.getModifiers())) {
		return null;
	}
	ITypeBinding superBinding= currBinding.getSuperclass();
	if (superBinding == null || superBinding.getDeclaringClass() == null || Modifier.isStatic(superBinding.getModifiers())) {
		return null;
	}
	ITypeBinding enclosing= superBinding.getDeclaringClass();

	while (currBinding != null) {
		if (Bindings.isSuperType(enclosing, currBinding)) {
			return null; // enclosing in scope
		}
		if (Modifier.isStatic(currBinding.getModifiers())) {
			return null; // no more enclosing instances
		}
		currBinding= currBinding.getDeclaringClass();
	}
	return enclosing;
}
 
Example 2
Source File: NLSAccessorFieldRenameParticipant.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isPotentialNLSAccessor(ICompilationUnit unit) throws JavaModelException {
	IType type= unit.getTypes()[0];
	if (!type.exists())
		return false;

	IField bundleNameField= getBundleNameField(type.getFields());
	if (bundleNameField == null)
		return false;

	if (!importsOSGIUtil(unit))
		return false;

	IInitializer[] initializers= type.getInitializers();
	for (int i= 0; i < initializers.length; i++) {
		if (Modifier.isStatic(initializers[0].getFlags()))
			return true;
	}

	return false;
}
 
Example 3
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Is the specified name a field access?
 *
 * @param name
 *            the name to check
 * @return <code>true</code> if this name is a field access,
 *         <code>false</code> otherwise
 */
protected static boolean isFieldAccess(final SimpleName name) {
	Assert.isNotNull(name);
	final IBinding binding= name.resolveBinding();
	if (!(binding instanceof IVariableBinding))
		return false;
	final IVariableBinding variable= (IVariableBinding) binding;
	if (!variable.isField())
		return false;
	if ("length".equals(name.getIdentifier())) { //$NON-NLS-1$
		final ASTNode parent= name.getParent();
		if (parent instanceof QualifiedName) {
			final QualifiedName qualified= (QualifiedName) parent;
			final ITypeBinding type= qualified.getQualifier().resolveTypeBinding();
			if (type != null && type.isArray())
				return false;
		}
	}
	return !Modifier.isStatic(variable.getModifiers());
}
 
Example 4
Source File: JavaElementDelegateMainLaunch.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected boolean containsElementsSearchedFor(IFile file) {
	IJavaElement element = JavaCore.create(file);
	if (element == null || !element.exists() || ! (element instanceof ICompilationUnit)) {
		return false;
	}
	try {
		ICompilationUnit cu = (ICompilationUnit) element;
		for (IType type : cu.getAllTypes()) {
			for (IMethod method : type.getMethods()) {
				int flags = method.getFlags();
				if (Modifier.isPublic(flags) && Modifier.isStatic(flags) && "main".equals(method.getElementName())
						&& method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals("[QString;")) { //$NON-NLS-1$
					return true;
				}
			}
		}
	} catch (JavaModelException e) {
		log.error(e.getMessage(), e);
	}
	return super.containsElementsSearchedFor(file);
}
 
Example 5
Source File: ConstructorFromSuperclassProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private ITypeBinding getEnclosingInstance() {
	ITypeBinding currBinding= fTypeNode.resolveBinding();
	if (currBinding == null || Modifier.isStatic(currBinding.getModifiers())) {
		return null;
	}
	ITypeBinding superBinding= currBinding.getSuperclass();
	if (superBinding == null || superBinding.getDeclaringClass() == null || Modifier.isStatic(superBinding.getModifiers())) {
		return null;
	}
	ITypeBinding enclosing= superBinding.getDeclaringClass();

	while (currBinding != null) {
		if (Bindings.isSuperType(enclosing, currBinding)) {
			return null; // enclosing in scope
		}
		if (Modifier.isStatic(currBinding.getModifiers())) {
			return null; // no more enclosing instances
		}
		currBinding= currBinding.getDeclaringClass();
	}
	return enclosing;
}
 
Example 6
Source File: JavaStatementPostfixContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private VariableDeclarationFragment addFieldDeclaration(ASTRewrite rewrite, org.eclipse.jdt.core.dom.ASTNode newTypeDecl, int modifiers, String varName, String qualifiedName, String value) {

		ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
		List<BodyDeclaration> decls = ASTNodes.getBodyDeclarations(newTypeDecl);
		AST ast = newTypeDecl.getAST();
		
		VariableDeclarationFragment newDeclFrag = ast.newVariableDeclarationFragment();
		newDeclFrag.setName(ast.newSimpleName(varName));
		
		Type type = createType(Signature.createTypeSignature(qualifiedName, true), ast);
		
		if (value != null && value.trim().length() > 0) {
			Expression e = createExpression(value);
			Expression ne = (Expression) org.eclipse.jdt.core.dom.ASTNode.copySubtree(ast, e);
			newDeclFrag.setInitializer(ne);
			
		} else {
			if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) {
				newDeclFrag.setInitializer(ASTNodeFactory.newDefaultExpression(ast, type, 0));
			}
		}

		FieldDeclaration newDecl = ast.newFieldDeclaration(newDeclFrag);
		newDecl.setType(type);
		newDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers));

		int insertIndex = findFieldInsertIndex(decls, getCompletionOffset(), modifiers);
		rewrite.getListRewrite(newTypeDecl, property).insertAt(newDecl, insertIndex, null);
		
		return newDeclFrag;
	}
 
Example 7
Source File: SelfEncapsulateFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void checkName(RefactoringStatus status, String name, List<IMethodBinding> usedNames, IType type, boolean reUseExistingField, IField field) {
	if ("".equals(name)) { //$NON-NLS-1$
		status.addFatalError(RefactoringCoreMessages.Checks_Choose_name);
		return;
    }
	boolean isStatic=false;
	try {
		isStatic= Flags.isStatic(field.getFlags());
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}
	status.merge(Checks.checkMethodName(name, field));
	for (Iterator<IMethodBinding> iter= usedNames.iterator(); iter.hasNext(); ) {
		IMethodBinding method= iter.next();
		String selector= method.getName();
		if (selector.equals(name)) {
			if (!reUseExistingField) {
				status.addFatalError(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_method_exists, new String[] { BindingLabelProvider.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(type.getElementName()) }));
			} else {
				boolean methodIsStatic= Modifier.isStatic(method.getModifiers());
				if (methodIsStatic && !isStatic)
					status.addWarning(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_static_method_but_nonstatic_field, new String[] { BasicElementLabels.getJavaElementName(method.getName()), BasicElementLabels.getJavaElementName(field.getElementName()) }));
				if (!methodIsStatic && isStatic)
					status.addFatalError(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_nonstatic_method_but_static_field, new String[] { BasicElementLabels.getJavaElementName(method.getName()), BasicElementLabels.getJavaElementName(field.getElementName()) }));
				return;
			}

		}
	}
	if (reUseExistingField)
		status.addFatalError(Messages.format(
			RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_methoddoesnotexist_status_fatalError,
			new String[] { BasicElementLabels.getJavaElementName(name), BasicElementLabels.getJavaElementName(type.getElementName())}));
}
 
Example 8
Source File: ConstantChecks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean visitName(Name name) {
	IBinding binding= name.resolveBinding();
	if(binding == null) {
		/* If the binding is null because of compile errors etc.,
		   scenarios which may have been deemed unacceptable in
		   the presence of semantic information will be admitted.
		   Descend deeper.
		 */
		 return true;
	}

	int modifiers= binding.getModifiers();
	if(binding instanceof IVariableBinding) {
		if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers))) {
			fResult= false;
			return false;
		}
	} else if(binding instanceof IMethodBinding) {
		if (!Modifier.isStatic(modifiers)) {
			fResult= false;
			return false;
		}
	} else if(binding instanceof ITypeBinding) {
		return false; // It's o.k.  Don't descend deeper.

	} else {
		return false; // e.g. a NameQualifiedType's qualifier, which can be a package binding
	}

	//Descend deeper:
	return true;
}
 
Example 9
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Expression createAccessExpressionToEnclosingInstanceFieldText(ASTNode node, IBinding binding, AbstractTypeDeclaration declaration) {
	if (Modifier.isStatic(binding.getModifiers()))
		return node.getAST().newName(fType.getDeclaringType().getTypeQualifiedName('.'));
	else if ((isInAnonymousTypeInsideInputType(node, declaration) || isInLocalTypeInsideInputType(node, declaration) || isInNonStaticMemberTypeInsideInputType(node, declaration)))
		return createQualifiedReadAccessExpressionForEnclosingInstance(node.getAST());
	else
		return createReadAccessExpressionForEnclosingInstance(node.getAST());
}
 
Example 10
Source File: ImplementOccurrencesFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(MethodDeclaration node) {
	IMethodBinding binding= node.resolveBinding();
	if (binding != null && !Modifier.isStatic(binding.getModifiers())) {
		IMethodBinding method= Bindings.findOverriddenMethodInHierarchy(fSelectedType, binding);
		if (method != null) {
			SimpleName name= node.getName();
			fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fDescription));
		}
	}
	return super.visit(node);
}
 
Example 11
Source File: NumberOfMethods.java    From ck with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(MethodDeclaration node) {
	methods++;

	// visibility
	boolean isPublic = Modifier.isPublic(node.getModifiers());
	boolean isPrivate = Modifier.isPrivate(node.getModifiers());
	boolean isProtected = Modifier.isProtected(node.getModifiers());

	if(isPublic)
		publicMethods++;
	else if(isPrivate)
		privateMethods++;
	else if(isProtected)
		protectedMethods++;
	else
		defaultMethods++;

	// other characteristics

	boolean isFinal = Modifier.isFinal(node.getModifiers());
	boolean isSynchronized = Modifier.isSynchronized(node.getModifiers());
	boolean isAbstract = Modifier.isAbstract(node.getModifiers());
	boolean isStatic = Modifier.isStatic(node.getModifiers());

	if(isStatic)
		staticMethods++;

	if(isAbstract)
		abstractMethods++;

	if(isFinal)
		finalMethods++;

	if(isSynchronized)
		synchronizedMethods++;
}
 
Example 12
Source File: ConstantChecks.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isMemberReferenceValidInClassInitialization(Name name) {
	IBinding binding = name.resolveBinding();
	Assert.isTrue(binding instanceof IVariableBinding || binding instanceof IMethodBinding);

	if (name instanceof SimpleName) {
		return Modifier.isStatic(binding.getModifiers());
	} else {
		Assert.isTrue(name instanceof QualifiedName);
		return checkName(((QualifiedName) name).getQualifier());
	}
}
 
Example 13
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isDefaultMethod(IMethodBinding method) {
	int modifiers= method.getModifiers();
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405517#c7
	ITypeBinding declaringClass= method.getDeclaringClass();
	if (declaringClass.isInterface()) {
		return !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers);
	}
	return false;
}
 
Example 14
Source File: ModifierChangeCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ASTRewrite getRewrite() throws CoreException {
	CompilationUnit astRoot= ASTResolving.findParentCompilationUnit(fNode);
	ASTNode boundNode= astRoot.findDeclaringNode(fBinding);
	ASTNode declNode= null;

	if (boundNode != null) {
		declNode= boundNode; // is same CU
	} else {
		//setSelectionDescription(selectionDescription);
		CompilationUnit newRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
		declNode= newRoot.findDeclaringNode(fBinding.getKey());
	}
	if (declNode != null) {
		AST ast= declNode.getAST();
		ASTRewrite rewrite= ASTRewrite.create(ast);

		if (declNode.getNodeType() == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
			VariableDeclarationFragment fragment= (VariableDeclarationFragment)declNode;
			ASTNode parent= declNode.getParent();
			if (parent instanceof FieldDeclaration) {
				FieldDeclaration fieldDecl= (FieldDeclaration) parent;
				if (fieldDecl.fragments().size() > 1 && (fieldDecl.getParent() instanceof AbstractTypeDeclaration)) { // split
					VariableDeclarationRewrite.rewriteModifiers(fieldDecl, new VariableDeclarationFragment[] {fragment}, fIncludedModifiers, fExcludedModifiers, rewrite, null);
					return rewrite;
				}
			} else if (parent instanceof VariableDeclarationStatement) {
				VariableDeclarationStatement varDecl= (VariableDeclarationStatement) parent;
				if (varDecl.fragments().size() > 1 && (varDecl.getParent() instanceof Block)) { // split
					VariableDeclarationRewrite.rewriteModifiers(varDecl, new VariableDeclarationFragment[] {fragment}, fIncludedModifiers, fExcludedModifiers, rewrite, null);
					return rewrite;
				}
			} else if (parent instanceof VariableDeclarationExpression) {
				// can't separate
			}
			declNode= parent;
		} else if (declNode.getNodeType() == ASTNode.METHOD_DECLARATION) {
			MethodDeclaration methodDecl= (MethodDeclaration) declNode;
			if (!methodDecl.isConstructor()) {
				IMethodBinding methodBinding= methodDecl.resolveBinding();
				if (methodDecl.getBody() == null && methodBinding != null && Modifier.isAbstract(methodBinding.getModifiers()) && Modifier.isStatic(fIncludedModifiers)) {
					// add body
					ICompilationUnit unit= getCompilationUnit();
					String delimiter= unit.findRecommendedLineSeparator();
					String bodyStatement= ""; //$NON-NLS-1$
					
					Block body= ast.newBlock();
					rewrite.set(methodDecl, MethodDeclaration.BODY_PROPERTY, body, null);
					Type returnType= methodDecl.getReturnType2();
					if (returnType != null) {
						Expression expression= ASTNodeFactory.newDefaultExpression(ast, returnType, methodDecl.getExtraDimensions());
						if (expression != null) {
							ReturnStatement returnStatement= ast.newReturnStatement();
							returnStatement.setExpression(expression);
							bodyStatement= ASTNodes.asFormattedString(returnStatement, 0, delimiter, unit.getJavaProject().getOptions(true));
						}
					}
					String placeHolder= CodeGeneration.getMethodBodyContent(unit, methodBinding.getDeclaringClass().getName(), methodBinding.getName(), false, bodyStatement, delimiter);
					if (placeHolder != null) {
						ReturnStatement todoNode= (ReturnStatement) rewrite.createStringPlaceholder(placeHolder, ASTNode.RETURN_STATEMENT);
						body.statements().add(todoNode);
					}
				}
			}
		}
		ModifierRewrite listRewrite= ModifierRewrite.create(rewrite, declNode);
		PositionInformation trackedDeclNode= listRewrite.setModifiers(fIncludedModifiers, fExcludedModifiers, null);
		
		LinkedProposalPositionGroup positionGroup= new LinkedProposalPositionGroup("group"); //$NON-NLS-1$
		positionGroup.addPosition(trackedDeclNode);
		getLinkedProposalModel().addPositionGroup(positionGroup);
		
		if (boundNode != null) {
			// only set end position if in same CU
			setEndPosition(rewrite.track(fNode));
		}
		return rewrite;
	}
	return null;
}
 
Example 15
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static boolean isStatic(IMethodBinding methodBinding){
	return Modifier.isStatic(methodBinding.getModifiers());
}
 
Example 16
Source File: PromoteTempToFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isTempDeclaredInStaticMethod() {
	return Modifier.isStatic(getMethodDeclaration().getModifiers());
}
 
Example 17
Source File: ConvertAnonymousToNestedRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean mustInnerClassBeStatic() {
    ITypeBinding typeBinding = ((AbstractTypeDeclaration) ASTNodes.getParent(fAnonymousInnerClassNode, AbstractTypeDeclaration.class)).resolveBinding();
    ASTNode current = fAnonymousInnerClassNode.getParent();
    boolean ans = false;
    while(current != null) {
        switch(current.getNodeType()) {
case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
case ASTNode.CONSTRUCTOR_INVOCATION:
	return true;
case ASTNode.ANONYMOUS_CLASS_DECLARATION:
            {
                AnonymousClassDeclaration enclosingAnonymousClassDeclaration= (AnonymousClassDeclaration)current;
                ITypeBinding binding= enclosingAnonymousClassDeclaration.resolveBinding();
                if (binding != null && Bindings.isSuperType(typeBinding, binding.getSuperclass())) {
                    return false;
                }
                break;
            }
            case ASTNode.FIELD_DECLARATION:
            {
                FieldDeclaration enclosingFieldDeclaration= (FieldDeclaration)current;
                if (Modifier.isStatic(enclosingFieldDeclaration.getModifiers())) {
                    ans = true;
                }
                break;
            }
            case ASTNode.METHOD_DECLARATION:
            {
                MethodDeclaration enclosingMethodDeclaration = (MethodDeclaration)current;
                if (Modifier.isStatic(enclosingMethodDeclaration.getModifiers())) {
                    ans = true;
                }
                break;
            }
            case ASTNode.TYPE_DECLARATION:
            {
                return ans;
            }
        }
        current = current.getParent();
    }
    return ans;
}
 
Example 18
Source File: AssignToVariableAssistProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private ASTRewrite doAddField(ASTRewrite rewrite, ASTNode nodeToAssign, ITypeBinding typeBinding, int index) {
	boolean isParamToField= nodeToAssign.getNodeType() == ASTNode.SINGLE_VARIABLE_DECLARATION;

	ASTNode newTypeDecl= ASTResolving.findParentType(nodeToAssign);
	if (newTypeDecl == null) {
		return null;
	}

	Expression expression= isParamToField ? ((SingleVariableDeclaration) nodeToAssign).getName() : ((ExpressionStatement) nodeToAssign).getExpression();

	AST ast= newTypeDecl.getAST();

	createImportRewrite((CompilationUnit) nodeToAssign.getRoot());

	BodyDeclaration bodyDecl= ASTResolving.findParentBodyDeclaration(nodeToAssign);
	Block body;
	if (bodyDecl instanceof MethodDeclaration) {
		body= ((MethodDeclaration) bodyDecl).getBody();
	} else if (bodyDecl instanceof Initializer) {
		body= ((Initializer) bodyDecl).getBody();
	} else {
		return null;
	}

	IJavaProject project= getCompilationUnit().getJavaProject();
	boolean isAnonymous= newTypeDecl.getNodeType() == ASTNode.ANONYMOUS_CLASS_DECLARATION;
	boolean isStatic= Modifier.isStatic(bodyDecl.getModifiers()) && !isAnonymous;
	int modifiers= Modifier.PRIVATE;
	if (isStatic) {
		modifiers |= Modifier.STATIC;
	}

	VariableDeclarationFragment newDeclFrag= addFieldDeclaration(rewrite, newTypeDecl, modifiers, expression, nodeToAssign, typeBinding, index);
	String varName= newDeclFrag.getName().getIdentifier();

	Assignment assignment= ast.newAssignment();
	assignment.setRightHandSide((Expression) rewrite.createCopyTarget(expression));

	boolean needsThis= StubUtility.useThisForFieldAccess(project);
	if (isParamToField) {
		needsThis |= varName.equals(((SimpleName) expression).getIdentifier());
	}

	SimpleName accessName= ast.newSimpleName(varName);
	if (needsThis) {
		FieldAccess fieldAccess= ast.newFieldAccess();
		fieldAccess.setName(accessName);
		if (isStatic) {
			String typeName= ((AbstractTypeDeclaration) newTypeDecl).getName().getIdentifier();
			fieldAccess.setExpression(ast.newSimpleName(typeName));
		} else {
			fieldAccess.setExpression(ast.newThisExpression());
		}
		assignment.setLeftHandSide(fieldAccess);
	} else {
		assignment.setLeftHandSide(accessName);
	}

	ASTNode selectionNode;
	if (isParamToField) {
		// assign parameter to field
		ExpressionStatement statement= ast.newExpressionStatement(assignment);
		int insertIdx= findAssignmentInsertIndex(body.statements(), nodeToAssign) + index;
		rewrite.getListRewrite(body, Block.STATEMENTS_PROPERTY).insertAt(statement, insertIdx, null);
		selectionNode= statement;
	} else {
		if (needsSemicolon(expression)) {
			rewrite.replace(expression, ast.newExpressionStatement(assignment), null);
		} else {
			rewrite.replace(expression, assignment, null);
		}
		selectionNode= nodeToAssign;
	}

	addLinkedPosition(rewrite.track(newDeclFrag.getName()), false, KEY_NAME + index);
	if (!isParamToField) {
		FieldDeclaration fieldDeclaration= (FieldDeclaration) newDeclFrag.getParent();
		addLinkedPosition(rewrite.track(fieldDeclaration.getType()), false, KEY_TYPE);
	}
	addLinkedPosition(rewrite.track(accessName), true, KEY_NAME + index);
	IVariableBinding variableBinding= newDeclFrag.resolveBinding();
	if (variableBinding != null) {
		SimpleName[] linkedNodes= LinkedNodeFinder.findByBinding(nodeToAssign.getRoot(), variableBinding);
		for (int i= 0; i < linkedNodes.length; i++) {
			addLinkedPosition(rewrite.track(linkedNodes[i]), false, KEY_NAME + index);
		}
	}
	setEndPosition(rewrite.track(selectionNode));

	return rewrite;
}
 
Example 19
Source File: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isMemberType() {
	return fType.isMember() && !Modifier.isStatic(fType.getModifiers());
}
 
Example 20
Source File: ASTNodes.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean visit(ITypeBinding type) {
	IMethodBinding[] methods= type.getDeclaredMethods();
	for (int i= 0; i < methods.length; i++) {
		IMethodBinding candidate= methods[i];
		if (candidate.getMethodDeclaration() == fOriginalMethod.getMethodDeclaration()) {
			continue;
		}
		ITypeBinding candidateDeclaringType= candidate.getDeclaringClass();
		if (fDeclaringType != candidateDeclaringType) {
			int modifiers= candidate.getModifiers();
			if (candidateDeclaringType.isInterface() && Modifier.isStatic(modifiers)) {
				continue;
			}
			if (Modifier.isPrivate(modifiers)) {
				continue;
			}
		}
		if (fOriginalMethod.getName().equals(candidate.getName()) && !fOriginalMethod.overrides(candidate)) {
			ITypeBinding[] originalParameterTypes= fOriginalMethod.getParameterTypes();
			ITypeBinding[] candidateParameterTypes= candidate.getParameterTypes();
			
			boolean couldBeAmbiguous;
			if (originalParameterTypes.length == candidateParameterTypes.length) {
				couldBeAmbiguous= true;
			} else if (fOriginalMethod.isVarargs() || candidate.isVarargs() ) {
				int candidateMinArgumentCount= candidateParameterTypes.length;
				if (candidate.isVarargs())
					candidateMinArgumentCount--;
				couldBeAmbiguous= fArgumentCount >= candidateMinArgumentCount;
			} else {
				couldBeAmbiguous= false;
			}
			if (couldBeAmbiguous) {
				ITypeBinding parameterType= ASTResolving.getParameterTypeBinding(candidate, fArgIndex);
				if (parameterType != null && parameterType.getFunctionalInterfaceMethod() != null) {
					if (!fExpressionIsExplicitlyTyped) {
						/* According to JLS8 15.12.2.2, implicitly typed lambda expressions are not "pertinent to applicability"
						 * and hence potentially applicable methods are always "applicable by strict invocation",
						 * regardless of whether argument expressions are compatible with the method's parameter types or not.
						 * If there are multiple such methods, 15.12.2.5 results in an ambiguous method invocation.
						 */
						return false;
					}
					/* Explicitly typed lambda expressions are pertinent to applicability, and hence
					 * compatibility with the corresponding method parameter type is checked. And since this check
					 * separates functional interface methods by their void-compatibility state, functional interfaces
					 * with a different void compatibility are not applicable any more and hence can't cause
					 * an ambiguous method invocation.
					 */
					ITypeBinding origParamType= ASTResolving.getParameterTypeBinding(fOriginalMethod, fArgIndex);
					boolean originalIsVoidCompatible=  Bindings.isVoidType(origParamType.getFunctionalInterfaceMethod().getReturnType());
					boolean candidateIsVoidCompatible= Bindings.isVoidType(parameterType.getFunctionalInterfaceMethod().getReturnType());
					if (originalIsVoidCompatible == candidateIsVoidCompatible) {
						return false;
					}
				}
			}
		}
	}
	return true;
}