Package org.eclipse.jdt.internal.compiler.ast

Examples of org.eclipse.jdt.internal.compiler.ast.LocalDeclaration


      return null;
    }
  }

  private JavaElement getJavaElement(LocalVariableBinding binding) {
    LocalDeclaration local = binding.declaration;

    JavaElement parent = null;
    ReferenceContext referenceContext = binding.declaringScope.referenceContext();
    if (referenceContext instanceof AbstractMethodDeclaration) {
      AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext;
      parent = this.getJavaElementOfCompilationUnit(methodDeclaration, methodDeclaration.binding);
    } else if (referenceContext instanceof TypeDeclaration){
      // Local variable is declared inside an initializer
      TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;

      JavaElement type = this.getJavaElementOfCompilationUnit(typeDeclaration, typeDeclaration.binding);
      parent = Util.getUnresolvedJavaElement(local.sourceStart, local.sourceEnd, type);
    }
    if (parent == null) return null;

    return new LocalVariable(
        parent,
        new String(local.name),
        local.declarationSourceStart,
        local.declarationSourceEnd,
        local.sourceStart,
        local.sourceEnd,
        Util.typeSignature(local.type),
        binding.declaration.annotations,
        local.modifiers,
        local.getKind() == AbstractVariableDeclaration.PARAMETER);
  }
