Example usage for org.eclipse.jdt.internal.compiler.ast ASTNode IsCompoundAssigned

List of usage examples for org.eclipse.jdt.internal.compiler.ast ASTNode IsCompoundAssigned

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast ASTNode IsCompoundAssigned.

Prototype

int IsCompoundAssigned

To view the source code for org.eclipse.jdt.internal.compiler.ast ASTNode IsCompoundAssigned.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

public FieldReferenceMatch newFieldReferenceMatch(IJavaElement enclosingElement, IJavaElement localElement,
        Binding enclosingBinding, int accuracy, int offset, int length, ASTNode reference) {
    int bits = reference.bits;
    boolean isCompoundAssigned = (bits & ASTNode.IsCompoundAssigned) != 0;
    boolean isReadAccess = isCompoundAssigned || (bits & ASTNode.IsStrictlyAssigned) == 0;
    boolean isWriteAccess = isCompoundAssigned || (bits & ASTNode.IsStrictlyAssigned) != 0;
    if (isWriteAccess) {
        if (reference instanceof QualifiedNameReference) {
            char[][] tokens = ((QualifiedNameReference) reference).tokens;
            char[] lastToken = tokens[tokens.length - 1];
            if (this.pattern instanceof OrPattern) {
                SearchPattern[] patterns = ((OrPattern) this.pattern).patterns;
                for (int i = 0, pLength = patterns.length; i < pLength; i++) {
                    if (!this.patternLocator.matchesName(((VariablePattern) patterns[i]).name, lastToken)) {
                        isWriteAccess = false;
                        isReadAccess = true;
                    }/*ww  w.  j a va2  s .  c o m*/
                }
            } else if (!this.patternLocator.matchesName(((VariablePattern) this.pattern).name, lastToken)) {
                isWriteAccess = false;
                isReadAccess = true;
            }
        }
    }
    boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0;
    SearchParticipant participant = getParticipant();
    IResource resource = this.currentPossibleMatch.resource;
    if (enclosingBinding != null) {
        enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
    }
    FieldReferenceMatch match = new FieldReferenceMatch(enclosingElement, accuracy, offset, length,
            isReadAccess, isWriteAccess, insideDocComment, participant, resource);
    match.setLocalElement(localElement);
    return match;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

public SearchMatch newLocalVariableReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset,
        int length, ASTNode reference) {
    int bits = reference.bits;
    boolean isCompoundAssigned = (bits & ASTNode.IsCompoundAssigned) != 0;
    boolean isReadAccess = isCompoundAssigned || (bits & ASTNode.IsStrictlyAssigned) == 0;
    boolean isWriteAccess = isCompoundAssigned || (bits & ASTNode.IsStrictlyAssigned) != 0;
    if (isWriteAccess) {
        if (reference instanceof QualifiedNameReference) {
            char[][] tokens = ((QualifiedNameReference) reference).tokens;
            char[] lastToken = tokens[tokens.length - 1];
            if (this.pattern instanceof OrPattern) {
                SearchPattern[] patterns = ((OrPattern) this.pattern).patterns;
                for (int i = 0, pLength = patterns.length; i < pLength; i++) {
                    if (!this.patternLocator.matchesName(((VariablePattern) patterns[i]).name, lastToken)) {
                        isWriteAccess = false;
                        isReadAccess = true;
                    }//from w w w  .  ja  v  a 2 s  .  c o  m
                }
            } else if (!this.patternLocator.matchesName(((VariablePattern) this.pattern).name, lastToken)) {
                isWriteAccess = false;
                isReadAccess = true;
            }
        }
    }
    boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0;
    SearchParticipant participant = getParticipant();
    IResource resource = this.currentPossibleMatch.resource;
    return new LocalVariableReferenceMatch(enclosingElement, accuracy, offset, length, isReadAccess,
            isWriteAccess, insideDocComment, participant, resource);
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementor.java

License:Open Source License

/**
 * API: If an expression failed to resolve a field,
 * try whether using a callout-to-field could be substituted
 * (potentially also inferring the callout itself).
 *
 * @param scope//from  w w w. java 2  s .c  om
 * @param receiver  can be null
 * @param location
 * @param fieldName
 * @param isSetter
 * @param expectedType what type does the caller of this inferred callout expect? May be null.
 * @return whether or not inference succeeded
 */
public static CalloutMappingDeclaration inferCalloutAccess(Scope scope, Expression receiver,
        Expression location, char[] fieldName, boolean isSetter, TypeBinding expectedType) {
    if (receiver != null && !(receiver instanceof ThisReference))
        return null;
    TypeDeclaration type = scope.referenceType();
    if (!type.isRole() || !type.getRoleModel().isBound())
        return null;
    char[] accessorName = OTNameUtils.accessorName(isSetter, fieldName);

    // search callout-to-field:
    CalloutMappingDeclaration callout = null;
    if (type.callinCallouts != null) {
        for (AbstractMethodMappingDeclaration mapping : type.callinCallouts) {
            if (!mapping.isCallout())
                continue;
            CalloutMappingDeclaration candidate = (CalloutMappingDeclaration) mapping;
            if (!candidate.isCalloutToField())
                continue;
            FieldAccessSpec fieldAccessSpec = (FieldAccessSpec) candidate.baseMethodSpec;
            if (fieldAccessSpec.isSetter() != isSetter)
                continue;
            FieldBinding baseField = fieldAccessSpec.resolvedField;
            if (baseField == null || !baseField.isValidBinding())
                continue;
            if (CharOperation.equals(baseField.name, fieldName)
                    && CharOperation.equals(candidate.roleMethodSpec.selector, accessorName)) {
                // found
                callout = candidate;
                break;
            }
        }
    }
    if (callout == null) { // second chance: infer the callout binding, too:
        AstGenerator gen = new AstGenerator(location.sourceStart, location.sourceEnd);
        callout = inferCalloutToField(type, fieldName, accessorName, isSetter, expectedType, gen);
    }

    if (callout != null) {
        if ((location.bits & ASTNode.IsCompoundAssigned) != 0) {
            // not legal in this context
            scope.problemReporter().inferredCalloutInCompoundAssignment(location, fieldName);
            return null;
        }
        scope.problemReporter().inferredUseOfCalloutToField(isSetter, location, fieldName,
                ((FieldAccessSpec) callout.baseMethodSpec).resolvedField);
    }
    return callout;
}