View Full Code Here


}
public void fakeReachable(ASTNode location) {
  int sourceStart = location.sourceStart;
  int sourceEnd = location.sourceEnd;
  if (location instanceof LocalDeclaration) {
    LocalDeclaration declaration = (LocalDeclaration) location;
    sourceStart = declaration.declarationSourceStart;
    sourceEnd = declaration.declarationSourceEnd;
 
  this.handle(
    IProblem.DeadCode,
View Full Code Here

}
public void unreachableCode(Statement statement) {
  int sourceStart = statement.sourceStart;
  int sourceEnd = statement.sourceEnd;
  if (statement instanceof LocalDeclaration) {
    LocalDeclaration declaration = (LocalDeclaration) statement;
    sourceStart = declaration.declarationSourceStart;
    sourceEnd = declaration.declarationSourceEnd;
  } else if (statement instanceof Expression) {
    int statemendEnd = ((Expression) statement).statementEnd;
    if (statemendEnd != -1) sourceEnd = statemendEnd;
View Full Code Here

          }
        } else if (i == statementsLength - 1 && insertNewLineAfterLastStatement) {
          this.scribe.printNewLine();
        }
      } else if (statement instanceof LocalDeclaration) {
        LocalDeclaration currentLocal = (LocalDeclaration) statement;
        if (i < (statementsLength - 1)) {
          /*
           * We need to check that the next statement is a local declaration
           */
          if (statements[i + 1] instanceof LocalDeclaration) {
            LocalDeclaration nextLocal = (LocalDeclaration) statements[i + 1];
            if (currentLocal.declarationSourceStart != nextLocal.declarationSourceStart) {
              this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
              this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
              if (i != statementsLength - 1) {
                if (!(statement instanceof EmptyStatement) && !(statements[i + 1] instanceof EmptyStatement)) {
View Full Code Here

           */
          this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
          this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
          this.scribe.printNewLine();
        } else if (statement instanceof LocalDeclaration) {
          LocalDeclaration currentLocal = (LocalDeclaration) statement;
          if (i < (statementsLength - 1)) {
            /*
             * We need to check that the next statement is a local declaration
             */
            if (statements[i + 1] instanceof LocalDeclaration) {
              LocalDeclaration nextLocal = (LocalDeclaration) statements[i + 1];
              if (currentLocal.declarationSourceStart != nextLocal.declarationSourceStart) {
                /*
                 * Print the semi-colon
                 */
                this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
View Full Code Here

          // convert it to a simple try statement tagged as MALFORMED
          tryStatement.setFlags(tryStatement.getFlags() | ASTNode.MALFORMED);
          break;
        default:
          for (int i = 0; i < resourcesLength; i++) {
            LocalDeclaration localDeclaration = localDeclarations[i];
            VariableDeclarationExpression variableDeclarationExpression = convertToVariableDeclarationExpression(localDeclaration);
            int start = variableDeclarationExpression.getStartPosition();
            int end = localDeclaration.declarationEnd;
            variableDeclarationExpression.setSourceRange(start, end - start + 1);
            tryStatement.resources().add(variableDeclarationExpression);
View Full Code Here

      }
    }
  }
}
public void acceptLocalVariable(LocalVariableBinding binding) {
  LocalDeclaration local = binding.declaration;
  IJavaElement parent = findLocalElement(local.sourceStart); // findLocalElement() cannot find local variable
  LocalVariable localVar = null;
  if(parent != null) {
    localVar = new LocalVariable(
        (JavaElement)parent,
        new String(local.name),
        local.declarationSourceStart,
        local.declarationSourceEnd,
        local.sourceStart,
        local.sourceEnd,
        Util.typeSignature(local.type),
        local.annotations,
        local.modifiers,
        local.getKind() == AbstractVariableDeclaration.PARAMETER);
  }
  if (localVar != null) {
    addElement(localVar);
    if(SelectionEngine.DEBUG){
      System.out.print("SELECTION - accept local variable("); //$NON-NLS-1$
View Full Code Here

        compilationResult);
    methodDeclaration.scope = new MethodScope(typeDeclaration.scope, null,
        false);
    methodDeclaration.returnType = createMockBinaryTypeReference(binaryTypeBinding);

    LocalDeclaration localDeclaration = new LocalDeclaration(null, 0, 0);
    localDeclaration.type = createMockBinaryTypeReference(binaryTypeBinding);
    methodDeclaration.statements = new Statement[] {localDeclaration};

    SingleMemberAnnotation annotation = new SingleMemberAnnotation(
        createMockBinaryTypeReference(binaryTypeBinding), 0);
View Full Code Here

      }
    }
  }
}
public void acceptLocalVariable(LocalVariableBinding binding, org.eclipse.jdt.internal.compiler.env.ICompilationUnit unit) {
  LocalDeclaration local = binding.declaration;
  IJavaElement parent = null;
  if (binding.declaringScope.isLambdaSubscope() && unit instanceof ICompilationUnit) {
    HashSet existingElements = new HashSet();
    HashMap knownScopes = new HashMap();
    parent = this.handleFactory.createElement(binding.declaringScope, local.sourceStart, (ICompilationUnit) unit, existingElements, knownScopes);
  } else {   
    parent = findLocalElement(local.sourceStart, binding.declaringScope.methodScope()); // findLocalElement() cannot find local variable
  }
  LocalVariable localVar = null;
  if(parent != null) {
    localVar = new LocalVariable(
        (JavaElement)parent,
        new String(local.name),
        local.declarationSourceStart,
        local.declarationSourceEnd,
        local.sourceStart,
        local.sourceEnd,
        local.type == null ? Signature.createTypeSignature(binding.type.readableName(), true) : Util.typeSignature(local.type),
        local.annotations,
        local.modifiers,
        local.getKind() == AbstractVariableDeclaration.PARAMETER);
  }
  if (localVar != null) {
    addElement(localVar);
    if(SelectionEngine.DEBUG){
      System.out.print("SELECTION - accept local variable("); //$NON-NLS-1$
View Full Code Here

  private void removeLocals(Statement[] statements, int start, int end) {
    if (statements != null) {
      for (int i = 0; i < statements.length; i++) {
        if (statements[i] instanceof LocalDeclaration) {
          LocalDeclaration localDeclaration = (LocalDeclaration) statements[i];
          int j = indexOfFisrtNameAfter(start);
          done : while (j != -1) {
            int nameStart = this.potentialVariableNameStarts[j];
            if (start <= nameStart && nameStart <= end) {
              if (CharOperation.equals(this.potentialVariableNames[j], localDeclaration.name, false)) {
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.ast.LocalDeclaration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.